robertleeplummerjr/Leaflet.glify

How to clear layers?

xlcrr opened this issue · 6 comments

xlcrr commented

When the user pans around the map, I would like to clear all point data and re-load it

Previously this was markers.clearLayers()

How can this be achieved with this awesome plugin?

Thanks <3

Hi, this works for me:

glify.remove();

glify being the variable set up as L.glify.points( {...

See docs about remove(): https://github.com/robertleeplummerjr/Leaflet.glify

xlcrr commented

I am getting this error

leaflet_glify__WEBPACK_IMPORTED_MODULE_8___default.a.points.remove is not a function

using

glify.remove()
glify.points.remove()

compiled with Laravel-mix, webpack plugin for laravel + vue

Not sure what this might be. I downloaded and built the lib manually (npm version (3.1.0) is not the latest 3.2.0) and imported it manually. Maybe try that?

When you call:

  • glify.points()
  • glify.lines()
  • glify.shapes()

You are creating variables, instances that you'll want to interact with. To this end, try this:

  • const myPoints = glify.points({ map, data });
    myPoints.remove();
  • const myLines = glify.lines({ map, data });
    myLines.remove();
  • const myShapes = glify.shapes({ map, data });
    myShapes.remove();

Conversely, you can add the layer back to a map:

  • const myPoints = glify.points();
    myPoints.addTo(map);
  • const myLines = glify.lines();
    myLines.addTo(map);
  • const myShapes = glify.shapes();
    myShapes.addTo(map);

Here is an example tailored to this specific issue.

xlcrr commented

I got this working at last by moving points.remove() before the request. I was trying to handle it in the response