Removing/changing ImageOverlay

2,455 views
Skip to first unread message

Christian Asker

unread,
Feb 5, 2013, 6:53:45 AM2/5/13
to leafl...@googlegroups.com
Hello there. I want to use ImageOverlay for an application, but need to be able to change the image that is overlayed. If I add another ImageOverlay, the old one will remain beneath the new one, which is not what I want. In the API documentation, I cannot find anything about removing an ImageOverlay, or changing the image that is overlayed. Any suggestions?

The application I'm working on will have a list of images next to the map, and when the mouse is hovered over one item on the list, the corresponding image will be shown on the map. For me, it seems that an ImageOverlay would be the way to go, but perhaps there is a simpler solution?


christian studer

unread,
Feb 11, 2013, 2:33:58 AM2/11/13
to leafl...@googlegroups.com
Hello Christian,

You can remove an image overlay with map.removeLayer(myImageOverlayLayer) anytime. But you'll need to keep the overlay object (myImageOverlayLayer) around.

I'm using this code to periodically refresh an ImageOverlay:

var radar = new L.ImageOverlay('getLatestRawRadarPicture.php', radarBounds);
map.addLayer(radar);

// Refresh image layer every couple of minutes
setInterval(function() {
map.removeLayer(radar);
radar = new L.ImageOverlay('getLatestRawRadarPicture.php', radarBounds);
map.addLayer(radar);
}, 2 * 60 * 1000);


Bye,
  christian
Reply all
Reply to author
Forward
0 new messages