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

Feature layers get displaced after switching from ESRI basemap #818

Closed
CraigVA opened this issue Aug 2, 2016 · 2 comments · Fixed by #820
Closed

Feature layers get displaced after switching from ESRI basemap #818

CraigVA opened this issue Aug 2, 2016 · 2 comments · Fixed by #820

Comments

@CraigVA
Copy link

CraigVA commented Aug 2, 2016

I have code like this that lets you switch between ESRI basemaps and also shows some features:

var m = L.map('map').setView([45.5275, -122.6717], 14);
var esriImagery = L.esri.basemapLayer("Imagery");
var esriTopo = L.esri.basemapLayer("Topographic");
var lc = L.control.layers({
    "ESRI Imagery": esriImagery,
    "ESRI Topographic": esriTopo,
}).addTo(m);
esriImagery.addTo(m);
var bikePaths = L.esri.featureLayer({url: 'https://services.arcgis.com/uCXeTVveQzP4IIcx/ArcGIS/rest/services/Bike_Routes/FeatureServer/0'}).addTo(m);

While it's still on the Imagery basemap, everything works fine. But switch to the Topographic basemap and zoom in and out repeatedly, and the feature layers will end up completely out of place.

As far as I can tell the issue is caused by line 216 of Basemap.js, in the onRemove function:
map.off('moveend', this._updateMapAttribution, this);

When I remove that line from my local copy, the issue is resolved. But I don't understand why it would affect feature layers.

Another workaround is to use TileLayers based on the basemaps but with static attributions:

var esriImagery2 = new L.TileLayer(esriImagery._url, {minZoom: esriImagery.options.minZoom, maxZoom: esriImagery.options.maxZoom, attribution: '<a href="https://www.esri.com">© Esri</a>, '+esriImagery.options.attribution, subdomains: esriImagery.options.subdomains});
var esriTopo2 = new L.TileLayer(esriTopo._url, {minZoom: esriTopo.options.minZoom, maxZoom: esriTopo.options.maxZoom, attribution: '<a href="https://www.esri.com">© Esri</a>, '+esriTopo.options.attribution, subdomains: esriTopo.options.subdomains});
@jgravois
Copy link
Contributor

jgravois commented Aug 2, 2016

apparently i introduced _two_ bugs when i refactored dynamic attribution logic into the generic L.esri.Util utility class. thank you for helping me identify both and my sincere apologies for the inconvenience.

the problem is that we are currently not unwiring the same event listener for interrogating and displaying attribution when a basemapLayer is removed that we appended when the layer was first added.

onAdd: function (map) {
  map.on('moveend', Util._updateMapAttribution);

onRemove: function (map) {
  // this refers to the layer itself, not the function housed within L.esri.Util
  map.off('moveend', this._updateMapAttribution, this);

if anyone is curious why i wanted to move that code out of basemapLayer to begin with, its because i'm in the middle of writing another plugin to load esri vector tiles in leaflet and i thought it made sense to reuse the same code to handle attribution updates as people pan and zoom around the map.

@jgravois
Copy link
Contributor

jgravois commented Aug 3, 2016

fix has been packaged in 2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants