Reputation: 317
I have been googling around awhile just to try get my map to redraw once I have set a new label on my vector. If I zoom in and out the label does work correctly, but I'd like it to refresh on a click function.
$(".openlayerLabel").change(function(){
var theValue = $(this).val();
if($(this).is(':checked')) {
console.log('Checkbox checked');
plugins.search.setStyles(true);
plugins.search.selectLayer.refresh({force:true});
}
else {
console.log('Checkbox unchecked');
}
});
What does NOT work is .refresh (rest is working just fine). I saw someone write that I should use force:true so I did try this but nothing happened really. I have also tried .redraw but this gives similar result.
Any headsup?
Upvotes: 1
Views: 998
Reputation: 13883
I worked on an OpenLayers project a while ago so I'm a bit rusty, but if I recall correctly you may need to loop through all of the features in the layer and explicitly call layer.drawFeature(feature)
on all of them. Something like this:
var features = plugins.search.selectLayer.features;
for(var i = 0; i < features.length; i++) {
plugins.search.selectLayer.drawFeature(features[i]);
}
Documentation here: http://dev.openlayers.org/apidocs/files/OpenLayers/Layer/Vector-js.html#OpenLayers.Layer.Vector.drawFeature
There's also a "redraw" method on the base layer class, so you can try:
plugins.search.selectLayer.redraw();
Documentation here: http://dev.openlayers.org/apidocs/files/OpenLayers/Layer-js.html#OpenLayers.Layer.redraw
Hopefully one of these two methods works!
Upvotes: 2