简体   繁体   中英

How to return latitude and longitude of a point in a feature layer for Esri Javascript API 4.18

I've created a client-side feature (point) and would like to know how to return it's lat and long. I've tried using the queryFeatures method, but have not been able to return anything.

featureLayer
.queryFeatures({
  returnGeometry: true,
})
.then(function (results) {
  // do something with the resulting graphics
  console.log(results.features.geometry.latitude);
});

EDIT: I'm only adding one point that I need to query. It has an initial location, but is moved when the user clicks a new location on the map.

var features = [
  {
    geometry: {
      type: "point",
      x: -94.68,
      y: 46.72,
    },
    attributes: {
      ObjectID: 1,
    },
  },
];

var featureLayer = new FeatureLayer({
  source: features, // autocast as a Collection of new Graphic()
  objectIdField: "ObjectID",
});

map.add(featureLayer);

If you want to query a feature layer that has the features on client side, you need to use the FeatureLayerView methods ( ArcGIS API - FeatureLayerView queryFeatures ). This methods act on every graphic available to dray on the view, these is what you are looking for.

The query methods of FeatureLayer act on the service, that is not your case.

BTW, if you only need to update the geometry just use applyEdits method of the feature layer ( ArcGIS API - FeatureLayer applyEdits ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM