类名 common/service/igs/arcgis/ArcGISFeatureServer.js
import BaseServer from '../../BaseServer'
import { Zondy } from '../../../base'
import { FetchMethod } from '../../../base/enum'

/**
 * ArcGIS的FeatureServer服务
 * @class ArcGISFeatureServer
 * @moduleEx ServiceModule
 * @extends BaseServer
 * @param {Object} options 构造参数
 * @param {String} [options.url = 无] 服务基地址
 */
class ArcGISFeatureServer extends BaseServer {
  constructor(options) {
    super(options)
  }

  /**
   * 要素服务文档查询
   * @param options 查询参数
   * @param {Function} [options.success] 成功回调函数
   * @param {Function} [options.failure] 失败回调函数
   * @param {Array} [options.layerDefs] 每个图层的查询条件
   * @param {Object} [options.geometries] 几何查询条件
   * @param {String} [options.geometryType] 几何类型
   * @param {String} [options.inSR] 几何查询的坐标系
   * @param {String} [options.spatialRel] 几何查询的相交关系
   * @param {Number} [options.time] 几何查询的相交关系
   * @param {String} [options.outSR] 返回的数据的坐标系
   * @param {String} [options.gdbVersion]
   * @param {Boolean} [options.returnGeometry] 是否返回几何
   * @param {Number} [options.maxAllowableOffset]
   * @param {Boolean} [options.returnIdsOnly] 是否仅返回要素id
   * @param {Boolean} [options.returnCountOnly] 是否仅返回要素数量
   * @param {Boolean} [options.returnZ] 返回几何是否包含z值
   * @param {Boolean} [options.returnM] 返回几何是否包含m值
   * @param {Number} [options.geometryPrecision] 返回几何的小数点位数
   */
  queryFeatures(options) {
    // 设置PATH PARAMETERS校验
    const checkPathOpts = {}

    // 设置QUERY PARAMETERS校验
    const checkQueryOpts = {
      layerDefs: {
        type: 'Array'
      },
      geometries: {
        type: 'Object',
        required: true,
        process(geometries) {
          return `&geometries=${JSON.stringify(geometries)}`
        }
      },
      geometryType: {
        type: 'String'
      },
      inSR: {
        type: 'String'
      },
      spatialRel: {
        type: 'String'
      },
      time: {
        type: 'Number'
      },
      outSR: {
        type: 'Number'
      },
      gdbVersion: {
        type: 'Number'
      },
      returnGeometry: {
        type: 'Boolean'
      },
      maxAllowableOffset: {
        type: 'Number'
      },
      returnIdsOnly: {
        type: 'Boolean'
      },
      returnCountOnly: {
        type: 'Boolean'
      },
      returnZ: {
        type: 'Boolean'
      },
      returnM: {
        type: 'Boolean'
      },
      geometryPrecision: {
        type: 'Boolean'
      }
    }

    options.method = FetchMethod.get
    // 调用基类的查询信息方法
    return this._queryByParameters(
      options,
      checkPathOpts,
      checkQueryOpts,
      // 拼装返回基地址
      function (url) {
        return `${url}/query?f=json`
      }
    )
  }

  /**
   * 查询指定图层信息
   * @param options 查询参数
   * @param {String} [options.layerId] 图层ID,必填
   * @param {Function} [options.success] 查询成功回调函数,若使用Promise方式则不必填写
   * @param {Function} [options.failure] 查询失败回调函数,若使用Promise方式则不必填写
   */
  queryLayerInfo(options) {
    // 设置PATH PARAMETERS校验
    const checkPathOpts = {
      layerId: 'String'
    }

    // 设置QUERY PARAMETERS校验
    const checkQueryOpts = {}

    options.method = FetchMethod.get
    // 调用基类的查询信息方法
    return this._queryByParameters(
      options,
      checkPathOpts,
      checkQueryOpts,
      // 拼装返回基地址
      function (url, options) {
        return `${url}/${options.layerId}?f=json`
      }
    )
  }

