How can I remove a single overlay in Openlayers 3.3.0? -


i creating overlays in mapping application need refresh every 5 seconds. having difficulties removing stale overlay map using code below. map.removeoverlay method not seem working correctly. stacking of overlays visibly apparent after few iterations.

using map.getoverlays().clear() removes stale overlay, however, removes overlays not desired. assistance appreciated.

window.setinterval(function() {  $.ajaxsetup({ mimetype: "text/plain" });   $.getjson('json/data.json', function(data) {       $.each(data.item, function(key, val) {          var storename = this.name;          var storelocation = this.location;          var storelatitude = this.latitude;          var storelongitude = this.longitude;            $.each(val.tasks, function(i, j){              var taskname = this.name;              var taskstate = this.state;                if (taskstate == "open") {                 var taskgeometry = ol.proj.transform([storelongitude,storelatitude], 'epsg:4326', 'epsg:3857');                 function createcircleoutoverlay(position) {                 var elem = document.createelement('div');                 elem.setattribute('class', 'circleout');                  return new ol.overlay({                     element: elem,                     position: position,                     positioning: 'center-center'                 });             }                 var taskoverlay = createcircleoutoverlay(taskgeometry);                 map.removeoverlay(taskoverlay);                 map.addoverlay(taskoverlay);                 }            });       });      });  }, 5000); 

            var taskoverlay = createcircleoutoverlay(taskgeometry);             map.removeoverlay(taskoverlay); 

the problem trying remove new overlay , not old one. have store reference overlay openlayers can remove map. like:

var currentoverlay = null; window.setinterval(function() {  $.ajaxsetup({ mimetype: "text/plain" });                 // ...                 if (currentoverlay === null) {                   map.removeoverlay(currentoverlay);                 }                 currentoverlay = createcircleoutoverlay(taskgeometry);                 map.addoverlay(currentoverlay);                // ... 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -