added latLngToLayerPoint; added overlayPane; converted LatLngBounds sw/ne properties to methods.

This commit is contained in:
mourner 2010-09-24 15:47:22 +03:00
parent 268aee8ad3
commit e9c1c0f685
2 changed files with 34 additions and 15 deletions

View File

@ -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);
}

View File

@ -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) &&
@ -190,6 +192,10 @@ L.Map = L.Class.extend({
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),
scale = this.options.scaling(isNaN(zoom) ? this._zoom : zoom);
@ -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) {