[OpenLayers-Users] layer.destroy causes errors
Iain Mott
mott at reverberant.com
Tue Aug 14 03:22:06 PDT 2012
Hello,
I have a page that needs to have a layer of markers updated after a
search is made on a database.
The page is here: http://rabeca.org/?ip=buscar
To test it, please use a search string such as "cordas"
The redraw function causes a javascript error in firefox (viewable with
firebug) of "TypeError: this.format is null". This doesn't cause any
problem in firefox or Chrome - however in IE9 the redrawing of points
fails and I suspect this may be due to the same error.
The error seems to be caused by the following call:
if(layer)
layer.destroy();
as part of the encompassing redraw function:
function drawRabecaLayer_buscar(){
var layers = map.getLayersByName("layer");
for(var layerIndex = 0; layerIndex < layers.length; layerIndex++)
{
map.removeLayer(layers[layerIndex]);
}
layers = map.getLayersByName('pointLayer');
for(var layerIndex = 0; layerIndex < layers.length; layerIndex++)
{
map.removeLayer(layers[layerIndex]);
}
selectControl.destroy();
if(layer) layer.destroy();
if(pointLayer)
{
pointLayer.destroy();
}
layer = new OpenLayers.Layer.Vector("Rabecas", { strategies: [new
OpenLayers.Strategy.BBOX({resFactor: 1.1})], sphericalMercator : true,
protocol: new OpenLayers.Protocol.HTTP({ url:
"featuresbrief_buscar.php?", format: new OpenLayers.Format.Text() })});
pointLayer = new OpenLayers.Layer.Vector("Localização nova",
{ sphericalMercator : true});
map.addLayers([layer, pointLayer]);
selectControl = new OpenLayers.Control.SelectFeature(layer);
map.addControl(selectControl);
selectControl.activate();
layer.events.on({ 'featureselected': onFeatureSelect });
UpdateFeatureLayer();
return true;
}
Can anyone please suggest a fix?
Thank you,
Iain
More information about the Users
mailing list