3

I've got a SceneView with a FeatureLayer, and I'm trying to catch every click on a PictureMarkerSymbol to display additional data under the map.

The map works well, so do symbols and popups, but I never catch any event, am I missing something?

require([
    "esri/Map",
    "esri/views/SceneView",
    "esri/layers/FeatureLayer",
    "esri/renderers/UniqueValueRenderer",
    "esri/symbols/PictureMarkerSymbol",
    "dojo/on"
], function(
    Map, SceneView, FeatureLayer, UniqueValueRenderer, PictureMarkerSymbol, on
) {

    var map = new Map({ ... });   
    var view = new SceneView({ ... });

    view.then(function() {

        var renderer = new UniqueValueRenderer({ ... });
        var pins = [...];
        pins.forEach(function (element) {
          renderer.addUniqueValueInfo(element,
            new PictureMarkerSymbol({ ... })
          );
        });

        layerMarkers = new FeatureLayer({
            title: "Labels Layer",
            url: "...",
            definitionExpression: "...",
            renderer: renderer,
            outFields: ["*"],
            popupTemplate: { ... }
        });

        layerMarkers.on("click", function (evt) {  
            console.log(evt.graphic.attributes);  // No output??
        }); 

        map.add(layerMarkers);

    });
});

1 Answer 1

3

I finally figured out how to catch these events.
I'm not allowed to listen for click events on a FeatureLayer, nor on a Map, but I still can listen it on my SceneView, and use the hitTest() function to get the related symbol:

// Listen for SceneView click events
view.on("click", function (evt) {  
  // Search for symbols on click's position
  view.hitTest(evt.screenPoint)
    .then(function(response){
      // Retrieve the first symbol
      var graphic = response.results[0].graphic;
      if (graphic) {
        // We now have access to its attributes
        console.log(graphic.attributes);
      }
    });
}); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.