extract bounds conversion from Map.Geolocation.Also fix geolocation test page.

This commit is contained in:
Steve Kashishian 2014-11-06 13:23:14 -06:00
parent 4f06ac30b0
commit f3b132e414
3 changed files with 12 additions and 10 deletions

View File

@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../css/screen.css" /> <link rel="stylesheet" href="../css/screen.css" />
<script type="text/javascript" src="../../build/deps.js"></script>
<script src="../leaflet-include.js"></script> <script src="../leaflet-include.js"></script>
</head> </head>
<body> <body>

View File

@ -40,7 +40,16 @@ L.LatLng.prototype = {
wrap: function () { wrap: function () {
return L.CRS.Earth.wrapLatLng(this); return L.CRS.Earth.wrapLatLng(this);
} },
toBounds: function (sizeInMeters) {
var latAccuracy = 180 * sizeInMeters / 40075017,
lngAccuracy = latAccuracy / Math.cos((Math.PI / 180) * this.lat);
return L.latLngBounds(
[this.lat - latAccuracy, this.lng - lngAccuracy],
[this.lat + latAccuracy, this.lng + lngAccuracy]);
}
}; };

View File

@ -66,14 +66,7 @@ L.Map.include({
var lat = pos.coords.latitude, var lat = pos.coords.latitude,
lng = pos.coords.longitude, lng = pos.coords.longitude,
latlng = new L.LatLng(lat, lng), latlng = new L.LatLng(lat, lng),
bounds = latlng.toBounds(pos.coords.accuracy),
latAccuracy = 180 * pos.coords.accuracy / 40075017,
lngAccuracy = latAccuracy / Math.cos((Math.PI / 180) * lat),
bounds = L.latLngBounds(
[lat - latAccuracy, lng - lngAccuracy],
[lat + latAccuracy, lng + lngAccuracy]),
options = this._locateOptions; options = this._locateOptions;
if (options.setView) { if (options.setView) {