diff --git a/src/geo/LatLng.js b/src/geo/LatLng.js index 9873a76a..ebb1b4d7 100644 --- a/src/geo/LatLng.js +++ b/src/geo/LatLng.js @@ -2,7 +2,7 @@ L.LatLng represents a geographical point with latitude and longitude coordinates. */ -L.LatLng = function (rawLat, rawLng, noWrap) { // (Number, Number[, Boolean]) +L.LatLng = function (rawLat, rawLng) { // (Number, Number) var lat = parseFloat(rawLat), lng = parseFloat(rawLng); @@ -10,11 +10,6 @@ L.LatLng = function (rawLat, rawLng, noWrap) { // (Number, Number[, Boolean]) throw new Error('Invalid LatLng object: (' + rawLat + ', ' + rawLng + ')'); } - if (noWrap !== true) { - lat = Math.max(Math.min(lat, 90), -90); // clamp latitude into -90..90 - lng = (lng + 180) % 360 + ((lng < -180 || lng === 180) ? 180 : -180); // wrap longitude into -180..180 - } - this.lat = lat; this.lng = lng; }; @@ -31,17 +26,21 @@ L.LatLng.prototype = { obj = L.latLng(obj); - var margin = Math.max(Math.abs(this.lat - obj.lat), Math.abs(this.lng - obj.lng)); + var margin = Math.max( + Math.abs(this.lat - obj.lat), + Math.abs(this.lng - obj.lng)); + return margin <= L.LatLng.MAX_MARGIN; }, - toString: function (precision) { // -> String + toString: function (precision) { // (Number) -> String return 'LatLng(' + L.Util.formatNum(this.lat, precision) + ', ' + L.Util.formatNum(this.lng, precision) + ')'; }, // 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 other = L.latLng(other); @@ -57,10 +56,21 @@ L.LatLng.prototype = { var a = sin1 * sin1 + sin2 * sin2 * Math.cos(lat1) * Math.cos(lat2); return R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); + }, + + wrap: function (a, b) { // (Number, Number) -> LatLng + var lng = this.lng; + + a = a || -180; + b = b || 180; + + lng = (lng + b) % (b - a) + (lng < a || lng === b ? b : a); + + return new L.LatLng(this.lat, lng); } }; -L.latLng = function (a, b, c) { // (LatLng) or ([Number, Number]) or (Number, Number, Boolean) +L.latLng = function (a, b) { // (LatLng) or ([Number, Number]) or (Number, Number) if (a instanceof L.LatLng) { return a; } @@ -70,6 +80,6 @@ L.latLng = function (a, b, c) { // (LatLng) or ([Number, Number]) or (Number, Nu if (isNaN(a)) { return a; } - return new L.LatLng(a, b, c); + return new L.LatLng(a, b); }; diff --git a/src/geo/LatLngBounds.js b/src/geo/LatLngBounds.js index fc91fdba..6caca19e 100644 --- a/src/geo/LatLngBounds.js +++ b/src/geo/LatLngBounds.js @@ -23,8 +23,8 @@ L.LatLngBounds = L.Class.extend({ if (obj instanceof L.LatLng) { if (!this._southWest && !this._northEast) { - this._southWest = new L.LatLng(obj.lat, obj.lng, true); - this._northEast = new L.LatLng(obj.lat, obj.lng, true); + this._southWest = new L.LatLng(obj.lat, obj.lng); + this._northEast = new L.LatLng(obj.lat, obj.lng); } else { this._southWest.lat = Math.min(obj.lat, this._southWest.lat); this._southWest.lng = Math.min(obj.lng, this._southWest.lng); @@ -66,11 +66,11 @@ L.LatLngBounds = L.Class.extend({ }, getNorthWest: function () { - return new L.LatLng(this._northEast.lat, this._southWest.lng, true); + return new L.LatLng(this._northEast.lat, this._southWest.lng); }, getSouthEast: function () { - return new L.LatLng(this._southWest.lat, this._northEast.lng, true); + return new L.LatLng(this._southWest.lat, this._northEast.lng); }, contains: function (obj) { // (LatLngBounds) or (LatLng) -> Boolean diff --git a/src/geo/projection/Projection.LonLat.js b/src/geo/projection/Projection.LonLat.js index 70f9f40a..b53ddee6 100644 --- a/src/geo/projection/Projection.LonLat.js +++ b/src/geo/projection/Projection.LonLat.js @@ -5,6 +5,6 @@ L.Projection.LonLat = { }, unproject: function (point) { - return new L.LatLng(point.y, point.x, true); + return new L.LatLng(point.y, point.x); } }; diff --git a/src/geo/projection/Projection.Mercator.js b/src/geo/projection/Projection.Mercator.js index 8298edb0..8ff7253c 100644 --- a/src/geo/projection/Projection.Mercator.js +++ b/src/geo/projection/Projection.Mercator.js @@ -47,6 +47,6 @@ L.Projection.Mercator = { phi += dphi; } - return new L.LatLng(phi * d, lng, true); + return new L.LatLng(phi * d, lng); } }; diff --git a/src/geo/projection/Projection.SphericalMercator.js b/src/geo/projection/Projection.SphericalMercator.js index 5425f450..cc3ad336 100644 --- a/src/geo/projection/Projection.SphericalMercator.js +++ b/src/geo/projection/Projection.SphericalMercator.js @@ -19,7 +19,6 @@ L.Projection.SphericalMercator = { lng = point.x * d, lat = (2 * Math.atan(Math.exp(point.y)) - (Math.PI / 2)) * d; - // TODO refactor LatLng wrapping - return new L.LatLng(lat, lng, true); + return new L.LatLng(lat, lng); } }; diff --git a/src/layer/GeoJSON.js b/src/layer/GeoJSON.js index d07e5d1b..79a7e558 100644 --- a/src/layer/GeoJSON.js +++ b/src/layer/GeoJSON.js @@ -111,7 +111,7 @@ L.extend(L.GeoJSON, { var lat = parseFloat(coords[reverse ? 0 : 1]), lng = parseFloat(coords[reverse ? 1 : 0]); - return new L.LatLng(lat, lng, true); + return new L.LatLng(lat, lng); }, coordsToLatLngs: function (coords, levelsDeep, reverse) { // (Array, Number, Boolean) -> Array diff --git a/src/layer/vector/Circle.js b/src/layer/vector/Circle.js index 89fd5be8..e9cbc489 100644 --- a/src/layer/vector/Circle.js +++ b/src/layer/vector/Circle.js @@ -26,7 +26,7 @@ L.Circle = L.Path.extend({ projectLatlngs: function () { var lngRadius = this._getLngRadius(), - latlng2 = new L.LatLng(this._latlng.lat, this._latlng.lng - lngRadius, true), + latlng2 = new L.LatLng(this._latlng.lat, this._latlng.lng - lngRadius), point2 = this._map.latLngToLayerPoint(latlng2); this._point = this._map.latLngToLayerPoint(this._latlng);