geoman-io / leaflet-geoman

🍂🗺️ The most powerful leaflet plugin for drawing and editing geometry layers
https://geoman.io
MIT License
2.21k stars 433 forks source link

Util.js:55 Uncaught TypeError: Cannot use 'in' operator to search for '_leaflet_id' in undefined #1321

Closed AlbertoMCS closed 1 year ago

AlbertoMCS commented 1 year ago

Hi, I created a button to create rectangles. When clicking the button I get this error: Util.js:55 Uncaught TypeError: Cannot use 'in' operator to search for '_leaflet_id' in undefined This just happens with Leaflet 1.8.0 and newer versions (with 1.7.0 works). image Here the fiddle: https://jsfiddle.net/7cx2ztuq/1/ Thanks

AlbertoMCS commented 1 year ago

Hi, Already found the error, it is not Geoman related it is Leaflet related. In previous versions you could do the following:

    var lyrBus; // empty layer, a placeholder
    if (map.hasLayer(lyrBus)) {
      map.removeLayer(lyrBus);
  }

From 1.8.0 version onwards you need to provide a proper argument, otherwise you will get the error mentioned:

    var lyrBus = L.marker([51.505, -0.09]); // need to be initiated with a Leaflet layer
    if (map.hasLayer(lyrBus)) {
      map.removeLayer(lyrBus);
  }