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
|
||||
|
||||
|
||||
window.levelToTilesPerEdge = function(level) {
|
||||
var LEVEL_TO_TILES_PER_EDGE = [65536, 65536, 16384, 16384, 4096, 1536, 1024, 256, 32];
|
||||
return LEVEL_TO_TILES_PER_EDGE[level];
|
||||
window.zoomToTilesPerEdge = function(zoom) {
|
||||
// var LEVEL_TO_TILES_PER_EDGE = [65536, 65536, 16384, 16384, 4096, 1536, 1024, 256, 32];
|
||||
// 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) {
|
||||
return Math.floor((lng + 180) / 360 * levelToTilesPerEdge(level));
|
||||
window.lngToTile = function(lng, zoom) {
|
||||
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) +
|
||||
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) {
|
||||
return x / levelToTilesPerEdge(level) * 360 - 180;
|
||||
window.tileToLng = function(x, zoom) {
|
||||
return x / zoomToTilesPerEdge(zoom) * 360 - 180;
|
||||
}
|
||||
|
||||
window.tileToLat = function(y, level) {
|
||||
var n = Math.PI - 2 * Math.PI * y / levelToTilesPerEdge(level);
|
||||
window.tileToLat = function(y, zoom) {
|
||||
var n = Math.PI - 2 * Math.PI * y / zoomToTilesPerEdge(zoom);
|
||||
return 180 / Math.PI * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
|
||||
}
|
||||
|
||||
window.pointToTileId = function(level, x, y) {
|
||||
return level + "_" + x + "_" + y;
|
||||
window.pointToTileId = function(zoom, x, y) {
|
||||
return zoom + "_" + x + "_" + y;
|
||||
}
|
||||
|
||||
|
||||
|
@ -180,6 +180,7 @@ window.MapDataRequest.prototype.refresh = function() {
|
||||
|
||||
var bounds = clampLatLngBounds(map.getBounds());
|
||||
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);
|
||||
|
||||
//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);
|
||||
//setTimeout (function(){ map.removeLayer(debugrect); }, 10*1000);
|
||||
|
||||
var x1 = lngToTile(bounds.getWest(), minPortalLevel);
|
||||
var x2 = lngToTile(bounds.getEast(), minPortalLevel);
|
||||
var y1 = latToTile(bounds.getNorth(), minPortalLevel);
|
||||
var y2 = latToTile(bounds.getSouth(), minPortalLevel);
|
||||
var x1 = lngToTile(bounds.getWest(), zoom);
|
||||
var x2 = lngToTile(bounds.getEast(), zoom);
|
||||
var y1 = latToTile(bounds.getNorth(), zoom);
|
||||
var y2 = latToTile(bounds.getSouth(), zoom);
|
||||
|
||||
// calculate the full bounds for the data - including the part of the tiles off the screen edge
|
||||
var dataBounds = L.latLngBounds([
|
||||
[tileToLat(y2+1,minPortalLevel), tileToLng(x1,minPortalLevel)],
|
||||
[tileToLat(y1,minPortalLevel), tileToLng(x2+1,minPortalLevel)]
|
||||
[tileToLat(y2+1,zoom), tileToLng(x1,zoom)],
|
||||
[tileToLat(y1,zoom), tileToLng(x2+1,zoom)]
|
||||
]);
|
||||
//var debugrect2 = L.rectangle(dataBounds,{color: 'magenta', fill: false, weight: 4, opacity: 0.8}).addTo(map);
|
||||
//setTimeout (function(){ map.removeLayer(debugrect2); }, 10*1000);
|
||||
|
||||
// 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});
|
||||
@ -235,11 +236,11 @@ window.MapDataRequest.prototype.refresh = function() {
|
||||
for (var y = y1; y <= y2; y++) {
|
||||
// x goes from bottom to top(?)
|
||||
for (var x = x1; x <= x2; x++) {
|
||||
var tile_id = pointToTileId(minPortalLevel, x, y);
|
||||
var latNorth = tileToLat(y,minPortalLevel);
|
||||
var latSouth = tileToLat(y+1,minPortalLevel);
|
||||
var lngWest = tileToLng(x,minPortalLevel);
|
||||
var lngEast = tileToLng(x+1,minPortalLevel);
|
||||
var tile_id = pointToTileId(zoom, x, y);
|
||||
var latNorth = tileToLat(y,zoom);
|
||||
var latSouth = tileToLat(y+1,zoom);
|
||||
var lngWest = tileToLng(x,zoom);
|
||||
var lngEast = tileToLng(x+1,zoom);
|
||||
|
||||
this.debugTiles.create(tile_id,[[latSouth,lngWest],[latNorth,lngEast]]);
|
||||
|
||||
|
@ -280,14 +280,9 @@ window.androidPermalink = function() {
|
||||
|
||||
|
||||
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
|
||||
// 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;
|
||||
return ZOOM_TO_LEVEL[z] || 0;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user