Select to view content in your preferred language

Sceneview hittest expected behavior

503
0
08-13-2021 11:40 AM
bcasu
by
Emerging Contributor

I have a 3D Sceneview with multiple layers and am using HitTest to call a function when one specific layer is clicked. This works fine but when there are overlapping layers and I click on a different layer, the HitTest fires and runs a call to the REST API. The layer the HitTest is included in does not highlight and the popup does not open but it runs the rest api call among other things. Is this the expected behavior? 

If it is unclear what I am talking about. Let's say I have two 3D layers, one for walls and one for cabinets. I choose to only include 'cabinets' in the HitTest. When I click on a wall and there is a cabinet behind it, the HitTest fires the function on the cabinets layer, even though there is a wall in front of it. I do not want this to happen. 

view.on("click", function(event) { 
          // if any, remove the previous highlights
          if (highlight) {
            highlight.remove();
          }
          // only include graphics from hurricanesLayer in the hitTest
          const opts = {
            include: cabLayer
          }
          view.hitTest(event, opts).then(function(response) {            
            // check if a feature is returned from the cabLayer
            if (response.results.length) {
              const graphic = response.results[0].graphic;
              // Get the Drawer_ID of the clicked drawer
              var drawerId = graphic.attributes.Sheet1__DRAWER_ID;
              var drawerTitle = graphic.attributes.Sheet1__DRAWER_TITLE; 
              var cabId = graphic.attributes.Sheet1__CAB_ID;              
              // Call to the ArcGIS REST API to retreive the maps in each drawer
              $.ajax({
                      dataType: 'json',
                      url: url ,
                      type: "GET",    
                      success: function(data) {
                       if (data.features.length <= 0) {
                         $('#noDataModal').modal('show');
                       } else {
                         // show the cabinet info div
                         $("#drawerTitle").show(); 
                         console.log(data.features);
                         // Get the features from the REST API 
                         var features = data.features;  
                         $('#drawerModal').modal('show');
                         var numResults = data.features.length;
                         cabLayer.popupTemplate = {
                            title: "Drawer: " + drawerId + " (" + drawerTitle + ")",
                            content: "Map count: " + numResults
                         };
                         $('#results').html("Map count: " + numResults + " maps");  
                         // Create a new table with the array of features 
                         table.setData(features);
                         // Show the icon to get the table back
                         $(".esri-icon-table").show();
                       }
                      }
              });   
            }
          });
        });
0 Kudos
0 Replies