Reputation: 1655
Is it possible to store a feature layer with just the basic information included with ArcGIS and be able to reference local data when a hosted feature is clicked?
For example, if I was looking at a map of hosted data, and it’s just had the coordinates and in the properties a master reference key (like parcel_id), could I then click the parcel like in the normal behavior of the basic JavaScript map, use the parcel_id for an Ajax request and then pull additional data from the local database and display it in the same pop-up? Could I edit data this way too? Or is this all only available for data/features only hosted with ArcGIS?
That being said, for what I am asking, would it be better to go the route of something like OpenLayers and using a Geojson file?
Upvotes: 0
Views: 266
Reputation: 1324
If you load a FeatureLayer onto the map, you can create a map click handler basically to listen for clicks on your map, do a hit test, and do some logic with whatever it clicked. Doesn't have to be a FeatureLayer, could be a GeoJSONLayer if you want. I believe it should be the same workflow for any type of layer.
Actually clicking on the map and getting the data from the feature would be setting up a click handler on the view (MapView or SceneView whichever you're working with) and then using a hit test based on the coordinates clicked.
Something to the effect of...
view.on("click", function(event) {
view.hitTest({x: event.x, y: event.y}).then(function(response) {
//response.results would hold the features you clicked
if (response.results.length) {
const graphic = response.results[0].graphic;
// do something with the graphic
const attributes = resposne.results[0].graphic.attributes;
// do something with the attributes
}
});
});
You can see a similar example here for mouse hover events I adapted that from: https://developers.arcgis.com/javascript/latest/sample-code/view-hittest/ with more information about performing hit tests on maps and getting results back here in the documentation: https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#hitTest
Upvotes: 1