OpenStreetMap wraps X and crops Y
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
goog.provide('ol.TileStore');
|
||||
goog.provide('ol.TileStore.createOpenStreetMap');
|
||||
|
||||
goog.require('goog.math');
|
||||
goog.require('ol.Store');
|
||||
goog.require('ol.Tile');
|
||||
goog.require('ol.TileCoord');
|
||||
@@ -63,7 +64,14 @@ ol.TileStore.createOpenStreetMap = function() {
|
||||
var tileGrid = ol.TileGrid.createOpenStreetMap(18);
|
||||
var tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
|
||||
function(tileCoord) {
|
||||
return new ol.TileCoord(tileCoord.z, tileCoord.x, -tileCoord.y - 1);
|
||||
var n = 1 << tileCoord.z;
|
||||
var y = -tileCoord.y - 1;
|
||||
if (y < 0 || n <= y) {
|
||||
return null;
|
||||
} else {
|
||||
var x = goog.math.modulo(tileCoord.x, n);
|
||||
return new ol.TileCoord(tileCoord.z, x, y);
|
||||
}
|
||||
},
|
||||
ol.TileUrlFunction.createFromTemplates([
|
||||
'http://a.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
goog.require('goog.testing.jsunit');
|
||||
goog.require('ol.TileCoord');
|
||||
goog.require('ol.TileStore.createOpenStreetMap');
|
||||
|
||||
|
||||
function getTileCoordPart(tileUrl) {
|
||||
return tileUrl.substr(32, tileUrl.length - 36);
|
||||
}
|
||||
|
||||
|
||||
function testOpenStreetMap() {
|
||||
|
||||
var tileStore = ol.TileStore.createOpenStreetMap(8);
|
||||
@@ -11,10 +17,6 @@ function testOpenStreetMap() {
|
||||
new goog.math.Coordinate(829330.2064098881, 5933916.615134273);
|
||||
var tileUrl;
|
||||
|
||||
var getTileCoordPart = function(tileUrl) {
|
||||
return tileUrl.substr(32, tileUrl.length - 36);
|
||||
};
|
||||
|
||||
tileUrl = tileStore.getTileCoordUrl(tileGrid.getTileCoord(0, coordinate));
|
||||
assertEquals('0/0/0', getTileCoordPart(tileUrl));
|
||||
|
||||
@@ -37,3 +39,35 @@ function testOpenStreetMap() {
|
||||
assertEquals('6/33/22', getTileCoordPart(tileUrl));
|
||||
|
||||
}
|
||||
|
||||
|
||||
function testOpenStreetMapWrapX() {
|
||||
|
||||
var tileStore = ol.TileStore.createOpenStreetMap(8);
|
||||
|
||||
tileUrl = tileStore.getTileCoordUrl(new ol.TileCoord(6, -31, -23));
|
||||
assertEquals('6/33/22', getTileCoordPart(tileUrl));
|
||||
|
||||
tileUrl = tileStore.getTileCoordUrl(new ol.TileCoord(6, 33, -23));
|
||||
assertEquals('6/33/22', getTileCoordPart(tileUrl));
|
||||
|
||||
tileUrl = tileStore.getTileCoordUrl(new ol.TileCoord(6, 97, -23));
|
||||
assertEquals('6/33/22', getTileCoordPart(tileUrl));
|
||||
|
||||
}
|
||||
|
||||
|
||||
function testOpenStreetMapCropY() {
|
||||
|
||||
var tileStore = ol.TileStore.createOpenStreetMap(8);
|
||||
|
||||
tileUrl = tileStore.getTileCoordUrl(new ol.TileCoord(6, 33, -87));
|
||||
assertUndefined(tileUrl);
|
||||
|
||||
tileUrl = tileStore.getTileCoordUrl(new ol.TileCoord(6, 33, -23));
|
||||
assertEquals('6/33/22', getTileCoordPart(tileUrl));
|
||||
|
||||
tileUrl = tileStore.getTileCoordUrl(new ol.TileCoord(6, 33, 41));
|
||||
assertUndefined(tileUrl);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user