-1

How do we get the details of the layer when clicking on the ArcGIS map in angular 10. The click event is triggering on the map. Eg: A map showing house numbers. How do we get the house number when clicking on one of the house numbers on the map. I have to use the 'house number' in my code for other functionality.

this._view.on('click', function (event) {
    console.log('click working');
    //Need to get the value of clicked layer.
  });

/Updated code/

this._view.on('click', function (event) {
        this._view.hitTest(event).then(function (response) {
          const graphic = response.results.filter(function (result) {
            // return result.graphic.layer === hurricanesLayer;
            return result.graphic.layer;
          })[0].graphic;
          console.log(graphic.attributes);
        });
      });

I am getting the error, 'Uncaught TypeError: Cannot read property '_view' of undefined'

Adam-KER
  • 67
  • 9
  • Per https://stackoverflow.com/help/how-to-ask please add enough code to allow others to reproduce the problem and consider creating a live example of the problem that you can link to. – Nathan Beck Oct 05 '20 at 14:30

1 Answers1

0

That would depend on what you want to achieve. For example, if you want to retrieve the top most feature of each "queryable" layer you could use hitTest method from the MapView. This method takes as a parameter a screen coordinate. In your case would be the result of a click event on the view.

Here the docs, ArcGIS API - MapView hitTest

Here an example, ArcGIS Examples - Access features with pointer events

cabesuon
  • 4,860
  • 2
  • 15
  • 24
  • Just see the code you add .. I think I nail it with the case ;) – cabesuon Oct 05 '20 at 14:41
  • Thank you so much for the clue. :) I have updated the code. Suppose I have a single layer doI need to check 'return result.graphic.layer === hurricanesLayer;' ? If 'hurricanesLayer' is the layer name. – Adam-KER Oct 05 '20 at 15:00
  • It is the layer object ... If your layer is `hurricanesLayer` (ex., `let hurricanesLayer = new FeatureLayer(...);`), then it will work. Not the name, the layer. – cabesuon Oct 05 '20 at 15:19
  • Okay Got it. I am getting an error 'Uncaught TypeError: Cannot read property '_view' of undefined' when I apply hitTest() with this._view. (I have assigned this._view = new EsriMapView(mapViewProperties); ) – Adam-KER Oct 05 '20 at 15:31
  • It is probably the context, do this little trick, add `let self = this;` before `this._view.on(..) ` and inside use `self` instead of `this`. – cabesuon Oct 05 '20 at 15:34
  • Cabesuon, The code is working fine without any error. But I am getting the value of 'OBJECTID' . Eg: OBJECTID: 24533. When I checked the layer in esri rest service mapserver, I found the OBJECTID ( type: esriFieldTypeOID, alias: OBJECTID ). This is not the expected result. I have created a feature layer object for the same layer which shows the details on the map (House number). But that info is not getting here. How it is possible to get the same number which shows on the map.? – Adam-KER Oct 05 '20 at 16:25
  • Sorry the delay .. So the features hit it only has one attribute? the OBJECTID? – cabesuon Oct 06 '20 at 14:27
  • No. It has multiple attributes. But the strange thing is for some layer it returns two attributes. Eg: 'HOUSE' is an attribute that returns along with the OBJECTID. How can we decide the exact attribute that it should return? – Adam-KER Oct 07 '20 at 03:19
  • Click is not working for some layers (Wich is appeared like a label). But working for some layers. Do we need to change anything settings in the layer itself? – Adam-KER Oct 07 '20 at 06:56
  • One layer is not clickable, I found in the layer, its 'Display Field: TextString'. Does that make it non-clickable? How can we access this string on the map with hitTest() ? – Adam-KER Oct 07 '20 at 11:42
  • Sorry again for the delay .. super busy week .. OK, many things, the fields of the selected features should be the ones specified in the layer .. Remember that it returns the top most feature of each "query able layer", so if you need all the features or is not supported layer type you will need another approach .. I am not sure if it answer your questions .. BTW I see that you made another question I will take a look it tonight – cabesuon Oct 09 '20 at 16:37
  • Np Cabsuon. I have created a separate layer object for the layer which provides the required information. – Adam-KER Oct 11 '20 at 14:39
  • Hi Cabesuon, Can you please check this thread? https://stackoverflow.com/questions/64306799/arcgis-4-16-popup-template-custom-function-for-content-in-angular – Adam-KER Oct 12 '20 at 06:10
  • Hi @Adam-KER, I have answered the question take a look and let me know, hope it helps .. Regards – cabesuon Oct 12 '20 at 07:14