How capture event click on the LayerList,so zoom layer visible clicked?

587
1
06-12-2020 10:36 AM
Juan_CarlosColchado_Casas
New Contributor II

layerList.on("click",function(event) {
var aa="asdas";
});

view.when(function() {
// Event listener that fires each time an action is triggered
//layerList.on("click", function(event) {
// contentLegend=layer;
//});
// Create the LayerList widget with the associated actions
// and add it to the top-right corner of the view.
// This function will execute once the promise is resolved

contentGroupLayerFeature.when(function() {
contentGroupLayerFeature.on("trigger-action", function(event) {
var aa="asdas";
});
});

contentGroupLayerFeature.on("click", function(event) {
var aa="asdas";
});


console.log("webmap loaded successfully");

}, function(error){
// Use the errback function to handle when the view doesn't load properly
console.log("The view's resources failed to load: ", error);
});

0 Kudos
1 Reply
GeorgeAbraham
New Contributor III

Hi Juan Carlos Colchado Casas

If you are looking for identifying the feature where you clicked and then say zoom

to that, what you need to is to use view.hitTest() and check if the feature returned is same as what you are looking for and if yes, then zoomto thay feature.

Something like say

var yourLayer = <layer>;

view.hitTest(event).then(function (response) {
var graphic;
if (response.results.length) {
graphic = response.results.filter(function (result) {
return result.graphic.layer === yourLayer;
})[0].graphic;
}

//you can then do a view.zoomTo graphic

});