OpenLayers 3 - How can I abort pending ajax requests - ol.source.GeoJSON -


i'm adding layer source requested ol.source.geojson on moveend. how can abort pending ajax requests if map panned again before request finishes?

map.on('moveend', function(){     map.removelayer(highlightedlayer);     var thesource = new ol.source.geojson({             url: 'wfs.php?bbox='+bbox             });     var highlightedsource = new ol.source.geojson({});     thesource.on('change', function(e){             if(thesource.getstate() == 'ready'){                     var features = thesource.getfeatures();                     $.each(features, function(k,v){                             if(v.n.filter == 'include'){                                     highlightedsource.addfeature(features[k]);                                     }                             });                     highlightedlayer.setsource(highlightedsource);                     map.addlayer(highlightedlayer);                     }             });     }); 

instead of adding layer directly @ moveend fetch geojson ajax (which can cancelled) , when complated add geojson data using object paramter instead of url.

heres docs geojson source: http://openlayers.org/en/v3.4.0/apidoc/ol.source.geojson.html?unstable=true

heres how cancel ajax request: abort ajax requests using jquery

hope helps you.


Popular posts from this blog