1

I am working on circleMarker on leaflet. A method which has latLng will be refreshed for each 5 seconds and new latLng will be returned. So when a method is loaded I need to remove previous layer and should show new points(layer) on a map.

Here is sample code: http://jsfiddle.net/GZHJX/121/

I used .removeLayer(), but it's not working. How can I do it?

nikoshr
  • 32,926
  • 33
  • 91
  • 105
laz
  • 281
  • 8
  • 18

1 Answers1

1

You're using a very old version of Leaflet (0.4). Switch to a recent version and use layer.remove

An updated example immediately removing the marker :

var map = L.map('map').setView([51.505, -0.09], 13);

var createCircleMarker = function (latlng) {
    return L.marker(latlng, {
        icon: L.divIcon({
            className: 'circle',
            iconSize: [8, 8]
        }),
        title: 'test'
    })
}

var l = createCircleMarker([51.505, -0.09]).addTo(map);
l.remove();
nikoshr
  • 32,926
  • 33
  • 91
  • 105
  • I want to remove all previous marker.then new marker should be appended is there any way for that?please give me some ideas. – laz Mar 29 '18 at 04:10
  • @laz see https://stackoverflow.com/questions/49498385/deleting-leaflet-realtime-markers/49513026#49513026 – ghybs Apr 03 '18 at 01:55