protocol changes 2014-02-22 - quadkeys have gone back to using map zoom, rather than portal level, in their names
This commit is contained in:
@ -10,32 +10,34 @@
|
|||||||
// http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames
|
// http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames
|
||||||
|
|
||||||
|
|
||||||
window.levelToTilesPerEdge = function(level) {
|
window.zoomToTilesPerEdge = function(zoom) {
|
||||||
var LEVEL_TO_TILES_PER_EDGE = [65536, 65536, 16384, 16384, 4096, 1536, 1024, 256, 32];
|
// var LEVEL_TO_TILES_PER_EDGE = [65536, 65536, 16384, 16384, 4096, 1536, 1024, 256, 32];
|
||||||
return LEVEL_TO_TILES_PER_EDGE[level];
|
// return LEVEL_TO_TILES_PER_EDGE[level];
|
||||||
|
var ZOOM_TO_TILES_PER_EDGE = [32, 32, 32, 32, 256, 256, 256, 1024, 1024, 1536, 4096, 4096, 16384, 16384, 16384];
|
||||||
|
return ZOOM_TO_TILES_PER_EDGE[zoom] || 65536;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
window.lngToTile = function(lng, level) {
|
window.lngToTile = function(lng, zoom) {
|
||||||
return Math.floor((lng + 180) / 360 * levelToTilesPerEdge(level));
|
return Math.floor((lng + 180) / 360 * zoomToTilesPerEdge(zoom));
|
||||||
}
|
}
|
||||||
|
|
||||||
window.latToTile = function(lat, level) {
|
window.latToTile = function(lat, zoom) {
|
||||||
return Math.floor((1 - Math.log(Math.tan(lat * Math.PI / 180) +
|
return Math.floor((1 - Math.log(Math.tan(lat * Math.PI / 180) +
|
||||||
1 / Math.cos(lat * Math.PI / 180)) / Math.PI) / 2 * levelToTilesPerEdge(level));
|
1 / Math.cos(lat * Math.PI / 180)) / Math.PI) / 2 * zoomToTilesPerEdge(zoom));
|
||||||
}
|
}
|
||||||
|
|
||||||
window.tileToLng = function(x, level) {
|
window.tileToLng = function(x, zoom) {
|
||||||
return x / levelToTilesPerEdge(level) * 360 - 180;
|
return x / zoomToTilesPerEdge(zoom) * 360 - 180;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.tileToLat = function(y, level) {
|
window.tileToLat = function(y, zoom) {
|
||||||
var n = Math.PI - 2 * Math.PI * y / levelToTilesPerEdge(level);
|
var n = Math.PI - 2 * Math.PI * y / zoomToTilesPerEdge(zoom);
|
||||||
return 180 / Math.PI * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
|
return 180 / Math.PI * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
|
||||||
}
|
}
|
||||||
|
|
||||||
window.pointToTileId = function(level, x, y) {
|
window.pointToTileId = function(zoom, x, y) {
|
||||||
return level + "_" + x + "_" + y;
|
return zoom + "_" + x + "_" + y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -180,6 +180,7 @@ window.MapDataRequest.prototype.refresh = function() {
|
|||||||
|
|
||||||
var bounds = clampLatLngBounds(map.getBounds());
|
var bounds = clampLatLngBounds(map.getBounds());
|
||||||
var zoom = map.getZoom();
|
var zoom = map.getZoom();
|
||||||
|
//TODO: fix this: the API now takes zoom (again) rather than portal level, so we need to go back to more like the old API
|
||||||
var minPortalLevel = getMinPortalLevelForZoom(zoom);
|
var minPortalLevel = getMinPortalLevelForZoom(zoom);
|
||||||
|
|
||||||
//DEBUG: resize the bounds so we only retrieve some data
|
//DEBUG: resize the bounds so we only retrieve some data
|
||||||
@ -188,21 +189,21 @@ window.MapDataRequest.prototype.refresh = function() {
|
|||||||
//var debugrect = L.rectangle(bounds,{color: 'red', fill: false, weight: 4, opacity: 0.8}).addTo(map);
|
//var debugrect = L.rectangle(bounds,{color: 'red', fill: false, weight: 4, opacity: 0.8}).addTo(map);
|
||||||
//setTimeout (function(){ map.removeLayer(debugrect); }, 10*1000);
|
//setTimeout (function(){ map.removeLayer(debugrect); }, 10*1000);
|
||||||
|
|
||||||
var x1 = lngToTile(bounds.getWest(), minPortalLevel);
|
var x1 = lngToTile(bounds.getWest(), zoom);
|
||||||
var x2 = lngToTile(bounds.getEast(), minPortalLevel);
|
var x2 = lngToTile(bounds.getEast(), zoom);
|
||||||
var y1 = latToTile(bounds.getNorth(), minPortalLevel);
|
var y1 = latToTile(bounds.getNorth(), zoom);
|
||||||
var y2 = latToTile(bounds.getSouth(), minPortalLevel);
|
var y2 = latToTile(bounds.getSouth(), zoom);
|
||||||
|
|
||||||
// calculate the full bounds for the data - including the part of the tiles off the screen edge
|
// calculate the full bounds for the data - including the part of the tiles off the screen edge
|
||||||
var dataBounds = L.latLngBounds([
|
var dataBounds = L.latLngBounds([
|
||||||
[tileToLat(y2+1,minPortalLevel), tileToLng(x1,minPortalLevel)],
|
[tileToLat(y2+1,zoom), tileToLng(x1,zoom)],
|
||||||
[tileToLat(y1,minPortalLevel), tileToLng(x2+1,minPortalLevel)]
|
[tileToLat(y1,zoom), tileToLng(x2+1,zoom)]
|
||||||
]);
|
]);
|
||||||
//var debugrect2 = L.rectangle(dataBounds,{color: 'magenta', fill: false, weight: 4, opacity: 0.8}).addTo(map);
|
//var debugrect2 = L.rectangle(dataBounds,{color: 'magenta', fill: false, weight: 4, opacity: 0.8}).addTo(map);
|
||||||
//setTimeout (function(){ map.removeLayer(debugrect2); }, 10*1000);
|
//setTimeout (function(){ map.removeLayer(debugrect2); }, 10*1000);
|
||||||
|
|
||||||
// store the parameters used for fetching the data. used to prevent unneeded refreshes after move/zoom
|
// store the parameters used for fetching the data. used to prevent unneeded refreshes after move/zoom
|
||||||
this.fetchedDataParams = { bounds: dataBounds, mapZoom: map.getZoom(), minPortalLevel: minPortalLevel };
|
this.fetchedDataParams = { bounds: dataBounds, mapZoom: map.getZoom(), minPortalLevel: minPortalLevel, zoom: zoom };
|
||||||
|
|
||||||
|
|
||||||
window.runHooks ('mapDataRefreshStart', {bounds: bounds, zoom: zoom, minPortalLevel: minPortalLevel, tileBounds: dataBounds});
|
window.runHooks ('mapDataRefreshStart', {bounds: bounds, zoom: zoom, minPortalLevel: minPortalLevel, tileBounds: dataBounds});
|
||||||
@ -235,11 +236,11 @@ window.MapDataRequest.prototype.refresh = function() {
|
|||||||
for (var y = y1; y <= y2; y++) {
|
for (var y = y1; y <= y2; y++) {
|
||||||
// x goes from bottom to top(?)
|
// x goes from bottom to top(?)
|
||||||
for (var x = x1; x <= x2; x++) {
|
for (var x = x1; x <= x2; x++) {
|
||||||
var tile_id = pointToTileId(minPortalLevel, x, y);
|
var tile_id = pointToTileId(zoom, x, y);
|
||||||
var latNorth = tileToLat(y,minPortalLevel);
|
var latNorth = tileToLat(y,zoom);
|
||||||
var latSouth = tileToLat(y+1,minPortalLevel);
|
var latSouth = tileToLat(y+1,zoom);
|
||||||
var lngWest = tileToLng(x,minPortalLevel);
|
var lngWest = tileToLng(x,zoom);
|
||||||
var lngEast = tileToLng(x+1,minPortalLevel);
|
var lngEast = tileToLng(x+1,zoom);
|
||||||
|
|
||||||
this.debugTiles.create(tile_id,[[latSouth,lngWest],[latNorth,lngEast]]);
|
this.debugTiles.create(tile_id,[[latSouth,lngWest],[latNorth,lngEast]]);
|
||||||
|
|
||||||
|
@ -280,14 +280,9 @@ window.androidPermalink = function() {
|
|||||||
|
|
||||||
|
|
||||||
window.getMinPortalLevelForZoom = function(z) {
|
window.getMinPortalLevelForZoom = function(z) {
|
||||||
|
var ZOOM_TO_LEVEL = [8, 8, 8, 8, 7, 7, 7, 6, 6, 5, 4, 4, 3, 2, 2, 1, 1];
|
||||||
|
|
||||||
// these values are from the stock intel map. however, they're too detailed for reasonable speed, and increasing
|
return ZOOM_TO_LEVEL[z] || 0;
|
||||||
// detail at a higher zoom level shows enough detail still, AND speeds up IITC considerably
|
|
||||||
//var ZOOM_TO_LEVEL = [8, 8, 8, 8, 7, 7, 7, 6, 6, 5, 4, 4, 3, 2, 2, 1, 1];
|
|
||||||
var ZOOM_TO_LEVEL = [8, 8, 8, 8, 8, 7, 7, 7, 6, 5, 4, 4, 3, 2, 2, 1, 1];
|
|
||||||
|
|
||||||
var l = ZOOM_TO_LEVEL[z] || 0;
|
|
||||||
return l;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user