Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
213 views
in Technique[技术] by (71.8m points)

ajax - Storing features layer with ArcGIS or as Geojson locally to access database data

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?

question from:https://stackoverflow.com/questions/65875505/storing-features-layer-with-arcgis-or-as-geojson-locally-to-access-database-data

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...