add CRS & Map wrapLatLng, fix GridLayer bounding
This commit is contained in:
parent
0305b593fe
commit
a03bfb753e
@ -45,13 +45,13 @@ describe("CRS.EPSG3857", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#getSize", function () {
|
describe("#getProjectedBounds", function () {
|
||||||
it("gives correct size", function () {
|
it("gives correct size", function () {
|
||||||
var i,
|
var i,
|
||||||
worldSize = 256,
|
worldSize = 256,
|
||||||
crsSize;
|
crsSize;
|
||||||
for (i = 0; i <= 22; i++) {
|
for (i = 0; i <= 22; i++) {
|
||||||
crsSize = crs.getSize(i);
|
crsSize = crs.getProjectedBounds(i).getSize();
|
||||||
expect(crsSize.x).equal(worldSize);
|
expect(crsSize.x).equal(worldSize);
|
||||||
expect(crsSize.y).equal(worldSize);
|
expect(crsSize.y).equal(worldSize);
|
||||||
worldSize *= 2;
|
worldSize *= 2;
|
||||||
@ -69,7 +69,7 @@ describe("CRS.EPSG4326", function () {
|
|||||||
worldSize = 256,
|
worldSize = 256,
|
||||||
crsSize;
|
crsSize;
|
||||||
for (i = 0; i <= 22; i++) {
|
for (i = 0; i <= 22; i++) {
|
||||||
crsSize = crs.getSize(i);
|
crsSize = crs.getProjectedBounds(i).getSize();
|
||||||
expect(crsSize.x).equal(worldSize * 2);
|
expect(crsSize.x).equal(worldSize * 2);
|
||||||
// Lat bounds are half as high (-90/+90 compared to -180/+180)
|
// Lat bounds are half as high (-90/+90 compared to -180/+180)
|
||||||
expect(crsSize.y).equal(worldSize);
|
expect(crsSize.y).equal(worldSize);
|
||||||
|
@ -25,12 +25,32 @@ L.CRS = {
|
|||||||
return 256 * Math.pow(2, zoom);
|
return 256 * Math.pow(2, zoom);
|
||||||
},
|
},
|
||||||
|
|
||||||
getSize: function (zoom) {
|
getProjectedBounds: function (zoom) {
|
||||||
var b = this.projection.bounds,
|
var b = this.projection.bounds,
|
||||||
s = this.scale(zoom),
|
s = this.scale(zoom),
|
||||||
min = this.transformation.transform(b.min, s),
|
min = this.transformation.transform(b.min, s),
|
||||||
max = this.transformation.transform(b.max, s);
|
max = this.transformation.transform(b.max, s);
|
||||||
|
|
||||||
return L.point(Math.abs(max.x - min.x), Math.abs(max.y - min.y));
|
return L.bounds(min, max);
|
||||||
|
},
|
||||||
|
|
||||||
|
getBounds: function () {
|
||||||
|
var proj = this.projection,
|
||||||
|
min = proj.unproject(proj.bounds.min),
|
||||||
|
max = proj.unproject(proj.bounds.max);
|
||||||
|
|
||||||
|
return L.latLngBounds(min, max);
|
||||||
|
},
|
||||||
|
|
||||||
|
wrapLatLng: function (latlng) {
|
||||||
|
var bounds = this.getBounds(),
|
||||||
|
lng = this.wrapLng ? this._wrap(latlng.lng, bounds.getWest(), bounds.getEast()) : latlng.lng,
|
||||||
|
lat = this.wrapLat ? this._wrap(latlng.lat, bounds.getSouth(), bounds.getNorth()) : latlng.lat;
|
||||||
|
|
||||||
|
return L.latLng(lat, lng);
|
||||||
|
},
|
||||||
|
|
||||||
|
_wrap: function (value, min, max) {
|
||||||
|
return (value + max) % (max - min) + (value < min || value === max ? max : min);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -309,13 +309,14 @@ L.GridLayer = L.Class.extend({
|
|||||||
|
|
||||||
_tileCoordsToBounds: function (coords) {
|
_tileCoordsToBounds: function (coords) {
|
||||||
|
|
||||||
var tileSize = this.options.tileSize,
|
var map = this._map,
|
||||||
|
tileSize = this.options.tileSize,
|
||||||
|
|
||||||
nwPoint = coords.multiplyBy(tileSize),
|
nwPoint = coords.multiplyBy(tileSize),
|
||||||
sePoint = nwPoint.add([tileSize, tileSize]),
|
sePoint = nwPoint.add([tileSize, tileSize]),
|
||||||
|
|
||||||
nw = this._map.unproject(nwPoint, coords.z),
|
nw = map.wrapLatLng(map.unproject(nwPoint, coords.z)),
|
||||||
se = this._map.unproject(sePoint, coords.z);
|
se = map.wrapLatLng(map.unproject(sePoint, coords.z));
|
||||||
|
|
||||||
return new L.LatLngBounds(nw, se);
|
return new L.LatLngBounds(nw, se);
|
||||||
},
|
},
|
||||||
|
@ -392,7 +392,7 @@ L.Map = L.Class.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
getWorldPixelSize: function () {
|
getWorldPixelSize: function () {
|
||||||
return this.options.crs.getSize(this.getZoom());
|
return this.options.crs.getProjectedBounds(this.getZoom()).getSize();
|
||||||
},
|
},
|
||||||
|
|
||||||
getPanes: function () {
|
getPanes: function () {
|
||||||
@ -438,6 +438,10 @@ L.Map = L.Class.extend({
|
|||||||
return projectedPoint._subtract(this.getPixelOrigin());
|
return projectedPoint._subtract(this.getPixelOrigin());
|
||||||
},
|
},
|
||||||
|
|
||||||
|
wrapLatLng: function (latlng) {
|
||||||
|
return this.options.crs.wrapLatLng(latlng);
|
||||||
|
},
|
||||||
|
|
||||||
containerPointToLayerPoint: function (point) { // (Point)
|
containerPointToLayerPoint: function (point) { // (Point)
|
||||||
return L.point(point).subtract(this._getMapPanePos());
|
return L.point(point).subtract(this._getMapPanePos());
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user