Updating / refreshing a geojson layer
- by Ozaki
TLDR My geoJSON layer will display the vector mark but will not destroy the features or re add the features in causing a moving / updating look to the OpenLayers map.
Hey S O.
I have a geojson layer set up as follows:
//GeoJSON Layer//
var layer1 = new OpenLayers.Layer.GML("My GeoJSON Layer", "coordinates",
{format: OpenLayers.Format.GeoJSON,
styleMap: style_red});
My features are set up as follows:
var f = new OpenLayers.Feature.Vector(null,style_red);
var style_red = OpenLayers.Util.extend({}, layer_style);
style_red.strokeColor = "red";
style_red.fillColor = "black";
style_red.fillOpacity = 0.5;
style_red.graphicName = "circle";
style_red.pointRadius = 3.8;
style_red.strokeWidth = 2;
style_red.strokeLinecap = "butt";
and my layer updating function:
function UpdateLayer(){
var p = new OpenLayers.Format.GeoJSON({
'internalProjection': new OpenLayers.Projection("EPSG:900913"),
'externalProjection': new OpenLayers.Projection("EPSG:4326")
});
var url = "coordinates.geojson";
OpenLayers.loadURL(url, {}, null, function(r) {
var f = p.read(r.responseText);
map.layers[1].destroyFeatures();
map.layers[1].addFeatures(f);
});
setTimeout("UpdateLayer()",1000)
}
Any idea what I am doing wrong or what I am missing?