  /**
   * @description 添加要素
   * @param options 查询参数
   * @param {String} [options.layerId] 要添加要素的图层id,必填
   * @param {Array} [options.features] 要添加的要素,必填
   * @param {Function} [options.success] 成功回调函数
   * @param {Function} [options.failure] 失败回调函数
   * @param {String} [options.gdbVersion]
   * @param {String} [options.rollbackOnFailure]
   */
  addFeatures(options) {
    // 设置PATH PARAMETERS校验
    const checkPathOpts = {
      layerId: {
        type: 'String'
      }
    }

    // 设置QUERY PARAMETERS校验
    const checkQueryOpts = {
      features: {
        type: 'Array',
        required: true
      },
      gdbVersion: {
        type: 'String'
      },
      rollbackOnFailure: {
        type: 'Boolean'
      }
    }

    options.method = FetchMethod.get
    // 调用基类的查询信息方法
    return this._queryByParameters(
      options,
      checkPathOpts,
      checkQueryOpts,
      // 拼装返回基地址
      function (url, options) {
        return `${url}/${options.layerId}/addFeatures?f=json`
      }
    )
  }

  /**
   * 编辑指定图层要素
   * @param options 查询参数
   * @param {String} [options.layerId] 要添加要素的图层id,必填
   * @param {Array} [options.features] 要添加的要素,必填
   * @param {Function} [options.success] 成功回调函数
   * @param {Function} [options.failure] 失败回调函数
   * @param {String} [options.gdbVersion]
   * @param {String} [options.rollbackOnFailure]
   * @param {String} [options.adds]
   * @param {String} [options.updates]
   * @param {String} [options.deletes]
   */
  editFeatures(options) {
    // 设置PATH PARAMETERS校验
    const checkPathOpts = {
      layerId: {
        type: 'String'
      }
    }

    // 设置QUERY PARAMETERS校验
    const checkQueryOpts = {
      adds: {
        type: 'String'
      },
      updates: {
        type: 'String'
      },
      deletes: {
        type: 'String'
      },
      features: {
        type: 'Array',
        required: true
      },
      gdbVersion: {
        type: 'String'
      },
      rollbackOnFailure: {
        type: 'Boolean'
      }
    }

    options.method = FetchMethod.get
    // 调用基类的查询信息方法
    return this._queryByParameters(
      options,
      checkPathOpts,
      checkQueryOpts,
      // 拼装返回基地址
      function (url, options) {
        return `${url}/${options.layerId}/addFeatures?f=json`
      }
    )
  }

  /**
   * @description 指定图层删除要素
   * @param options 查询参数
   * @param {String} [options.layerId] 要添加要素的图层id,必填
   * @param {Function} [options.success] 成功回调函数
   * @param {Function} [options.failure] 失败回调函数
   * @param {String} [options.objectIds] 指定要删除的id,多个id以逗号分割
   * @param {String} [options.where] where查询
   * @param {Object} [options.geometry] 几何查询
   * @param {String} [options.geometryType] 几何查询类型
   * @param {String} [options.inSR] 几何查询坐标系
   * @param {String} [options.spatialRel] 几何查询关系
   * @param {String} [options.gdbVersion]
   * @param {String} [options.rollbackOnFailure]
   */
  deleteFeatures(options) {
    // 设置PATH PARAMETERS校验
    const checkPathOpts = {
      layerId: {
        type: 'String'
      }
    }

    // 设置QUERY PARAMETERS校验
    const checkQueryOpts = {
      objectIds: {
        type: 'String'
      },
      where: {
        type: 'String'
      },
      geometry: {
        type: 'Object'
      },
      geometryType: {
        type: 'String'
      },
      inSR: {
        type: 'String'
      },
      spatialRel: {
        type: 'String'
      },
      gdbVersion: {
        type: 'String'
      },
      rollbackOnFailure: {
        type: 'String'
      }
    }

    options.method = FetchMethod.get
    // 调用基类的查询信息方法
    return this._queryByParameters(
      options,
      checkPathOpts,
      checkQueryOpts,
      // 拼装返回基地址
      function (url, options) {
        return `${url}/${options.layerId}/addFeatures?f=json`
      }
    )
  }

