Reputation: 1834
I want to redraw an OpenLayers vector.
my html button:
<button id="refresh" type="button">Refresh</button>
and my jquery functions to redraw the layer, the parksLayer in the refresh function is logging as false:
function refresh() {
parksLayer.redraw(true);
}
function bind(){
$("#refresh").bind("click", refresh);
}
and my map, I want to redraw the ParksLayer:
map = new OpenLayers.Map({
div: "map",
layers: [
new OpenLayers.Layer.OSM(),
parksLayer
]
});
UPDATE
Thanks for the help, my vector layer is defined like this:
function changeme(avalue){
parksLayer = new OpenLayers.Layer.Vector("Parks", {
projection: new OpenLayers.Projection("EPSG:4326"),
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.Script({
url: "http://my.cartodb.com/api/v2/sql",
params: {
q: "SELECT * FROM activities where type_code is not null"+" "+avalue,
format: "geojson"
},
format: new OpenLayers.Format.GeoJSON({
ignoreExtraDims: true
}),
callbackKey: "callback"
}),
});
}
I have a form that changes avalue
dynamically which changes the GeoJSON query, so if I could redraw the parksLayer I would be left with a new selection from the layer.
Upvotes: 1
Views: 7813
Reputation: 1638
Here's one for a KML Format, but it's very easily adapted as you can see
var refresh = new OpenLayers.Strategy.Refresh({force: true, active: true});
var protocol = new OpenLayers.Protocol.HTTP({
url: "http://my_data.source.com",
format: new OpenLayers.Format.KML({
extractStyles: false,
extractAttributes: true
})
});
mylayer = new OpenLayers.Layer.Vector("MyLayerName", {
strategies: [new OpenLayers.Strategy.Fixed(), refresh],
protocol: protocol
});
Then to redraw/redownload data you do :
refresh.refresh();
Upvotes: 1
Reputation: 5299
I have problems with redraw() too and use this.
VecLayer.redraw(true);
VecLayer.refresh({force: true});
Upvotes: 3
Reputation: 3252
If I read the Openlayers API, redraw function does not use any parameters... You should try to call redraw() without putting "true" as a parameter...
Openlayers API: redraw: function() Redraws the layer. Returns true if the layer was redrawn, false if not.
Regards
Etienne
Upvotes: 3