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?
Solved! Go to Solution.
@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
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);
});
@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