|
@@ -0,0 +1,84 @@
|
|
|
+import axios from 'axios'
|
|
|
+// eslint-disable-next-line no-unused-vars
|
|
|
+import { AxiosResponse } from 'axios'
|
|
|
+// eslint-disable-next-line no-unused-vars
|
|
|
+import { Feature } from 'ol'
|
|
|
+import { EsriJSON } from 'ol/format'
|
|
|
+
|
|
|
+/**
|
|
|
+ * https://developers.arcgis.com/rest/services-reference/enterprise/query-image-service-.htm
|
|
|
+ * @typedef RequestParameters
|
|
|
+ * @type {object}
|
|
|
+ */
|
|
|
+
|
|
|
+/**
|
|
|
+ * @typedef {Object} ResponseS
|
|
|
+ * @property {string} displayFieldName
|
|
|
+ * @property {Array<({attributes:Object,geometry:{rings:Array}}|Feature)>} features
|
|
|
+ * @property {Object} fieldAliases
|
|
|
+ * @property {Array<Object>} fields
|
|
|
+ */
|
|
|
+
|
|
|
+/**
|
|
|
+ * @param {String} url
|
|
|
+ * @param {Object} [param]
|
|
|
+ * @param {string} [param.where='1=1']
|
|
|
+ * @param {string} [param.text]
|
|
|
+ * @param {string} [param.objectIds]
|
|
|
+ * @param {string} [param.time]
|
|
|
+ * @param {string} [param.geometry]
|
|
|
+ * @param {string} [param.geometryType='esriGeometryEnvelope']
|
|
|
+ * @param {string} [param.inSR]
|
|
|
+ * @param {string} [param.spatialRel='esriSpatialRelIntersects']
|
|
|
+ * @param {string} [param.relationParam]
|
|
|
+ * @param {string} [param.outFields]
|
|
|
+ * @param {boolean} [param.returnGeometry=true]
|
|
|
+ * @param {boolean} [param.returnTrueCurves=false]
|
|
|
+ * @param {string} [param.maxAllowableOffset]
|
|
|
+ * @param {string} [param.geometryPrecision]
|
|
|
+ * @param {string} [param.outSR='4326']
|
|
|
+ * @param {boolean} [param.returnIdsOnly=false]
|
|
|
+ * @param {boolean} [param.returnCountOnly=false]
|
|
|
+ * @param {string} [param.orderByFields]
|
|
|
+ * @param {string} [param.groupByFieldsForStatistics]
|
|
|
+ * @param {string} [param.outStatistics]
|
|
|
+ * @param {boolean} [param.returnZ=false]
|
|
|
+ * @param {boolean} [param.returnM=false]
|
|
|
+ * @param {string} [param.gdbVersion]
|
|
|
+ * @param {boolean} [param.returnDistinctValues=false]
|
|
|
+ * @param {string} [param.resultOffset]
|
|
|
+ * @param {string} [param.resultRecordCount]
|
|
|
+ * @param {string} [param.f='pjson']
|
|
|
+ * @param {boolean} [toFeature=false]
|
|
|
+ * @returns {Promise<ResponseS>}
|
|
|
+ */
|
|
|
+export function arcgisIdentify (url, param, toFeature = false) {
|
|
|
+ const _default = {
|
|
|
+ geometry: '',
|
|
|
+ geometryType: 'esriGeometryEnvelope',
|
|
|
+ sr: 4326,
|
|
|
+ layers: 'visible',
|
|
|
+ tolerance: 3,
|
|
|
+ returnGeometry: true,
|
|
|
+ maxAllowableOffset: '',
|
|
|
+ geometryPrecision: '',
|
|
|
+ f: 'json'
|
|
|
+ }
|
|
|
+
|
|
|
+ Object.assign(_default, param)
|
|
|
+ const data = new FormData()
|
|
|
+ for (const key in _default) {
|
|
|
+ data.set(key, _default[key])
|
|
|
+ }
|
|
|
+ return axios.get(url, {params : data}).then(({ data: resp }) => {
|
|
|
+ if (resp.error) {
|
|
|
+ const { details, message } = resp.error
|
|
|
+ // return Promise.reject(new Error([message, ...details].join(';') || 'Error'))
|
|
|
+ return Promise.reject([message, ...details].join(';') || 'Error')
|
|
|
+ }
|
|
|
+ if (toFeature) {
|
|
|
+ resp.features = new EsriJSON().readFeatures(resp)
|
|
|
+ }
|
|
|
+ return resp
|
|
|
+ })
|
|
|
+}
|