From e9c1c0f685cb1d8e5b9e5f637c90bd3d6203e7b4 Mon Sep 17 00:00:00 2001 From: mourner Date: Fri, 24 Sep 2010 15:47:22 +0300 Subject: [PATCH] added latLngToLayerPoint; added overlayPane; converted LatLngBounds sw/ne properties to methods. --- src/geo/LatLngBounds.js | 38 +++++++++++++++++++++++++------------- src/map/Map.js | 11 +++++++++-- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/geo/LatLngBounds.js b/src/geo/LatLngBounds.js index 4df84f7a..9117ea76 100644 --- a/src/geo/LatLngBounds.js +++ b/src/geo/LatLngBounds.js @@ -12,28 +12,40 @@ L.LatLngBounds = L.Class.extend({ // extend the bounds to contain the given point extend: function(/*LatLng*/ latlng) { - if (!this.southWest && !this.northEast) { - this.southWest = new L.LatLng(latlng.lat, latlng.lng); - this.northEast = new L.LatLng(latlng.lat, latlng.lng); + if (!this._southWest && !this._northEast) { + this._southWest = new L.LatLng(latlng.lat, latlng.lng); + this._northEast = new L.LatLng(latlng.lat, latlng.lng); } else { - this.southWest.lat = Math.min(latlng.lat, this.southWest.lat); - this.southWest.lng = Math.min(latlng.lng, this.southWest.lng); - this.northEast.lat = Math.max(latlng.lat, this.northEast.lat); - this.northEast.lng = Math.max(latlng.lng, this.northEast.lng); + this._southWest.lat = Math.min(latlng.lat, this._southWest.lat); + this._southWest.lng = Math.min(latlng.lng, this._southWest.lng); + this._northEast.lat = Math.max(latlng.lat, this._northEast.lat); + this._northEast.lng = Math.max(latlng.lng, this._northEast.lng); } }, getCenter: function() /*-> LatLng*/ { return new L.LatLng( - (this.southWest.lat + this.northEast.lat) / 2, - (this.southWest.lng + this.northEast.lng) / 2); + (this._southWest.lat + this._northEast.lat) / 2, + (this._southWest.lng + this._northEast.lng) / 2); + }, + + getSouthWest: function() { return this._southWest; }, + + getNorthEast: function() { return this._northEast; }, + + getNorthWest: function() { + return new L.LatLng(this._northEast.lat, this._southWest.lng); + }, + + getSouthEast: function() { + return new L.LatLng(this._southWest.lat, this._northEast.lng); }, contains: function(/*LatLngBounds*/ bounds) /*-> Boolean*/ { - var sw = this.southWest, - ne = this.northEast, - sw2 = bounds.southWest, - ne2 = bounds.northEast; + var sw = this._southWest, + ne = this._northEast, + sw2 = bounds.getSouthWest(), + ne2 = bounds.getNorthEast(); return (sw2.lat >= sw.lat) && (ne2.lat <= ne.lat) && (sw2.lng >= sw.lng) && (ne2.lng <= ne.lng); } diff --git a/src/map/Map.js b/src/map/Map.js index 5c4fa5c6..6b49d259 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -141,12 +141,14 @@ L.Map = L.Class.extend({ var size = this.getSize(), zoom = this.getMinZoom(), maxZoom = this.getMaxZoom(), + ne = bounds.getNorthEast(), + sw = bounds.getSouthWest(), boundsSize, nePoint, swPoint, boundsSize; do { - nePoint = this.project(bounds.northEast, zoom); - swPoint = this.project(bounds.southWest, zoom); + nePoint = this.project(ne, zoom); + swPoint = this.project(sw, zoom); boundsSize = new L.Point(nePoint.x - swPoint.x, swPoint.y - nePoint.y); zoom++; } while ((boundsSize.x <= size.x) && @@ -189,6 +191,10 @@ L.Map = L.Class.extend({ layerPointToLatLng: function(point) { return this.unproject(point.add(this._initialTopLeftPoint)); }, + + latLngToLayerPoint: function(latlng) { + return this.project(latlng).subtract(this._initialTopLeftPoint); + }, project: function(/*Object*/ coord, /*(optional) Number*/ zoom)/*-> Point*/ { var projectedPoint = this.options.projection.project(coord), @@ -218,6 +224,7 @@ L.Map = L.Class.extend({ this._panes = {}; this._panes.mapPane = this._mapPane = this._createPane('leaflet-map-pane'); this._panes.tilePane = this._createPane('leaflet-tile-pane'); + this._panes.overlayPane = this._createPane('leaflet-overlay-pane'); }, _createPane: function(className) {