[OpenLayers-Users] How to obtain reference to map layer in 2.5????

Peter Len peteralen at earthlink.net
Tue Apr 8 08:54:10 EDT 2008


Paul,

Thanks for the reply.  That worked fine but my frustration with some of this is that the API (http://dev.openlayers.org/releases/OpenLayers-2.5/doc/apidocs/files/OpenLayers/Map-js.html) does not list a "layers" property for the map object.  How is someone suppose to know that it is available to use?

Thanks for your insight - Peter

-----Original Message-----
>From: Paul Spencer <pagameba at gmail.com>
>Sent: Apr 7, 2008 9:39 PM
>To: plen <peteralen at earthlink.net>
>Cc: users at openlayers.org
>Subject: Re: [OpenLayers-Users] How to obtain reference to map layer in 2.5????
>
>I would imagine that you can use something like:
>
>for (var i=0; i<map.layers.length; i++) {
>     var layer = map.layers[i];
>     //do something with the layer?
>}
>
>Cheers
>
>Paul
>
>PS Firebug is a great extension for firefox that allows you to inspect  
>live javascript objects like the map object and find what you need.
>
>On 7-Apr-08, at 9:28 PM, plen wrote:
>>
>> Hello,
>>
>> I am using OpenLayers 2.5.  Our situation is that we are getting a  
>> handle to
>> the map after someone else has loaded some WMS map layers.  So, by  
>> the time
>> I can do anything with the OpenLayers map, another group has added  
>> 10 or 11
>> map layers through calls like:
>>
>> var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
>>                "http://labs.metacarta.com/wms/vmap0?", {layers:  
>> 'basic'},
>>                options);
>>
>> I want to get a handle to a particular layer and I think I have to  
>> use the
>> OpenLayers API to get the layer.  For example, the 2.5 API has a
>> map.getLayer([layer_id]); and then a  
>> map.setBaseLayer(OpenLayers.Layer);
>>
>> My question is that you have to have the layer ID as the argument  
>> for the
>> getLayer() function.  Since I did not load any of those layers, I  
>> don't know
>> how I would get the ID for the layer I am interested in.  There is no
>> generic function which returns an array of all the layers to which I  
>> could
>> just cycle through and check each layers name, for example.  Version  
>> 2.6 has
>> more functions to obtain layer data but we must use 2.5 for the time  
>> being.
>>
>> Any thoughts how I can programmatically go through the layers?
>>
>> Thanks - Peter
>>
>> -- 
>> View this message in context: http://www.nabble.com/How-to-obtain-reference-to-map-layer-in-2.5-----tp16545652p16545652.html
>> Sent from the OpenLayers Users mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> Users mailing list
>> Users at openlayers.org
>> http://openlayers.org/mailman/listinfo/users
>




More information about the Users mailing list