Layer name

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Layer name

Jsantos

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
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-users
Reply | Threaded
Open this post in threaded view
|

Re: Layer name

toni hernández-4
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)
[hidden email]

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
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-users


_______________________________________________
Users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-users
Reply | Threaded
Open this post in threaded view
|

Re: Layer name

Jsantos

Thank you Toni.

 

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

 

Regards.

 

JJ.

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of toni hernández
Sent: Thursday, October 08, 2015 3:35 AM
To: [hidden email]
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)
[hidden email]

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
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-users

 


_______________________________________________
Users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-users