Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert-pr-1011 #1223

Merged
merged 1 commit into from
Jul 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 1 addition & 57 deletions src/Layers/BasemapLayer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { TileLayer, Util } from 'leaflet';
import { pointerEvents } from '../Support';
import { request } from '../Request';
import {
setEsriAttribution,
_getAttributionData,
Expand Down Expand Up @@ -104,9 +103,7 @@ export var BasemapLayer = TileLayer.extend({
urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
options: {
minZoom: 1,
maxZoom: 22,
maxNativeZoom: 22,
downsampled: false,
maxZoom: 19,
subdomains: ['server', 'services'],
attribution: 'DigitalGlobe, GeoEye, i-cubed, USDA, USGS, AEX, Getmapping, Aerogrid, IGN, IGP, swisstopo, and the GIS User Community',
attributionUrl: 'https://static.arcgis.com/attribution/World_Imagery'
Expand Down Expand Up @@ -250,21 +247,12 @@ export var BasemapLayer = TileLayer.extend({

map.on('moveend', _updateMapAttribution);

// Esri World Imagery is cached all the way to zoom 22 in select regions
if (this._url === BasemapLayer.TILES.Imagery.urlTemplate) {
map.on('zoomanim', _fetchTilemap, this);
}

TileLayer.prototype.onAdd.call(this, map);
},

onRemove: function (map) {
map.off('moveend', _updateMapAttribution);

if (this._url === BasemapLayer.TILES.Imagery.urlTemplate) {
map.off('zoomanim', _fetchTilemap, this);
}

TileLayer.prototype.onRemove.call(this, map);
},

Expand All @@ -284,50 +272,6 @@ export var BasemapLayer = TileLayer.extend({
}
});

function _fetchTilemap (evt) {
var map = evt.target;
if (!map) { return; }

var oldZoom = map.getZoom();
var newZoom = evt.zoom;
var newCenter = map.wrapLatLng(evt.center);

if (newZoom > oldZoom && newZoom > 13 && !this.options.downsampled) {
// convert wrapped lat/long into tile coordinates and use them to generate the tilemap url
var tilePoint = map.project(newCenter, newZoom).divideBy(256).floor();

// use new coords to determine the tilemap url
var tileUrl = Util.template(this._url, Util.extend({
s: this._getSubdomain(tilePoint),
x: tilePoint.x,
y: tilePoint.y,
z: newZoom
}, this.options));

// 8x8 grids are cached
var tilemapUrl = tileUrl.replace(/tile/, 'tilemap') + '/8/8';

// an array of booleans in the response indicate missing tiles
request(tilemapUrl, {}, function (err, response) {
if (!err) {
for (var i = 0; i < response.data.length; i++) {
if (!response.data[i]) {
// if necessary, resample a lower zoom
this.options.maxNativeZoom = newZoom - 1;
this.options.downsampled = true;
break;
}
// if no tiles are missing, reset the original maxZoom
this.options.maxNativeZoom = 22;
}
}
}, this);
} else if (newZoom < 13) {
// if the user moves to a new region, time for a fresh test
this.options.downsampled = false;
}
}

export function basemapLayer (key, options) {
return new BasemapLayer(key, options);
}
Expand Down