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

Existing polygon not remove if load a new one #63

Open
ghost opened this issue Oct 1, 2018 · 1 comment
Open

Existing polygon not remove if load a new one #63

ghost opened this issue Oct 1, 2018 · 1 comment
Labels

Comments

@ghost
Copy link

ghost commented Oct 1, 2018

I have seen a problem that if i load a KML file and display polygon on map using this plugin, and when drag and drop a new KML file or load from button, previous polygon still remain on map.

@leplatrem leplatrem added the bug label Oct 23, 2018
@johnd0e
Copy link

johnd0e commented Mar 26, 2019

It is definitely not bug.
We can load multiple layers, it's a feature.

To keep loaded single layer only we should remove previous, e.g.:

  var lastLayer;
  control.loader.on('data:loaded', function (e) {
    if (lastLayer) { lastLayer.remove(); }
    lastLayer = e.layer;
  });

Alternatively, you may prefer different approach, involving layers control: #61 (comment)

Also both approaches could be combined, e.g.:

  var layerswitcher = L.control.layers().addTo(map);
  var lastLayer;
  control.loader.on('data:loaded', function (e) {
    if (lastLayer) { layerswitcher.removeLayer(lastLayer); }
    layerswitcher.addOverlay(e.layer, e.filename);
    lastLayer = e.layer;
  });

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

No branches or pull requests

2 participants