diff --git a/code/boot.js b/code/boot.js index fc997a63..4ebce81f 100644 --- a/code/boot.js +++ b/code/boot.js @@ -591,6 +591,7 @@ function boot() { window.setupTaphold(); window.setupStyles(); window.setupDialogs(); + window.setupDataTileParams(); window.setupMap(); window.setupOMS(); window.search.setup(); diff --git a/code/map_data_calc_tools.js b/code/map_data_calc_tools.js index 9e0b4d9d..f4d238ad 100755 --- a/code/map_data_calc_tools.js +++ b/code/map_data_calc_tools.js @@ -10,22 +10,69 @@ // http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames +window.setupDataTileParams = function() { + // default values - used to fall back to if we can't detect those used in stock intel + var DEFAULT_ZOOM_TO_TILES_PER_EDGE = [256, 256, 256, 256, 512, 512, 512, 2048, 2048, 2048, 4096, 4096, 6500, 6500, 6500, 18e3, 18e3, 36e3]; + var DEFAULT_ZOOM_TO_LEVEL = [ 8, 8, 8, 8, 7, 7, 7, 6, 6, 5, 4, 4, 3, 2, 2, 1, 1 ]; + + + window.TILE_PARAMS = {}; + + if (niantic_params.ZOOM_TO_LEVEL && niantic_params.TILES_PER_EDGE) { + window.TILE_PARAMS.ZOOM_TO_LEVEL = niantic_params.ZOOM_TO_LEVEL; + window.TILE_PARAMS.TILES_PER_EDGE = niantic_params.TILES_PER_EDGE; + + + // lazy numerical array comparison + if ( JSON.stringify(niantic_params.ZOOM_TO_LEVEL) != JSON.stringify(DEFAULT_ZOOM_TO_LEVEL)) { + console.warn('Tile parameter ZOOM_TO_LEVEL have changed in stock intel. Detectec correct values, but code should be updated'); + debugger; + } + if ( JSON.stringify(niantic_params.TILES_PER_EDGE) != JSON.stringify(DEFAULT_ZOOM_TO_TILES_PER_EDGE)) { + console.warn('Tile parameter ZOOM_TO_LEVEL have changed in stock intel. Detectec correct values, but code should be updated'); + debugger; + } + + } else { + console.warn('Failed to detect both ZOOM_TO_LEVEL and TILES_PER_EDGE in the stock intel site - using internal defaults'); + debugger; + + window.TILE_PARAMS.ZOOM_TO_LEVEL = DEFAULT_ZOOM_TO_LEVEL; + window.TILE_PARAMS.TILES_PER_EDGE = DEFAULT_ZOOM_TO_TILES_PER_EDGE; + } + + // disable SHOW_MORE_PORTALS if it would be unfriendly to the servers (i.e. result in more requests) + // needs to be fired a bit later, after plugins have been initialised + setTimeout(function(){ + if (window.CONFIG_ZOOM_SHOW_MORE_PORTALS) { + if (window.TILE_PARAMS.TILES_PER_EDGE[17] > window.TILE_PARAMS.TILES_PER_EDGE[15]) { + var edgeScale = window.TILE_PARAMS.TILES_PER_EDGE[17]/window.TILE_PARAMS.TILES_PER_EDGE[15]; + var mapScale = edgeScale*edgeScale; + + dialog({ + title: 'Show more portals plugin disabled', + width: 400, + text: 'The "show-more-portals" plugin has been disabled.\n\n' + +'Niantic have changed the intel site so that zoom level 17 (all portals) now needs '+mapScale+' times more requests than level 15 (L1+ portals), so fetching at the wrong zoom level will be unfriendly to the servers\n\n' + }); + + window.CONFIG_ZOOM_SHOW_MORE_PORTALS=false; + } + } + }, 1); + +} + + window.getMapZoomTileParameters = function(zoom) { - var ZOOM_TO_TILES_PER_EDGE = [256, 256, 256, 256, 512, 512, 512, 2048, 2048, 2048, 4096, 4096, 6500, 6500, 6500, 18e3, 18e3, 36e3]; - var ZOOM_TO_LEVEL = [ 8, 8, 8, 8, 7, 7, 7, 6, 6, 5, 4, 4, 3, 2, 2, 1, 1 ]; - if (niantic_params.ZOOM_TO_LEVEL && niantic_params.TILES_PER_EDGE) { - ZOOM_TO_LEVEL = niantic_params.ZOOM_TO_LEVEL; - ZOOM_TO_TILES_PER_EDGE = niantic_params.TILES_PER_EDGE; - } - - // the current API allows the client to request a minimum portal level. the ZOOM_TO_LEVEL list are minimums + // the current API allows the client to request a minimum portal level. the window.TILE_PARAMS.ZOOM_TO_LEVEL list are minimums // however, in my view, this can return excessive numbers of portals in many cases. let's try an optional reduction // of detail level at some zoom levels - var level = ZOOM_TO_LEVEL[zoom] || 0; // default to level 0 (all portals) if not in array + var level = window.TILE_PARAMS.ZOOM_TO_LEVEL[zoom] || 0; // default to level 0 (all portals) if not in array if (window.CONFIG_ZOOM_SHOW_LESS_PORTALS_ZOOMED_OUT) { if (level <= 7 && level >= 4) { @@ -34,12 +81,12 @@ window.getMapZoomTileParameters = function(zoom) { } } - var maxTilesPerEdge = ZOOM_TO_TILES_PER_EDGE[ZOOM_TO_TILES_PER_EDGE.length-1]; + var maxTilesPerEdge = window.TILE_PARAMS.TILES_PER_EDGE[window.TILE_PARAMS.TILES_PER_EDGE.length-1]; return { level: level, - maxLevel: ZOOM_TO_LEVEL[zoom] || 0, // for reference, for log purposes, etc - tilesPerEdge: ZOOM_TO_TILES_PER_EDGE[zoom] || maxTilesPerEdge, + maxLevel: window.TILE_PARAMS.ZOOM_TO_LEVEL[zoom] || 0, // for reference, for log purposes, etc + tilesPerEdge: window.TILE_PARAMS.TILES_PER_EDGE[zoom] || maxTilesPerEdge, zoom: zoom // include the zoom level, for reference }; } @@ -48,7 +95,7 @@ window.getMapZoomTileParameters = function(zoom) { window.getDataZoomForMapZoom = function(zoom) { // we can fetch data at a zoom level different to the map zoom. - //NOTE: the specifics of this are tightly coupled with the above ZOOM_TO_LEVEL and ZOOM_TO_TILES_PER_EDGE arrays + //NOTE: the specifics of this are tightly coupled with the above ZOOM_TO_LEVEL and TILES_PER_EDGE arrays // firstly, some of IITCs zoom levels, depending on base map layer, can be higher than stock. limit zoom level // (stock site max zoom may vary depending on google maps detail in the area - 20 or 21 max is common)