mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-16 22:03:37 +02:00
Fix zoom-to-feature annoyances
* Zoom to feature only if map parameter isn't also specified. * Don't zoom too far in (>z20). Fixes #1511. * Don't zoom too far out (<z16). Fixes #1522.
This commit is contained in:
@@ -40,12 +40,14 @@ iD.behavior.Hash = function(context) {
|
||||
// the hash can declare that the map should select a feature, but it can
|
||||
// do so before any features are loaded. thus wait for the feature to
|
||||
// be loaded and then select
|
||||
function willselect(id) {
|
||||
context.connection().loadEntity(id, function(error, entity) {
|
||||
if (entity) {
|
||||
context.map().zoomTo(entity);
|
||||
}
|
||||
});
|
||||
function willselect(id, hasMap) {
|
||||
if (!hasMap) {
|
||||
context.connection().loadEntity(id, function(error, entity) {
|
||||
if (entity) {
|
||||
context.map().zoomTo(entity);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
context.map().on('drawn.hash', function() {
|
||||
if (!context.hasEntity(id)) return;
|
||||
@@ -71,7 +73,7 @@ iD.behavior.Hash = function(context) {
|
||||
|
||||
if (location.hash) {
|
||||
var q = iD.util.stringQs(location.hash.substring(1));
|
||||
if (q.id) willselect(q.id);
|
||||
if (q.id) willselect(q.id, q.map);
|
||||
hashchange();
|
||||
if (q.map) hash.hadHash = true;
|
||||
}
|
||||
|
||||
@@ -350,10 +350,11 @@ iD.Map = function(context) {
|
||||
return redraw();
|
||||
};
|
||||
|
||||
map.zoomTo = function(entity) {
|
||||
map.zoomTo = function(entity, zoomLimits) {
|
||||
var extent = entity.extent(context.graph()),
|
||||
zoom = map.extentZoom(extent);
|
||||
map.centerZoom(extent.center(), zoom);
|
||||
zoomLimits = zoomLimits || [16, 20];
|
||||
map.centerZoom(extent.center(), Math.min(Math.max(zoom, zoomLimits[0]), zoomLimits[1]));
|
||||
};
|
||||
|
||||
map.centerZoom = function(loc, z) {
|
||||
|
||||
Reference in New Issue
Block a user