How can I add a new layer, then remove previous layer from a Leaflet/CartdoDB map wit

المشرف العام

Administrator
طاقم الإدارة
I am new to CartoDB/Leaflet. Here's my fiddle...http://jsfiddle.net/zippyferguson/fLkqgf4q/1/

If you click the play button, I want it to load data to the map year by year from 1966 to 2015 from a CartoDB query. But, with each iteration, the map is cleared of data, and then the next year data appears. I am looking to load the next year data and remove the previous year data underneath in the previous layer, without the clearing of everything on the map. If you comment out this line in the fiddle, you will kind of see what I am looking for.

removeAllLayersExcept(layer);

...this function is an attempt to remove all layers on the map except the one just loaded.

But, with removeAllLayersExcept(layer) commented out, that just keeps putting more layers on the map. I don't understand why it clears the whole map each iteration.

Any ideas or direction would be appreciated!



أكثر...
 
أعلى