From 34fa12a132e000589f663853c689a944ed0d03ea Mon Sep 17 00:00:00 2001 From: john gravois Date: Thu, 14 Jun 2018 13:18:00 -0700 Subject: [PATCH] use existing method to trigger tilemap --- modules/renderer/background_source.js | 70 ++++++++++++++------------- modules/ui/notice.js | 8 +++ 2 files changed, 44 insertions(+), 34 deletions(-) diff --git a/modules/renderer/background_source.js b/modules/renderer/background_source.js index 0543b2e06..ceb4bda5a 100644 --- a/modules/renderer/background_source.js +++ b/modules/renderer/background_source.js @@ -296,6 +296,42 @@ rendererBackgroundSource.Esri = function(data) { cache = {}, inflight = {}; + // use a tilemap service to set maximum zoom for esri tiles dynamically + // https://developers.arcgis.com/documentation/tiled-elevation-service/ + esri.fetchTilemap = function(center) { + // tiles are available globally to zoom level 19, afterward they may or may not be present + var z = 20; + + // first generate a random url using the template + var dummyUrl = esri.url([1,2,3]); + + // calculate url z/y/x from the lat/long of the center of the map + var x = (Math.floor((center[0] + 180) / 360 * Math.pow(2, z))); + var y = (Math.floor((1 - Math.log(Math.tan(center[1] * Math.PI / 180) + 1 / Math.cos(center[1] * Math.PI / 180)) / Math.PI) / 2 * Math.pow(2, z))); + + // fetch an 8x8 grid because responses to leverage cache + var tilemapUrl = dummyUrl.replace(/tile\/[0-9]+\/[0-9]+\/[0-9]+/, 'tilemap') + '/' + z + '/' + y + ' /' + '/8/8'; + + // make the request and introspect the response from the tilemap server + d3_json(tilemapUrl, function (err, tilemap) { + if (err || !tilemap) return; + + var tiles = true; + for (var i=0; i= 20 && esri.id === 'EsriWorldImageryClarity'): metadataLayer = 4; @@ -407,37 +440,6 @@ rendererBackgroundSource.Esri = function(data) { }); } - // use a tilemap service to set maximum zoom for esri tiles dynamically - function fetchTilemap(center, esri) { - // tiles are available globally to zoom level 19, afterward they are only a possibility - const urlZ = 20; - - // calculate url z/y/x from the lat/long of the center of the map - const urlX = (Math.floor((center[0] + 180) / 360 * Math.pow(2, urlZ))); - const urlY = (Math.floor((1 - Math.log(Math.tan(center[1] * Math.PI / 180) + 1 / Math.cos(center[1] * Math.PI / 180)) / Math.PI) / 2 * Math.pow(2, urlZ))); - - // we fetch an 8x8 grid because they cover a normal extent and responses are cached - const tilemapUrl = tileCoord[3].replace(/tile\/[0-9]+\/[0-9]+\/[0-9]+/, 'tilemap') + `/${urlZ}/${urlY}/${urlX}/8/8`; - - // make the request and introspect the response from the tilemap server - d3_json(tilemapUrl, function (err, tilemap) { - if (err || !tilemap) return; - - let tiles = true; - for (i=0;i= context.minEditableZoom(); div.style('display', canEdit ? 'none' : 'block'); + // if an Esri basemap is being displayed and native zoom past 19 is enabled, check the tilemap + if (canEdit) { + var basemap = context.background().baseLayerSource(); + if (/^EsriWorldImagery/.test(basemap.id) && basemap.scaleExtent[1] > 19) { + var center = context.map().center(); + basemap.fetchTilemap(center); + } + } } context.map()