[OpenLayers-Users] layer by name or by id events

Christopher Schmidt crschmidt at metacarta.com
Mon Apr 6 10:07:39 EDT 2009


On Mon, Apr 06, 2009 at 04:06:55PM +0200, Luis Ortiz (lortiz) wrote:
> Hi,
> 
> I would like to register some especial events that happend in a layer.
> 
> So i would like capture events in such layer.
> 
> My example is this:
> 
> var aktLayer = 1; //index of a vectorlayer
> 
> map.layers[aktLayer].events.register('featureselected',
> map.layers[aktLayer], regFeatureSelected);
> map.layers[aktLayer].events.register('featureunselected',
> map.layers[aktLayer], regFeatureUnselected);
> 
> 
> 
> 
> Issue comes when i add a new layer with this method:
> 
> gml_new = new OpenLayers.Layer.GML("ZONE", link, {format:
> OpenLayers.Format.GeoJSON, projection: map.displayProjection, styleMap :
> aStyleMap });
> map.addLayer(gml_new);
> 
> 
> I added some control.selectfeatures
> 
>           
>         ctrlSelectFeatures = new OpenLayers.Control.SelectFeature(
>         gml_new,
>             {
>             clickout: true, toggle: true,
>             multiple: false, hover: false,
>             toggleKey: "ctrlKey", // ctrl key removes from selection
>             multipleKey: "shiftKey", // shift key adds to selection
>             box: false
>             }
>         )
>         map.addControl(ctrlSelectFeatures);
>         ctrlSelectFeatures.activate();
>        
> 
> 
> how i can register events to this new layer? I don't know how obtain the
> number/id of the layer just added with method map.addLayer(gml_new);

gml_new.events.register("featureselected", etc.)

just use the variable you created...

-- Chris

> 
> 
> Thank you
> 
> 
> 
>    
> 
> -- 
> 
> *Luis Ortiz*
> Technical Department
> 
> tel.: 902 512 260
> int. tel.: +34 933 968 068
> fax: +34 937 959 605
> mobile: +34 687 703 541
> skype: luis.compegps
> email: lortiz at compegps.com <mailto:lortiz at compegps.com>
> 
> www.compegps.com <http://www.compegps.com>
> www.twonav.com <http://www.twonav.com>
> 	
> CompeGPS Team SL
> Carrer d'en Draper, 13
> 08350 Arenys de Mar
> Barcelona - Spain
> 
> UTM 31T X 461512 Y 4603162
> (WGS 84)
> 

> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users


-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list