From 4f6631d1f7a9c21754da47a91497575dd8883ca0 Mon Sep 17 00:00:00 2001 From: Jon Atkins Date: Tue, 11 Mar 2014 02:29:21 +0000 Subject: [PATCH] make IITC first try to use the TILES_PER_EDGE and ZOOM_TO_LEVEL values from the stock script - only falling back (with a warning) to our pre-defined list on error this way we automatically follow any changes to these made in the stock site, but have a fallback case in case the stock site renames the variables --- code/map_data_calc_tools.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/code/map_data_calc_tools.js b/code/map_data_calc_tools.js index 15bf1bd4..db56ebbf 100755 --- a/code/map_data_calc_tools.js +++ b/code/map_data_calc_tools.js @@ -11,12 +11,28 @@ window.getMapZoomTileParameters = function(zoom) { - // these arrays/constants are based on those in the stock intel site. it's essential we keep them in sync with their code - // (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 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]; + // attempt to use the values from the stock site. this way, if they're changed, IITC should continue to work + // however, if Niantic rename things, it would fail, so we'll fall back to the current known values + var ZOOM_TO_TILES_PER_EDGE, MAX_TILES_PER_EDGE, ZOOM_TO_LEVEL; + try { + ZOOM_TO_TILES_PER_EDGE = nemesis.dashboard.mercator.Tile.ZOOM_TO_NUM_TILES_PER_EDGE_; + if (ZOOM_TO_TILES_PER_EDGE === undefined) throw('ZOOM_TO_TILES_PER_EDGE not found'); + MAX_TILES_PER_EDGE = nemesis.dashboard.mercator.Tile.MAX_NUM_TILES_PER_EDGE_; + if (MAX_TILES_PER_EDGE === undefined) throw('MAX_TILES_PER_EDGE not found'); + ZOOM_TO_LEVEL = nemesis.dashboard.zoomlevel.ZOOM_TO_LOD_; + if (ZOOM_TO_LEVEL === undefined) throw('ZOOM_TO_LEVEL not found'); + } catch(e) { + console.warn(e); + + // known correct as of 2014-03-11 + ZOOM_TO_TILES_PER_EDGE = [32, 32, 32, 32, 256, 256, 256, 1024, 1024, 1536, 4096, 4096, 16384, 16384, 16384]; + MAX_TILES_PER_EDGE = 65536; + ZOOM_TO_LEVEL = [8, 8, 8, 8, 7, 7, 7, 6, 6, 5, 4, 4, 3, 2, 2, 1, 1]; + + // for developers, let's stop in the debugger + debugger; + } + return { level: ZOOM_TO_LEVEL[zoom] || 0, // default to level 0 (all portals) if not in array