  /**
   * 要素服务图层查询
   * @param options 查询参数
   * @param {String} [options.layerId] 图层ID,必填
   * @param {String} [options.where] where查询条件,类似sql语句
   * @param {Function} [options.success] 查询成功回调函数,若使用Promise方式则不必填写
   * @param {Function} [options.failure] 查询失败回调函数,若使用Promise方式则不必填写
   */
  queryFeaturesInLayer(options) {
    // 设置PATH PARAMETERS校验
    const checkPathOpts = {
      layerId: {
        type: 'String'
      }
    }

    // 设置QUERY PARAMETERS校验
    const checkQueryOpts = {
      where: {
        type: 'String'
      },
      geometry: {
        type: 'Geometry'
      },
      distance: {
        type: 'Number'
      },
      geometryPrecision: {
        type: 'Number'
      },
      spatialRel: {
        type: 'String'
      },
      outFields: {
        type: 'String'
      },
      objectIds: {
        type: 'String'
      },
      orderByFields: {
        type: 'String'
      },
      groupByFieldsForStatistics: {
        type: 'String'
      },
      resultRecordCount: {
        type: 'Number'
      },
      resultOffset: {
        type: 'Number'
      },
      outStatistics: {
        type: 'OutStatistics'
      },
      returnGeometry: {
        type: 'Boolean'
      },
      returnAttribute: {
        type: 'Boolean'
      },
      returnStyle: {
        type: 'Boolean'
      },
      returnIdsOnly: {
        type: 'Boolean'
      },
      returnCountOnly: {
        type: 'Boolean'
      },
      returnExtentOnly: {
        type: 'Boolean'
      },
      returnZ: {
        type: 'Boolean'
      }
    }

    // 调用基类的查询信息方法
    return this._queryByParameters(
      options,
      checkPathOpts,
      checkQueryOpts,
      // 拼装返回基地址
      function (url, options) {
        return `${url}/${options.layerId}/query?f=json`
      }
    )
  }

  /**
   * @description 指定图层更新要素
   * @param options 查询参数
   * @param {String} [options.layerId] 要添加要素的图层id,必填
   * @param {Array} [options.features] 要添加的要素,必填
   * @param {Function} [options.success] 成功回调函数
   * @param {Function} [options.failure] 失败回调函数
   * @param {String} [options.gdbVersion]
   * @param {String} [options.rollbackOnFailure]
   */
  updateFeatures(options) {
    // 设置PATH PARAMETERS校验
    const checkPathOpts = {
      layerId: {
        type: 'String'
      }
    }

    // 设置QUERY PARAMETERS校验
    const checkQueryOpts = {
      features: {
        type: 'Array',
        required: true
      },
      gdbVersion: {
        type: 'String'
      },
      rollbackOnFailure: {
        type: 'Boolean'
      }
    }

    options.method = FetchMethod.get
    // 调用基类的查询信息方法
    return this._queryByParameters(
      options,
      checkPathOpts,
      checkQueryOpts,
      // 拼装返回基地址
      function (url, options) {
        return `${url}/${options.layerId}/updateFeatures?f=json`
      }
    )
  }

  /**
   * 查询指定要素
   * @param options 查询参数
   * @param {String} [options.layerId] 图层ID,必填
   * @param {String} [options.featureId] 要素ID,必填
   * @param {Function} [options.success] 查询成功回调函数,若使用Promise方式则不必填写
   * @param {Function} [options.failure] 查询失败回调函数,若使用Promise方式则不必填写
   */
  queryFeatureInfo(options) {
    // 设置PATH PARAMETERS校验
    const checkPathOpts = {
      layerId: {
        type: 'String'
      },
      featureId: {
        type: 'String'
      }
    }

    // 设置QUERY PARAMETERS校验
    const checkQueryOpts = {}

    options.method = FetchMethod.get
    // 调用基类的查询信息方法
    return this._queryByParameters(
      options,
      checkPathOpts,
      checkQueryOpts,
      // 拼装返回基地址
      function (url, options) {
        return `${url}/${options.layerId}/${options.featureId}?f=json`
      }
    )
  }
}

Zondy.Service.ArcGISFeatureServer = ArcGISFeatureServer
export default ArcGISFeatureServer
构造函数
成员变量
方法
事件