我对要素图层进行了查询并得到了结果。唯一的问题是生成的对象不包含 LAT 和 LNG 属性。问题来了:
centerAndZoomOnAsset(assetId: string) {
let query = this.pipeFL.createQuery();
query.where = `AssetId = '${assetId}'`;
query.outFields = ['*'];
this.pipeFL.queryFeatures(query).then((result: esri.FeatureSet) => {
debugger;
const foundFeatureGraphic: esri.Graphic = result.features[0];
if (foundFeatureGraphic) {
const center = foundFeatureGraphic.geometry.extent.center.clone();
此时我有一个中心值,并且它有它的x,y坐标,但是,我没有:center.latitude或center.longitude... 我不明白为什么它不会有它。当我对点击进行命中测试时,它包含纬度和经度,但是当我从命中测试之外查询时,它不包含我的纬度和经度。 关于为什么会发生这种情况有什么想法吗?
您需要将
returnGeometry
参数设置为 true 才能从查询中获取空间数据。 请参阅此处的 API
尝试使用这个:
centerAndZoomOnAsset(assetId: string) {
let query = this.pipeFL.createQuery();
query.where = `AssetId = '${assetId}'`;
query.returnGeometry = true;
query.outFields = ['*'];
this.pipeFL.queryFeatures(query).then((result: esri.FeatureSet) => {
debugger;
const foundFeatureGraphic: esri.Graphic = result.features[0];
if (foundFeatureGraphic) {
const center = foundFeatureGraphic.geometry.extent.center.clone();
尝试在查询中为 queryFeature 调用定义 outSpatialReference 参数
query.outSpatialReference = mapView.spatialReference;