Select to view content in your preferred language

In ESRI Leaflet, is it possible to grab a value from layer on a click event?

1265
2
Jump to solution
10-11-2021 04:15 PM
Labels (1)
GeoDev
by
New Contributor II

I did it in ESRI JS API like  this: 

view.on("immediate-click", (event) => {
const latitude = event.mapPoint.latitude;
const longitude = event.mapPoint.longitude;
const screenPoint = view.toScreen(new Point({latitude, longitude}));
view.hitTest(screenPoint).then((hitTestResult) => {
console.log(hitTestResult);
soilOrder = hitTestResult.results[0].graphic.attributes.esrisymbology;
console.log(soilOrder);

 

But I want to do it in Leaflet since it'll be more suited for my needs. Any idea how I can do this in leaflet? 





0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

@DanielDormont is right, @GeoDev, you can attach a click listener to your Leaflet layer instance. Let's say you are using an esri-leaflet L.esri.FeatureLayer, then you could attach a click listener like so and inspect the event object to get client-side feature attributes.

myFeatureLayer.on('click', function(e) {
console.log(e.layer.feature.properties);
});

 

Reference: https://esri.github.io/esri-leaflet/api-reference/layers/feature-layer.html#events 

View solution in original post

0 Kudos
2 Replies
DanielDormont
Occasional Contributor

I don't know Esri JS very well, but in Leaflet you can bind click events either to the entire map or to a particular marker:

marker.on('click', function (e) {
   alert(e.latlng);
});
0 Kudos
by Anonymous User
Not applicable

@DanielDormont is right, @GeoDev, you can attach a click listener to your Leaflet layer instance. Let's say you are using an esri-leaflet L.esri.FeatureLayer, then you could attach a click listener like so and inspect the event object to get client-side feature attributes.

myFeatureLayer.on('click', function(e) {
console.log(e.layer.feature.properties);
});

 

Reference: https://esri.github.io/esri-leaflet/api-reference/layers/feature-layer.html#events 

0 Kudos