internal cleanups on the API used to convert map zoom levels to the parameters needed to generate quadkeys for data tiles.
this should also prevent mixed release plugins/test IITC builds causing issues with it's 'show more portals' plugin further changes are planned - by lying to the backend about the map zoom to optimise the portal detail level (density) returned and make better use of the data cache. needs some practical experimentation to get good adjustments, and a cleaner API for these plugins
This commit is contained in:
parent
336393a76d
commit
8ce28334cc
@ -10,34 +10,42 @@
|
|||||||
// http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames
|
// http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames
|
||||||
|
|
||||||
|
|
||||||
window.zoomToTilesPerEdge = function(zoom) {
|
window.getMapZoomTileParameters = function(zoom) {
|
||||||
// var LEVEL_TO_TILES_PER_EDGE = [65536, 65536, 16384, 16384, 4096, 1536, 1024, 256, 32];
|
// these arrays/constants are based on those in the stock intel site. it's essential we keep them in sync with their code
|
||||||
// return LEVEL_TO_TILES_PER_EDGE[level];
|
// (it may be worth reading the values from their code rather than using our own copies? it's a case of either
|
||||||
|
// breaking if they rename their variables if we do, or breaking if they change the values if we don't)
|
||||||
var ZOOM_TO_TILES_PER_EDGE = [32, 32, 32, 32, 256, 256, 256, 1024, 1024, 1536, 4096, 4096, 16384, 16384, 16384];
|
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;
|
var MAX_TILES_PER_EDGE = 65536;
|
||||||
|
var ZOOM_TO_LEVEL = [8, 8, 8, 8, 7, 7, 7, 6, 6, 5, 4, 4, 3, 2, 2, 1, 1];
|
||||||
|
|
||||||
|
return {
|
||||||
|
level: ZOOM_TO_LEVEL[zoom] || 0, // default to level 0 (all portals) if not in array
|
||||||
|
tilesPerEdge: ZOOM_TO_TILES_PER_EDGE[zoom] || MAX_TILES_PER_EDGE,
|
||||||
|
zoom: zoom // include the zoom level, for reference
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
window.lngToTile = function(lng, zoom) {
|
window.lngToTile = function(lng, params) {
|
||||||
return Math.floor((lng + 180) / 360 * zoomToTilesPerEdge(zoom));
|
return Math.floor((lng + 180) / 360 * params.tilesPerEdge);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.latToTile = function(lat, zoom) {
|
window.latToTile = function(lat, params) {
|
||||||
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 * zoomToTilesPerEdge(zoom));
|
1 / Math.cos(lat * Math.PI / 180)) / Math.PI) / 2 * params.tilesPerEdge);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.tileToLng = function(x, zoom) {
|
window.tileToLng = function(x, params) {
|
||||||
return x / zoomToTilesPerEdge(zoom) * 360 - 180;
|
return x / params.tilesPerEdge * 360 - 180;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.tileToLat = function(y, zoom) {
|
window.tileToLat = function(y, params) {
|
||||||
var n = Math.PI - 2 * Math.PI * y / zoomToTilesPerEdge(zoom);
|
var n = Math.PI - 2 * Math.PI * y / params.tilesPerEdge;
|
||||||
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(zoom, x, y) {
|
window.pointToTileId = function(params, x, y) {
|
||||||
return zoom + "_" + x + "_" + y;
|
return params.zoom + "_" + x + "_" + y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -180,8 +180,8 @@ 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 tileParams = getMapZoomTileParameters(zoom);
|
||||||
|
|
||||||
//DEBUG: resize the bounds so we only retrieve some data
|
//DEBUG: resize the bounds so we only retrieve some data
|
||||||
//bounds = bounds.pad(-0.4);
|
//bounds = bounds.pad(-0.4);
|
||||||
@ -189,36 +189,34 @@ 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(), zoom);
|
var x1 = lngToTile(bounds.getWest(), tileParams);
|
||||||
var x2 = lngToTile(bounds.getEast(), zoom);
|
var x2 = lngToTile(bounds.getEast(), tileParams);
|
||||||
var y1 = latToTile(bounds.getNorth(), zoom);
|
var y1 = latToTile(bounds.getNorth(), tileParams);
|
||||||
var y2 = latToTile(bounds.getSouth(), zoom);
|
var y2 = latToTile(bounds.getSouth(), tileParams);
|
||||||
|
|
||||||
// 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,zoom), tileToLng(x1,zoom)],
|
[tileToLat(y2+1,tileParams), tileToLng(x1,tileParams)],
|
||||||
[tileToLat(y1,zoom), tileToLng(x2+1,zoom)]
|
[tileToLat(y1,tileParams), tileToLng(x2+1,tileParams)]
|
||||||
]);
|
]);
|
||||||
//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, zoom: zoom };
|
this.fetchedDataParams = { bounds: dataBounds, mapZoom: map.getZoom(), zoom: zoom };
|
||||||
|
|
||||||
|
|
||||||
window.runHooks ('mapDataRefreshStart', {bounds: bounds, zoom: zoom, minPortalLevel: minPortalLevel, tileBounds: dataBounds});
|
window.runHooks ('mapDataRefreshStart', {bounds: bounds, zoom: zoom, minPortalLevel: tileParams.level, tileBounds: dataBounds});
|
||||||
|
|
||||||
this.render.startRenderPass();
|
this.render.startRenderPass();
|
||||||
this.render.clearPortalsBelowLevel(minPortalLevel);
|
this.render.clearPortalsBelowLevel(tileParams.level);
|
||||||
|
|
||||||
|
|
||||||
this.render.clearEntitiesOutsideBounds(dataBounds);
|
this.render.clearEntitiesOutsideBounds(dataBounds);
|
||||||
|
|
||||||
this.render.updateEntityVisibility();
|
this.render.updateEntityVisibility();
|
||||||
|
|
||||||
this.render.processGameEntities(artifact.getArtifactEntities());
|
this.render.processGameEntities(artifact.getArtifactEntities());
|
||||||
|
|
||||||
console.log('requesting data tiles at zoom '+zoom+' (L'+minPortalLevel+'+ portals), map zoom is '+map.getZoom());
|
console.log('requesting data tiles at zoom '+zoom+' (L'+tileParams.level+'+ portals, '+tileParams.tilesPerEdge+' tiles per global edge), map zoom is '+map.getZoom());
|
||||||
|
|
||||||
|
|
||||||
this.cachedTileCount = 0;
|
this.cachedTileCount = 0;
|
||||||
@ -236,11 +234,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(zoom, x, y);
|
var tile_id = pointToTileId(tileParams, x, y);
|
||||||
var latNorth = tileToLat(y,zoom);
|
var latNorth = tileToLat(y,tileParams);
|
||||||
var latSouth = tileToLat(y+1,zoom);
|
var latSouth = tileToLat(y+1,tileParams);
|
||||||
var lngWest = tileToLng(x,zoom);
|
var lngWest = tileToLng(x,tileParams);
|
||||||
var lngEast = tileToLng(x+1,zoom);
|
var lngEast = tileToLng(x+1,tileParams);
|
||||||
|
|
||||||
this.debugTiles.create(tile_id,[[latSouth,lngWest],[latNorth,lngEast]]);
|
this.debugTiles.create(tile_id,[[latSouth,lngWest],[latNorth,lngEast]]);
|
||||||
|
|
||||||
|
@ -279,16 +279,10 @@ 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];
|
|
||||||
|
|
||||||
return ZOOM_TO_LEVEL[z] || 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
window.getMinPortalLevel = function() {
|
window.getMinPortalLevel = function() {
|
||||||
var z = map.getZoom();
|
var z = map.getZoom();
|
||||||
return getMinPortalLevelForZoom(z);
|
return getMapZoomTileParameters(z).level;
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns number of pixels left to scroll down before reaching the
|
// returns number of pixels left to scroll down before reaching the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user