question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

removeLayer method throws an error

See original GitHub issue

Here it the code-fragment for ‘removeLayer’:

 removeLayer: function (layer) {
    var id = L.Util.stamp(layer);
    var _layer = this._getLayer(id);
    if (_layer) {
      delete this.layers[this.layers.indexOf(_layer)]; // `this.layers` should be replaced with `this._layers`
    }
    this._update();
    return this;
  }

Instead of this.layers should be this._layers i guess.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
ForgottenLordscommented, May 13, 2017

Calling delete on the array index is not sufficient, as it is later iterated over; delete removes the index from the array, causing the deleted index’s value to be ‘undefined’ when expecting an object. Instead, you must splice the item from the array to leave the indexes continuous.

The current pull request #50 is insufficient. I had included a fix in my pull request #46 (an unrelated feature request).

1reaction
karlitoscommented, Oct 25, 2017

Please, accept the PR to fix the issue caused by using delete on array.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React-leaflet LayersControl throws error when moving code ...
removeLayer is not a function ". What I do not understand is: if I comment out the "TestOverlay" component, it compiles. There seems...
Read more >
removeLayer() error - Esri Community
Hello- I'm simply trying to remove a layer from an aprx using arcpy and am getting an error related to the save() function....
Read more >
Error attempting to remove layer using arcpy in ArcGIS Pro?
The removeLayer method is expecting a Layer object not the raster name as a string. Try using the listLayers method on the map...
Read more >
mapbox-gl-utils - npm
Adds U property to map, containing these methods. ... 'toplayer'); // removeLayer() doesn't throw errors if the layers don't exist map.
Read more >
API · cornerstone
getImage function a function that returns a JavaScript Image object with the image ... Check if the supplied parameter is undefined and throws...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found