remove LatLng constants, add move maxMargin to equals arguments
This commit is contained in:
parent
3d7520ff27
commit
b151ceb63f
@ -2,7 +2,7 @@
|
||||
* L.LatLng represents a geographical point with latitude and longitude coordinates.
|
||||
*/
|
||||
|
||||
L.LatLng = function (lat, lng, alt) { // (Number, Number, Number)
|
||||
L.LatLng = function (lat, lng, alt) {
|
||||
lat = parseFloat(lat);
|
||||
lng = parseFloat(lng);
|
||||
|
||||
@ -18,14 +18,8 @@ L.LatLng = function (lat, lng, alt) { // (Number, Number, Number)
|
||||
}
|
||||
};
|
||||
|
||||
L.extend(L.LatLng, {
|
||||
DEG_TO_RAD: Math.PI / 180,
|
||||
RAD_TO_DEG: 180 / Math.PI,
|
||||
MAX_MARGIN: 1.0E-9 // max margin of error for the "equals" check
|
||||
});
|
||||
|
||||
L.LatLng.prototype = {
|
||||
equals: function (obj) { // (LatLng) -> Boolean
|
||||
equals: function (obj, maxMargin) {
|
||||
if (!obj) { return false; }
|
||||
|
||||
obj = L.latLng(obj);
|
||||
@ -34,10 +28,10 @@ L.LatLng.prototype = {
|
||||
Math.abs(this.lat - obj.lat),
|
||||
Math.abs(this.lng - obj.lng));
|
||||
|
||||
return margin <= L.LatLng.MAX_MARGIN;
|
||||
return margin <= (maxMargin === undefined ? 1.0E-9 : maxMargin);
|
||||
},
|
||||
|
||||
toString: function (precision) { // (Number) -> String
|
||||
toString: function (precision) {
|
||||
return 'LatLng(' +
|
||||
L.Util.formatNum(this.lat, precision) + ', ' +
|
||||
L.Util.formatNum(this.lng, precision) + ')';
|
||||
@ -45,15 +39,15 @@ L.LatLng.prototype = {
|
||||
|
||||
// Haversine distance formula, see http://en.wikipedia.org/wiki/Haversine_formula
|
||||
// TODO move to projection code, LatLng shouldn't know about Earth
|
||||
distanceTo: function (other) { // (LatLng) -> Number
|
||||
distanceTo: function (other) {
|
||||
other = L.latLng(other);
|
||||
|
||||
var R = 6378137, // earth radius in meters
|
||||
d2r = L.LatLng.DEG_TO_RAD,
|
||||
dLat = (other.lat - this.lat) * d2r,
|
||||
dLon = (other.lng - this.lng) * d2r,
|
||||
lat1 = this.lat * d2r,
|
||||
lat2 = other.lat * d2r,
|
||||
rad = Math.PI / 180,
|
||||
dLat = (other.lat - this.lat) * rad,
|
||||
dLon = (other.lng - this.lng) * rad,
|
||||
lat1 = this.lat * rad,
|
||||
lat2 = other.lat * rad,
|
||||
sin1 = Math.sin(dLat / 2),
|
||||
sin2 = Math.sin(dLon / 2);
|
||||
|
||||
|
@ -12,7 +12,7 @@ L.Projection.Mercator = {
|
||||
bounds: L.bounds([-20037508.34279, -15496570.73972], [20037508.34279, 18764656.23138]),
|
||||
|
||||
project: function (latlng) {
|
||||
var d = L.LatLng.DEG_TO_RAD,
|
||||
var d = Math.PI / 180,
|
||||
max = this.MAX_LATITUDE,
|
||||
lat = Math.max(Math.min(max, latlng.lat), -max),
|
||||
r = this.R_MAJOR,
|
||||
@ -32,7 +32,7 @@ L.Projection.Mercator = {
|
||||
},
|
||||
|
||||
unproject: function (point) {
|
||||
var d = L.LatLng.RAD_TO_DEG,
|
||||
var d = 180 / Math.PI,
|
||||
r = this.R_MAJOR,
|
||||
r2 = this.R_MINOR,
|
||||
lng = point.x * d / r,
|
||||
|
@ -9,7 +9,7 @@ L.Projection.SphericalMercator = {
|
||||
R: 6378137,
|
||||
|
||||
project: function (latlng) {
|
||||
var d = L.LatLng.DEG_TO_RAD,
|
||||
var d = Math.PI / 180,
|
||||
max = this.MAX_LATITUDE,
|
||||
x = this.R * latlng.lng * d,
|
||||
y = Math.max(Math.min(max, latlng.lat), -max) * d;
|
||||
@ -20,7 +20,7 @@ L.Projection.SphericalMercator = {
|
||||
},
|
||||
|
||||
unproject: function (point) {
|
||||
var d = L.LatLng.RAD_TO_DEG,
|
||||
var d = 180 / Math.PI,
|
||||
lng = point.x * d / this.R,
|
||||
lat = (2 * Math.atan(Math.exp(point.y / this.R)) - (Math.PI / 2)) * d;
|
||||
|
||||
|
@ -77,7 +77,7 @@ L.Circle = L.Path.extend({
|
||||
},
|
||||
|
||||
_getLngRadius: function () {
|
||||
return this._getLatRadius() / Math.cos(L.LatLng.DEG_TO_RAD * this._latlng.lat);
|
||||
return this._getLatRadius() / Math.cos((Math.PI / 180) * this._latlng.lat);
|
||||
},
|
||||
|
||||
_checkIfEmpty: function () {
|
||||
|
@ -68,7 +68,7 @@ L.Map.include({
|
||||
latlng = new L.LatLng(lat, lng),
|
||||
|
||||
latAccuracy = 180 * pos.coords.accuracy / 40075017,
|
||||
lngAccuracy = latAccuracy / Math.cos(L.LatLng.DEG_TO_RAD * lat),
|
||||
lngAccuracy = latAccuracy / Math.cos((Math.PI / 180) * lat),
|
||||
|
||||
bounds = L.latLngBounds(
|
||||
[lat - latAccuracy, lng - lngAccuracy],
|
||||
|
Loading…
Reference in New Issue
Block a user