[OpenLayers-Users] Removing a layer

bartvde at osgis.nl bartvde at osgis.nl
Tue Oct 14 11:01:45 EDT 2008


Probably this is because of the scope of your variable.

If you define var xxxx in a function, it only has a local scope inside of
the function, outside of the function it is not accessible.

Instead, you can define the variable outside of the function with the var
keyword.

var xxxx = null;

function init() {
  xxx = new ......;
}

Best regards,
Bart

> Hi all,
> I am having one trouble and I don't know what else to do.
>
> I have my map and I have develop some javascript code that is working
> fine.
> What happened this weekend is that I developed a function that had that
> some
> layers in the beginning:
>
>
> var myStyle128684655922811250 = new OpenLayers.StyleMap({fillOpacity:
> 0.5});var rules128684655922811250 = {0: {fillColor: '#ffffff',
> fillOpacity:0.5}   };
>
> myStyle128684655922811250.addUniqueValueRules('default', 'type',
> rules128684655922811250);
>
> var layer128684655922811250 = new OpenLayers.Layer.GML('mercury layer',
> '../GML/glmush55qv3web45ak21mhrf128684655922811250.xml',{styleMap:
> myStyle128684655922811250} );
>
> map.addLayer(layer128684655922811250);
>
>
> and this is working fine.  What is really funny is that the following code
> only works if the code above is outside a function. If the code above is
> inside the init() function then this code don't work:
>
> //// REMOVE THE LAYER
> map.removeLayer(layer128684657963905000);
> layer128684657963905000.destroy();
>
>
> Why??? Anybody knows why??????
>
> Thanks
>
> Best,
>
> Carlos
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>





More information about the Users mailing list