[OpenLayers-Users] Layer name

Jair Santos jsantos5954 at gmail.com
Thu Oct 8 08:50:43 PDT 2015


Thank you Toni.

 

I’ll try and will post here if it works.

 

Regards.

 

JJ.

 

From: openlayers-users-bounces at lists.osgeo.org
[mailto:openlayers-users-bounces at lists.osgeo.org] On Behalf Of toni
hernández
Sent: Thursday, October 08, 2015 3:35 AM
To: openlayers-users at lists.osgeo.org
Subject: Re: [OpenLayers-Users] Layer name

 

Jair,

I am not an expert...if this doesn't work, I hope someelse helps you.
I am sure there are other ways to achive this.

once said that,

When creating your layers you need to add an "id" attribute. See the example
bellow.
Then, use get the onclic mouse event, and


earthQuakeLayer = new ol.layer.Vector({
  source: new ol.source.Vector({
    ....
  }),
  id:'yourlayerid' 
});

Then , when listening the clic event, you need to use something similar to
this.

    
map.on('click', function (e) {
  map.forEachFeatureAtPixel(e.pixel, function (feature, layer) {
  console.debug(layer.get('id'));
  });
}    



Toni Hernández Vallès 

Servei de Sistemes d'Informació Geogràfica i Teledetecció
-
Universitat de Girona
SIGTE
-
Pl. Ferrater Mora 1
17071 Girona
Tel +34 972 418 039 (7026 intern)
toni at sigte.udg.edu <mailto:toni at sigte.udg.edu>  

http://www.sigte.udg.edu
Twitter http://twitter.com/SIGTE_UDG

On 05/10/2015 21:30, Jair Santos wrote:

Hello,

 

In a multi-layer map how to determine the clicked layer name when the user
click on the map?

 

Thanks,

 

JJ.






_______________________________________________
Users mailing list
Users at lists.osgeo.org <mailto:Users at lists.osgeo.org> 
http://lists.osgeo.org/mailman/listinfo/openlayers-users

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20151008/091c8592/attachment-0001.html>


More information about the Users mailing list