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:
John Firebaugh
2013-05-24 21:47:49 -07:00
parent d846e8e3f8
commit da00413632
2 changed files with 12 additions and 9 deletions
+9 -7
View File
@@ -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;
}
+3 -2
View File
@@ -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) {