arcgis api for js 中的query实现数据查询

发布时间:2023年12月17日

相当于服务地址中的query查询

获取图层范围内的数据4.24

import Query from '@arcgis/core/rest/support/Query';
import * as QueryTask from "@arcgis/core/rest/query";

//获取图层范围内的数据4.24
_returnFeatureFromWhere(url, where, geo) {
     const self = this
     return new Promise((resolve, reject) => {
          const queryObject = new Query();
          queryObject.returnGeometry = true;
          queryObject.outFields = ["*"];
          queryObject.where = where
          queryObject.geometry = geo ? geo : null;
          queryObject.outSpatialReference = self.mapView.spatialReference
          QueryTask.executeQueryJSON(url, queryObject)
              .then(response => {
                  resolve(response)
              })
              .catch((err) => {
                  console.log("_returnFeatureFromWhere异常:", err);
              });
      })
},

获取图层范围内的数据4.18

//以下下代码放到初始化加载
const self = this

require(["esri/tasks/QueryTask","esri/tasks/support/Query"], function(QueryTask,Query) {
self.QueryTask = QueryTask
self.Query = Query

});

//获取图层范围内的数据4.18
_returnFeatureFromWhere(url, where, geo) {
     const self = this
     return new Promise((resolve, reject) => {
          const query = new self.Query();
          query.returnGeometry = true;
          query.outFields = ["*"];
          query.where = where
          query.geometry = geo ? geo : null;
          query.outSpatialReference = self.mapView.spatialReference
          const queryTask = new self.QueryTask(url);
           queryTask.execute(query)
               .then(response => {
                   resolve(response)
               })
     })
},

注意新旧版本的Query的变化!!!

文章来源:https://blog.csdn.net/baicai_123/article/details/134967710
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。