mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 09:12:52 +00:00
Add map.extent and use in geocoder
This commit is contained in:
@@ -243,8 +243,27 @@ iD.Map = function() {
|
||||
}, 20);
|
||||
};
|
||||
|
||||
map.extent = function() {
|
||||
return [projection.invert([0, 0]), projection.invert(dimensions)];
|
||||
map.extent = function(tl, br) {
|
||||
if (!arguments.length) {
|
||||
return [projection.invert([0, 0]), projection.invert(dimensions)];
|
||||
} else {
|
||||
|
||||
var TL = projection(tl),
|
||||
BR = projection(br);
|
||||
|
||||
// Calculate maximum zoom that fits extent
|
||||
hFactor = (BR[0] - TL[0]) / dimensions[0];
|
||||
vFactor = (BR[1] - TL[1]) / dimensions[1];
|
||||
hZoomDiff = Math.log(Math.abs(hFactor)) / Math.LN2;
|
||||
vZoomDiff = Math.log(Math.abs(vFactor)) / Math.LN2;
|
||||
zoomDiff = map.zoom() - Math.max(hZoomDiff, vZoomDiff);
|
||||
|
||||
// Calculate center of projected extent
|
||||
midPoint = [(TL[0] + BR[0]) / 2, (TL[1] + BR[1]) / 2];
|
||||
midLoc = projection.invert(midPoint);
|
||||
|
||||
map.zoom(zoomDiff).center(midLoc);
|
||||
}
|
||||
};
|
||||
|
||||
map.flush = function () {
|
||||
|
||||
@@ -15,7 +15,8 @@ iD.ui.geocoder = function() {
|
||||
.select('.content')
|
||||
.text('No location found for "' + resp.query[0] + '"');
|
||||
}
|
||||
map.center([resp.results[0][0].lon, resp.results[0][0].lat]);
|
||||
var bounds = resp.results[0][0].bounds;
|
||||
map.extent([bounds[0], bounds[3]], [bounds[2], bounds[1]]);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user