How to clear leaflet map of all markers and layers before adding new ones?

前端 未结 6 1534
遇见更好的自我
遇见更好的自我 2021-02-05 00:02

I have the fallowing code:

map: function (events) {
    var arrayOfLatLngs = [];
    var _this = this;

    // setup a marker group
    var markers = L.markerClu         


        
6条回答
  •  不思量自难忘°
    2021-02-05 00:33

    I used a combination of the two best answers here from beije and Prayitno Ashuri.

    Saving the markers to "this" so we can reference it later.

    this.marker = L.marker([event.location.lat, event.location.lng]);
    

    and then just removing the markers.

    this.markers.remove()
    

提交回复
热议问题