geolocation sets zoom based on accuracy

fixes #1375
This commit is contained in:
Ansis Brammanis
2013-04-25 11:04:22 -04:00
parent 2fa8ca174f
commit 579e6a8a8b
4 changed files with 13 additions and 9 deletions
-4
View File
@@ -85,7 +85,3 @@ iD.geo.pathLength = function(path) {
}
return length;
};
iD.geo.metersToCoordinates = function(loc, vector) {
return [vector[1] / 111200, vector[0] / 111200 / Math.abs(Math.cos(loc[1]))];
};
+8
View File
@@ -33,5 +33,13 @@ _.extend(iD.geo.Extent.prototype, {
obj[0][1] <= this[1][1] &&
obj[1][0] >= this[0][0] &&
obj[1][1] >= this[0][1];
},
padByMeters: function(meters) {
var dLat = meters / 111200,
dLon = meters / 111200 / Math.abs(Math.cos(this.center()[1]));
return iD.geo.Extent(
[this[0][0] - dLon, this[0][1] - dLat],
[this[1][0] + dLon, this[1][1] + dLat]);
}
});
+4 -1
View File
@@ -5,7 +5,10 @@ iD.ui.Geolocate = function(map) {
}
function success(position) {
map.center([position.coords.longitude, position.coords.latitude]);
var extent = iD.geo.Extent([position.coords.longitude, position.coords.latitude])
.padByMeters(position.coords.accuracy);
map.centerZoom(extent.center(), Math.min(20, map.extentZoom(extent)));
}
function error() { }
+1 -4
View File
@@ -12,10 +12,7 @@ iD.ui.preset.address = function(field, context) {
var extent = entity.extent(context.graph()),
l = extent.center(),
dist = iD.geo.metersToCoordinates(l, [200, 200]),
box = iD.geo.Extent(
[extent[0][0] - dist[0], extent[0][1] - dist[1]],
[extent[1][0] + dist[0], extent[1][1] + dist[1]]);
box = iD.geo.Extent(l).padByMeters(200);
return context.intersects(box)
.filter(isAddressable)