diff --git a/src/service/ArcGis/BaseParam.js b/src/service/ArcGis/BaseParam.js new file mode 100644 index 000000000..c36d32bc3 --- /dev/null +++ b/src/service/ArcGis/BaseParam.js @@ -0,0 +1,44 @@ +import { + Zondy,cloneObject +} from '../common'; + +/** + * @class module:ArcGis.ArcGisBaseParam + * @description ArcGis服务 + * @author 基础平台-杨琨 + */ +class ArcGisBaseParam { + clone(){ + //完全返回一个新对象 + return cloneObject(this); + } + + //接收一个参数对象,如果参数对象里的值,本身也含有,则赋值,否则不赋值 + static fromJSON(JSON){ + let me = new this(); + if(JSON instanceof Object){ + for(let key in JSON){ + if(me.hasOwnProperty(key)){ + me[key] = JSON[key]; + } + } + } + return me; + } + + toJSON(){ + //按照arcgis的tiJson编写,因为只接受对象类型,因此不做其他类型判断,返回一个对象 + let objInn = this; + let returnObj = {}; + for (let attr in objInn) { + if (typeof objInn[attr] !== "function" && attr !== "CLASS_NAME") { + if(objInn[attr]) returnObj[attr] = objInn[attr]; + } + } + returnObj["spatialRel"] = "esriSpatialRelIntersects"; + return returnObj; + } +} + +export {ArcGisBaseParam}; +Zondy.Service.ArcGisBaseParam = ArcGisBaseParam; \ No newline at end of file diff --git a/src/service/ArcGis/Extent.js b/src/service/ArcGis/Extent.js new file mode 100644 index 000000000..b5167760e --- /dev/null +++ b/src/service/ArcGis/Extent.js @@ -0,0 +1,263 @@ +import {extend, Zondy,notNULL} from "../common"; +import {ArcGisGeometry} from "./Geometry"; +import {ArcGisPoint} from "./Point"; +import * as T from '@turf/turf' +import * as H from '@turf/helpers' + +/** + * @class module:ArcGis.ArcGisExtent + * @description ArcGisExtent对象 + * @author 基础平台-杨琨 + * @param options - {Object} 必选项,构造Extent对象参数。 + * @param {String} [query.xmin] 可选项,x轴最小坐标。 + * @param {String} [query.ymin] 可选项,x轴最大坐标。 + * @param {String} [query.ymin] 可选项,y轴最小坐标。 + * @param {String} [query.ymax] 可选项,y轴最小坐标。 + * @param {String} [query.zmin] 可选项,z轴最小坐标。 + * @param {String} [query.zmax] 可选项,z轴最小坐标。 + * @param {String} [query.mmin] 可选项,m轴最小坐标。 + * @param {String} [query.mmax] 可选项,m轴最小坐标。 + */ + +class ArcGisExtent extends ArcGisGeometry{ + constructor(options) { + super(options); + this.center = undefined; + this.hasM = false; + this.hasZ = false; + this.height = 0; + this.mmax = undefined; + this.mmin = undefined; + this.type = "extent"; + this.width = 0; + this.xmax = 0; + this.xmin = 0; + this.ymax = 0; + this.ymin = 0; + this.zmax = undefined; + this.zmin = undefined; + this.extent = this; + + //确保私有变量不能被options修改 + this.private = ["center","hasM","hasZ","height","width","type","extent"]; + for (let key in this.private){ + if(notNULL(options[this.private[key]])){ + throw new Error("[accessor] cannot assign to read-only property '" + this.private[key] + "' of ArcGisExtent"); + } + } + + extend(this,options); + + //如果z、m有值,hasZ、hasM采薇true + if(this.zmax || this.zmin){ + this.hasZ = true; + } + if(this.mmax || this.mmin){ + this.hasM = true; + } + + //生成bbox + this._extentPolygon = T.polygon([[ + [this.xmin, this.ymin], + [this.xmin, this.ymax], + [this.xmax, this.ymax], + [this.ymax, this.ymin], + [this.xmin, this.ymin] + ]],{name:"_extentPlygon"}); + + //生成中心点 + this.center = initCenter(this); + + //计算width,height + this.width = this.xmax - this.xmin; + this.height = this.ymax - this.ymin; + } +} + +function initCenter(me){ + let points = [ + H.point( [me.xmin, me.ymin]), + H.point( [me.xmin, me.ymax]), + H.point( [me.xmax, me.ymax]), + H.point( [me.ymax, me.ymin]), + H.point( [me.xmin, me.ymin]) + ]; + let featureCollection = H.featureCollection(points); + let coordinates = T.center(featureCollection).geometry.coordinates; + return new ArcGisPoint({ + longitude: coordinates[0], + latitude: coordinates[1] + }); +} + +/** + * @function module:ArcGis.ArcGisExtent.prototype.equals + * @description 比较两个Extent对象是否相等 + * @param extent - {ArcGisExtent} 必选项,要比较的ArcGisExtent对象。 + * @returns Boolean,对象是否相等 + */ +ArcGisExtent.prototype.equals = function (extent){ + return this.mmax === extent.mmax && + this.mmin === extent.mmin && + this.xmax === extent.xmax && + this.xmin === extent.xmin && + this.ymax === extent.ymax && + this.ymin === extent.ymin && + this.zmax === extent.zmax && + this.zmin === extent.zmin; +} + +/** + * @function module:ArcGis.ArcGisExtent.prototype.contains + * @description 判断是否包含一个点或者一个ArcGisExtent对象 + * @param geometry - {Geometry} 必选项,要比较的ArcGisExtent对象或者ArcGisPoint对象。 + * @returns Boolean,是否包含 + */ +ArcGisExtent.prototype.contains = function (geometry){ + if(geometry.type === "point"){ + let point = geometry.toArray(); + point = T.point([point[0], point[1]]); + return T.booleanContains(this._extentPolygon,point) + } + if(geometry.type === "extent"){ + return T.booleanContains(this._extentPolygon,geometry._extentPolygon) + } + return false; +} + +/** + * @function module:ArcGis.ArcGisExtent.prototype.expand + * @description 根据输入的值,扩大或缩小一个ArcGisExtent + * @param factor - {Number} 必选项,放大或缩小系数。 + * @returns ArcGisExtent,缩放后的ArcGisExtent + */ +ArcGisExtent.prototype.expand = function (factor){ + if(factor instanceof Number){ + factor = Math.abs(factor); + this.width = this.width * factor; + this.height = this.height * factor; + this.xmin = this.center.x - this.width / 2; + this.xmax = this.center.x + this.width / 2; + this.ymin = this.center.y - this.height / 2; + this.ymax = this.center.y + this.height / 2; + return this; + }else { + throw new Error("require is not defined"); + } +} + +/** + * @function module:ArcGis.ArcGisExtent.prototype.intersects + * @description 比较点、多点、线、多边形、extent是否与当前extent相交 + * @param geometry - {Geometry} 必选项,要比较的几何对象。 + * @returns Boolean,是否相交 + */ +ArcGisExtent.prototype.intersects = function (geometry){ + if(!geometry.type){ + return false; + } + let geom; + if(geometry.type === "polyline"){ + geom = H.multiLineString(geometry.paths); + }else if(geometry.type === "point"){ + geom = H.point(geometry.toArray()); + }else if(geometry.type === "multipoint"){ + geom = H.multiPoint(geometry.points); + }else if(geometry.type === "extent"){ + geom = geometry._extentPolygon; + }else if(geometry.type === "polygon"){ + geom = H.polygon(geometry.rings); + } + return !T.booleanDisjoint(geom,this._extentPolygon); +} + +/** + * @function module:ArcGis.ArcGisExtent.prototype.offset + * @description 根据输入的dx, dy, dz值,平移extend + * @param dx - {Number} 必选项,要平移的x值。 + * @param dx - {Number} 必选项,要平移的y值。 + * @param dx - {Number} 必选项,要平移的z值。 + * @returns ArcGisExtent,平移后的ArcGisExtent对象 + */ +ArcGisExtent.prototype.offset = function (dx, dy, dz){ + this.xmax += dx; + this.xmin += dx; + this.ymax += dy; + this.ymin += dy; + if(this.hasZ){ + this.zmax += dz; + this.zmin += dz; + }else { + this.hasZ = true; + this.zmax = 0; + this.zmin = 0; + } + return this; +} + +/** + * @function module:ArcGis.ArcGisExtent.prototype.centerAt + * @description 根据输入的ArcGisPoint对象,生成衣蛾新的中心点 + * @param point - {ArcGisPoint} 必选项,新的中心点。 + * @returns ArcGisExtent + */ +ArcGisExtent.prototype.centerAt = function (point){ + if(point instanceof ArcGisPoint){ + this.center = new ArcGisPoint({ + longitude: point.x, + latitude: point.y + }); + this.xmin = this.center.x - this.width / 2; + this.xmax = this.center.x + this.width / 2; + this.ymin = this.center.y - this.height / 2; + this.ymax = this.center.y + this.height / 2; + return this; + } +} + +ArcGisExtent.prototype.normalize = function (){ + return [this]; +} + +/** + * @function module:ArcGis.ArcGisExtent.prototype.union + * @description 输入一个ArcGisExtent对象,与原extent对象合并,生成一个新的extent + * @param extent - {ArcGisExtent} 必选项,要合并的ArcGisExtent对象。 + * @returns ArcGisExtent,新的Extent对象 + */ +ArcGisExtent.prototype.union = function (extent){ + let cur = this.center; + let nex = extent.center; + if(((nex.x - cur.x) > 0 && (nex.y - cur.y) > 0) || ((nex.x - cur.x) === 0 && (nex.y - cur.y) > 0) + || ((nex.x - cur.x) === 0 && (nex.y - cur.y) === 0) + || ((nex.x - cur.x) > 0 && (nex.y - cur.y) === 0)){ + this.xmax = extent.xmax; + this.ymax = extent.ymax; + }else if((nex.x - cur.x) > 0 && (nex.y - cur.y) < 0 || ((nex.x - cur.x) === 0 && (nex.y - cur.y) < 0)){ + this.xmax = extent.xmax; + this.ymin = extent.ymin; + }else if((nex.x - cur.x) < 0 && (nex.y - cur.y) < 0){ + this.xmin = extent.xmin; + this.ymin = extent.ymin; + }else if((nex.x - cur.x) < 0 && (nex.y - cur.y || ((nex.x - cur.x) < 0 && (nex.y - cur.y) < 0)) === 0){ + this.xmin = extent.xmin; + this.ymax = extent.ymax; + } + this.center = initCenter(this); + //计算width,height + this.width = this.xmax - this.xmin; + this.height = this.ymax - this.ymin; + return this; +} + +/** + * @function module:ArcGis.ArcGisExtent.prototype.toString + * @description 返回如下格式的字符串:"xmin,ymin,xmax,ymax" + * @returns Sting + */ +ArcGisExtent.prototype.toString = function (){ + return this.xmin + "," + this.ymin + "," + this.xmax + "," + this.ymax; +} + +export {ArcGisExtent}; +Zondy.Service.ArcGisExtent = ArcGisExtent; \ No newline at end of file diff --git a/src/service/ArcGis/FeatureLayer.js b/src/service/ArcGis/FeatureLayer.js new file mode 100644 index 000000000..3622c71ee --- /dev/null +++ b/src/service/ArcGis/FeatureLayer.js @@ -0,0 +1,747 @@ +import { + Zondy,formatQuery,formatEdits,extend +} from '../common'; +import {ArcGisServiceBase} from "./ServiceBase"; +import {ArcGisQuery} from "./Query"; + +/** + * @class module:ArcGis.ArcGisFeatureLayer + * @description ArcGis服务 + * @author 基础平台-杨琨 + */ +class ArcGisFeatureLayer { + constructor(options) { + this.id = null; + this.uid = null; + this.indexes = { + items : [] + }; + this.load = null; + + this.attributionVisible = true; + this.listMode = "show"; + this.hasAttributionData = false; + this.createQueryVersion = 1; + this.blendMode = "normal"; + this.capabilities = null; + this.copyright = null; + this.loadError = null; + this.loadStatus = "not-loaded"; + this.loaded = false; + this.loadWarnings = []; + this.customParameters = null; + this.definitionExpression = null; + this.displayField = null; + this.dynamicDataSource = null; + this.editFieldsInfo = null; + this.editingEnabled = true; + this.editingInfo = null; + this.effect = null; + this.elevationInfo = null; + this.featureReduction = null; + this.fields = null; + this.fieldsIndex = { + dateFields:[], + fields:[], + uid:"" + }; + this.formTemplate = null; + this.gdbVersion = null; + this.geometryType = null; + this.hasM = null; + this.hasZ = null; + this.historicMoment = null; + this.isTable = false; + this.labelingInfo = null; + this.labelsVisible = true; + this.layerId = null; + this.legendEnabled = true; + this.maxScale = 0; + this.minScale = 0; + this.opacity = 1; + this.operationalLayerType = "ArcGisFeatureLayer"; + this.objectIdField = null; + this.outFields = null; + this.parent = null; + this.path = null; + this.parsedUrl = null; + this.popupEnabled = true; + this.popupTemplate = null; + this.portalItem = null; + this.refreshInterval = 0; + this.relationships = null; + this.renderer = null; + this.returnM = null; + this.returnZ = null; + this.resourceReferences = { + paths:[], + portalItem: null + }; + this.screenSizePerspectiveEnabled = true; + this.serviceDefinitionExpression = null; + this.source = null; + this.scaleRangeId = "0,0"; + this.sourceJSON = null; + this.spatialReference = { + imageCoordinateSystem: null, + isGeographic: true, + isWGS84: true, + isWebMercator: false, + isWrappable: true, + latestVcsWkid: null, + latestWkid: null, + vcsWkid: null, + wkid: 4326, + wkt: "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]" + }; + this.templates = null; + this.sublayerTitleMode = "item-title"; + this.timeExtent = null; + this.timeInfo = null; + this.timeOffset = null; + this.title = ""; + this.trackIdField = null; + this.type = "feature"; + this.typeIdField = null; + this.types = null; + this.url = null; + this.useViewTime = true; + this.version = null; + this.userIsAdmin = false; + this.visible = true; + + extend(this,options) + + //判断是查询整个地图还是单个图层 + this._queryService = this.url && this.url.indexOf('FeatureServer') + 'FeatureServer'.length === this.url.length ? 'queryByMap' : 'queryByLayer' + this._applyEditsService = this.url && this.url.indexOf('FeatureServer') + 'FeatureServer'.length === this.url.length ? 'applyEditsByMap' : 'applyEditsByLayer' + let service = new ArcGisServiceBase(); + //对整个地图查询,url为http://localhost:6080/arcgis/rest/services/wuhan_2/FeatureServer + this.queryByMap = function (query) { + let url = this.url + "/query?f=json"; + url = formatQuery(query,url,["geometry","layerDefs"],null); + return service.getPromise(url); + } + //对单个图层查询,url为http://localhost:6080/arcgis/rest/services/wuhan_2/FeatureServer/{layerId} + this.queryByLayer = function (query) { + let url = this.url + "/query?f=json"; + url = formatQuery(query,url,["geometry"],null); + return service.getPromise(url); + } + + //单个图层编辑 + this.applyEditsByLayer = function (edits,options) { + let url = this.url + "/applyEdits",dataStr="",me = this; + options = options ? options : { + gdbVersion:[], + rollbackOnFailure: true, + f:'json' + } + //处理edits + let editArr = ["addFeatures","updateFeatures","deleteFeatures"]; + if(edits.deleteFeatures){ + let IdsArr = []; + for(let i = 0;i < edits.deleteFeatures.length;i++){ + IdsArr.push(edits.deleteFeatures[i].objectId); + } + edits.deleteFeatures = IdsArr.join(","); + } + dataStr = formatEdits(dataStr,edits,editArr); + //处理options + dataStr = formatEdits(dataStr,options); + //去聊多余的&符号 + dataStr = dataStr.substring(0,dataStr.length - 1); + return service.getPromiseP(url,dataStr); + } + + //整个地图编辑 + this.applyEditsByMap = function (edits,options) { + options = options ? options : { + gdbVersion:[], + rollbackOnFailure: true, + f:'json' + } + let url = this.url + "/applyEdits",dataStr=""; + //处理请求参数 + //处理edits + dataStr += "edits=" + encodeURIComponent(JSON.stringify(edits)) + "&"; + //处理options + dataStr = formatEdits(dataStr,options); + //去聊多余的&符号 + dataStr = dataStr.substring(0,dataStr.length - 1); + return service.getPromiseP(url,dataStr); + } + } +} + +/** + * @function module:ArcGis.ArcGisFeatureLayer.prototype.createQuery + * @description 创建查询参数对象 + * @author 基础平台-杨琨 + */ +ArcGisFeatureLayer.prototype.createQuery = function () { + return new ArcGisQuery(); +} + + +/** + * @function module:ArcGis.ArcGisFeatureLayer.prototype.queryFeatures + * @description 查询要素信息 + * @author 基础平台-杨琨 + * @param query - {String} 必选项,查询参数。 + * @param {String} [query.geometry] 可选项。几何对象,要素查询条件,形式为x,y坐标。支持单个点,多个点、线、矩形、多边形。无需配合where使用,可单独查询。 + * 格式为:geometry对象或xmin,ymin,xmax,ymax点坐标;Example:单个点:geometry=-104,35.6;封闭矩形:geometry=-104,35.6,-94.32,41;geometry对象:{xmin: -104, ymin: 35.6, xmax: -94.32, ymax: 41}; + * 参考链接:Geometry objects:https://developers.arcgis.com/documentation/common-data-types/geometry-objects.htm + * @param {String} [query.geometryType] 可选项。配合geometry使用,当通过几何对象进行要素查询时,集合对象的类型,默认为矩形。可选值为:esriGeometryPoint | esriGeometryMultipoint | esriGeometryPolyline | esriGeometryPolygon | esriGeometryEnvelope + * Example:geometryType=esriGeometryEnvelope + * @param {String} [query.spatialRel] 可选项。空间关系。即所选的几何对象与图层的相交关系。例如包含、相交、相离等,默认值为esriSpatialRelIntersects。 + * 可选值为:esriSpatialRelIntersects | esriSpatialRelContains | esriSpatialRelCrosses | esriSpatialRelEnvelopeIntersects | esriSpatialRelIndexIntersects | esriSpatialRelOverlaps | esriSpatialRelTouches | esriSpatialRelWithin + * Example:spatialRel=esriSpatialRelIntersects + * @param {String} [query.returnGeometry] 可选项。返回要素集合时,是否返回几何信息。默认为true。返回几何信息。可选值:true | false + * @param {String} [query.geometryPrecision] 可选项。指定返回的要素集合中x、y坐标的小数位数。Example:geometryPrecision=3 + * @param {String} [query.maxAllowableOffset] 可选项。简化返回的几何要素时,允许的最大偏移量。对返回的要素的geometry对象起作用。 + * @param {String} [query.where] 可选项。通过where进行条件查询。与整个地图的查询相比没有返回值过滤。Example:where=POP2000 > 350000 + * 参考链接:SQL语句:https://developers.arcgis.com/rest/services-reference/query-feature-service-.htm#ESRI_SECTION2_07DD2C5127674F6A814CE6C07D39AD46 + * @param {String} [query.sqlFormat] 可选项。sql语句的格式,默认为none。 + * @param {String} [query.objectIds] 可选项。通过Id查询要素。格式:objectIds=, ;Example:objectIds=37, 462 + * @param {String} [query.orderByFields] 可选项。返回的要素几何以何种方式进行排序。是升序或降序。格式:orderByFields=field1 , field2 , field3 ; + * Example: orderByFields=STATE_NAME ASC, RACE DESC, GENDER + * @param {String} [query.groupByFieldsForStatistics] 可选项。"以某个字段进行分组。只有当outStatistics 为true是有效 + * 格式:groupByFieldsForStatistics=field1, field2;Example:groupByFieldsForStatistics=STATE_NAME, GENDER" + * @param {String} [query.outFields] 可选项。指定要显示的返回字段,为空时都不显示。Example:outFields=AREANAME,ST,POP2000;outFields=* + * @param {String} [query.inSR] 可选项。几何对象的空间参考系。当不指定时,默认为地图的空间参考系。 + * @param {String} [query.outSR] 可选项。返回的要素几何的空间参考系。默认为地图的空间参考系。 + * @param {String} [query.returnCentroid] 可选项。返回要素集合时,是否返回每个要素的中心点。仅对layer有效。默认false;可选值:true | false + * @param {String} [query.returnM] 可选项。是否返回m值,默认为false。可选值:true | false + * @param {String} [query.returnZ] 可选项。是否返回z轴的值,默认为false。可选值:true | false + * @param {String} [query.time] 可选项。按照时间进行查询。有两种方式瞬时查询和范围查询。Example:瞬时查询:time=;time=1199145600000,即 (1 Jan 2008 00:00:00 GMT) + * 范围查询:time=, ;time=1199145600000, 1230768000000,即 (1 Jan 2008 00:00:00 GMT to 1 Jan 2009 00:00:00 GMT);起始时间或结束时间可为null,即time=null, 1230768000000 + * @param {String} [query.distance] 可选项。缓冲距离。Example:distance=;distance=100 + * @param {String} [query.units] 可选项。缓冲距离单位。可选值:esriSRUnit_Meter | esriSRUnit_StatuteMile | esriSRUnit_Foot | esriSRUnit_Kilometer | + * esriSRUnit_NauticalMile | esriSRUnit_USNauticalMile + * @param {String} [query.supportsQueryWithDistance] 可选项。是否开启缓冲距离。默认false,不开启。可选项:true | false + * @param {String} [query.returnDistinctValues] 可选项。返回值是否去重,只保留不同的值。默认为false。最好配合outfields一起使用。也可以和returnCountOnly使用。不能和geometry配合使用可选值:true | false + * @param {String} [query.returnIdsOnly] 可选项。是只返回要素的ID还是返回要素集合。默认为false,即返回要素集合。可选值:true | false + * @param {String} [query.returnCountOnly] 可选项。是只返回查询到的要素数量还是要素集合。默认为false,即返回要素集合。可选值:true | false + * @param {String} [query.returnExtentOnly] 可选项。是否返回要素范围。 + * @param {String} [query.resultOffset] 可选项。当返回要素集合时,返回从resultOffset开始的要素。默认值为0;Example:resultRecordCount=10 + * @param {String} [query.resultRecordCount] 可选项。指定返回结果数量。 + * @param {String} [query.signal ] 可选项。是否取消异步任务。 + * @example + * //加载地图容器 + map = new mapboxgl.Map({ + container: 'map', + crs: 'EPSG:4326', + minZoom: 3, + zoom: 6, + center: [(114.02942023086823 + 114.9174350782441)/2,(30.562371200134724 + 30.96640367892471)/2] + }); + //加载容器的级数控件,非必须 + var navigationControl = new mapboxgl.NavigationControl(); + map.addControl(navigationControl, 'top-left'); + //加载一个地图 + mapDocLayer = new mapboxgl.Zondy.Map.ArcGisTileLayer({ + url: 'http://219.142.81.85/arcgis/rest/services/10wanZH/MapServer', + mapgisOffset: -1 + }); + mapDocLayer.addToMap(map); + //<-----------------------------查询单个图层-------------------------------> + //初始化要素编辑对象 + var queryServiceByLayer = new Zondy.Service.ArcGisFeatureLayer({ + //要查询的图层url,记得发布地图时,勾选Feature Access + url: 'http://localhost:6080/arcgis/rest/services/wuhan_2/FeatureServer/1' + }); + //创建查询参数对象 + var queryParamsLayer = queryServiceByLayer.createQuery(); + //示例一 =====> objectIds查询,这里我查询objectId为155的要素,并返回该要素的全部字段 + queryParamsLayer.objectIds = "155"; + queryParamsLayer.outFields = "*"; + //示例二 =====> where查询,这里我查询Name为金口街道的要素,并返回该要素的Name,countyname字段 + queryParamsLayer.where = "Name = '金口街道'"; + queryParamsLayer.outFields = "Name,countyname"; + //示例三 =====> geometry查询--简单点查询(封闭矩形),并设置returnCountOnly为true只返回要素数量 + queryParamsLayer = queryServiceByLayer.createQuery(); + queryParamsLayer.geometry = "114.100,30.399,114.42,30608"; + queryParamsLayer.returnCountOnly = true; + //示例四 =====> geometry查询--多边形查询,此时geometryType也要设成相应的值esriGeometryPolygon(多边形) + queryParamsLayer.geometry = { + "rings" : [[[114.100,30.399],[114.214,30.723],[114.321,32.344],[114.42,30608], + [114.100,30.399]]], + "spatialReference" : {"wkid" : 4326} + } + queryParamsLayer.geometryType = "esriGeometryPolygon"; + queryParamsLayer.returnCountOnly = false; + //调用查询方法,并在then方法中执行之后的处理步骤 + queryServiceByLayer.queryFeatures(queryParamsLayer).then(function (data){ + console.log('查询单个图层') + console.log(JSON.parse(data)) + }) + //<-----------------------------查询整个地图-------------------------------> + //初始化要素编辑对象 + var queryServiceByMap = new Zondy.Service.ArcGisFeatureLayer({ + //要查询的图层url,记得发布地图时,勾选Feature Access + //此处url没有加layerId!!!,因此查询的是整个地图 + url: 'http://localhost:6080/arcgis/rest/services/wuhan_2/FeatureServer' + }); + //创建查询参数对象 + var queryParamsMap = queryServiceByLayer.createQuery(); + //示例一 =====> layerDefs(where)查询,layerId即图层id,where即查询语句,outFields选择显示的字段 + queryParamsMap.layerDefs = [{"layerId" : 1, "where" : "OBJECTID=155", "outFields" : "Name,pyname"}]; + //示例二 =====> geometry查询--简单点查询(封闭矩形),layerId即图层id,outFields选择显示的字段,注意因为是在整个地图文档上查询 + // 此处必须在layerDefs指定查询的图层,因此不能单独使用geometry + queryParamsMap.layerDefs = [{"layerId" : 1, "outFields" : "Name,pyname"}]; + queryParamsMap.geometry = "114.100,30.399,114.42,30608"; + //示例三 =====> geometry查询--多边形查询 + queryParamsMap.layerDefs = [{"layerId" : 1, "outFields" : "Name,pyname"}]; + //设置要查询的多边形对象,rings为多边形点数组,spatialReference为多边形的坐标系可选填 + queryParamsMap.geometry = { + "rings" : [[[114.100,30.399],[114.214,30.723],[114.321,32.344],[114.42,30608], + [114.100,30.399]]], + "spatialReference" : {"wkid" : 4326} + } + //如果是多边形,这里也要设成相应的选项 + queryParamsMap.geometryType = "esriGeometryPolygon"; + //调用查询方法,并在then方法中执行之后的处理步骤 + queryServiceByMap.queryFeatures(queryParamsMap).then(function (data){ + console.log('查询整个地图') + console.log(JSON.parse(data)) + }) + */ +ArcGisFeatureLayer.prototype.queryFeatures = function (query) { + return this[this._queryService](query); +} + +/** + * @function module:ArcGis.ArcGisFeatureLayer.prototype.applyEdits + * @description 要素编辑 + * @author 基础平台-杨琨 + * @param edits - {Object} 必选项,要执行的要素编辑操作。 + * @param {Array} [edits.addFeatures] 可选项。添加要素的集合。格式addFeatures:[feature-object1,feature-object2,...]。 + * feature-object没有必填项,也就是说空值也会新增。[{},{}]如此则新增两个空数据。其中OBJECTID是自增的,无法指定。 + * 格式为: + * [ + * { + * "geometry":{}, + * "attributes":{} + * } + * ] + * 参考文档:https://developers.arcgis.com/documentation/common-data-types/feature-object.htm + * @param {Array} [edits.updateFeatures] 可选项。要更新要素的集合。格式updateFeatures:[feature-object1,feature-object2,...]。 + * OBJECTID必须填写,其他选填。 + * 格式为: + * [ + * { + * "geometry":{}, + * "attributes":{ + * "OBJECTID":"Your-ID",//OBJECTID必填,其他的都是选填。 + * ... + * } + * } + * ] + * 参考文档:https://developers.arcgis.com/documentation/common-data-types/feature-object.htm + * @param {String} [edits.deleteFeatures] 可选项。删除要素。 + * @param {String} [edits.deleteFeatures.objectIds ] 可选项。通过ObjectId来删除要素。 + * @param {String} [edits.deleteFeatures.where ] 可选项。通过where语句来删除要素。 + * @param {String} [edits.deleteFeatures.geometry ] 可选项。通过geometry对象来删除要素。 + * @param {String} [edits.deleteFeatures.geometryType ] 可选项。指定geometry的想的类型。 + * @param {String} [edits.deleteFeatures.inSR ] 可选项。指定geometry对象的坐标系,默认为地图坐标系。 + * @param {String} [edits.deleteFeatures.spatialRel ] 可选项。指定geometry与图层的相交关系,例如包含、相交、相离等,默认值为esriSpatialRelIntersects。 + 可选值为:esriSpatialRelIntersects | esriSpatialRelContains | esriSpatialRelCrosses | esriSpatialRelEnvelopeIntersects | esriSpatialRelIndexIntersects | esriSpatialRelOverlaps | esriSpatialRelTouches | esriSpatialRelWithin + Example:spatialRel:esriSpatialRelIntersects + * @param options - {Object} 可选项,额外编辑选项。 + * @param {String} [options.gdbVersion] 可选项,地理数据库版本号。 + * @param {String} [options.rollbackOnFailure ] 可选项,是否允许回滚,默认为true,可选值true|false。 + * @param {String} [options.useGlobalIds] 可选项,是否允许使用GlobalId,可选值true|false。 + * @example + * //要素集合 + * var features = [ + * { + "geometry": { + "points": [ + [ + 114.23201742000003, + 30.576808980000067 + ] + ] + }, + "attributes": { + "gml_id": "layer_lottery_pt.58836", + "Name": "彩票销售店", + "pyname": "cpxsd", + "kind": "AE04", + "zipcode": null, + "telephone": "027-83876450", + "display_x": "114.23746", + "display_y": "30.57435", + "side": "L", + "address": "汉宜路170号附近", + "mpLayer": 0 + } + } + ] + //<-------------------------单个图层的编辑操作示例-----------------------------------------> + //初始化要素服务对象 + var queryService = new Zondy.Service.ArcGisFeatureLayer({ + url: 'http://localhost:6080/arcgis/rest/services/wuhan_2/FeatureServer/0' + }); + //新增操作 + //调用编辑服务 + queryService.applyEdits({ + addFeatures: features + }).then(function (data){ + //在这里编写成功之后的操作 + console.log('新增成功') + console.log(data) + }) + //更新操作 + //更新操作必须指定OBJECTID + features[0].attributes.OBJECTID='577' + //调用编辑服务 + queryService.applyEdits({ + updateFeatures: features + }).then(function (data){ + //在这里编写成功之后的操作 + console.log('更新成功') + console.log(data) + }) + //删除操作,通过ObjectId删除要素 + queryService.applyEdits({ + deleteFeatures: 4020 + }).then(function (data){ + //在这里编写成功之后的操作 + console.log('删除成功') + console.log(data) + }) + //先新增要素,然后进行查询操作、新增要素、删除要素、 + //要编辑的要素对象 + var features = [ + { + "geometry": { + "points": [ + [ + 114.23201742000003, + 30.576808980000067 + ] + ] + }, + "attributes": { + "gml_id": "layer_lottery_pt.58836", + "Name": "彩票销售店", + "pyname": "cpxsd", + "kind": "AE04", + "zipcode": null, + "telephone": "027-83876450", + "display_x": "114.23746", + "display_y": "30.57435", + "side": "L", + "address": "汉宜路170号附近", + "mpLayer": 0 + } + } + ] + //初始化要素服务对象 + var queryService = new Zondy.Service.ArcGisFeatureLayer({ + url: 'http://localhost:6080/arcgis/rest/services/wuhan_2/FeatureServer/0' + }); + //调用编辑服务,新增要素 + queryService.applyEdits({ + addFeatures: features + }).then(function (addData){ + //在这里编写成功之后的操作 + console.log('新增成功'); + addData = JSON.parse(addData); + console.log(addData); + //创建查询参数对象 + var queryParamsLayer = queryService.createQuery(); + //设置查询条件,根据objectIds进行查询 + queryParamsLayer.objectIds = addData.addResults[0].objectId; + queryParamsLayer.outFields = "*"; + queryService.queryFeatures(queryParamsLayer).then(function (queryData) { + console.log('查询成功'); + queryData = JSON.parse(queryData); + console.log(queryData); + features[0].attributes.objectId = queryData.features[0].attributes.OBJECTID; + features[0].attributes.Name = "修改名字"; + queryService.applyEdits({ + updateFeatures:features + }).then(function (updateData) { + console.log('更新成功'); + updateData = JSON.parse(updateData); + console.log(updateData); + var objIds = updateData.updateResults[0].objectId; + queryService.applyEdits({ + deleteFeatures:objIds + }).then(function (deleteData) { + console.log('删除成功'); + deleteData = JSON.parse(deleteData); + console.log(deleteData); + }); + }); + }); + }) + //<----------------------整个地图的编辑操作-----------------------------------> + //初始化要素服务对象 + var queryService = new Zondy.Service.ArcGisFeatureLayer({ + //编辑整个地图,因此末尾不带layerId + url: 'http://localhost:6080/arcgis/rest/services/wuhan_2/FeatureServer' + }); + //设置返回格式 + var options = { + gdbVersion:[], + rollbackOnFailure: true, + f:'json' + } + //新增要素 + //新增要素的格式,[{第0个图层新增操作},{第1个图层新增操作},...],对每个图层的操作分开来写,要带上layerid + var edit = [ + { + //id即为layerId,必须带,否则不知道编辑哪一个图层 + "id" : 0, + //adds操作,[feature-object1,feature-object2,feature-object3,...] + adds: [ + { + "geometry": { + "points": [ + [ + 114.23201742000003, + 30.576808980000067 + ] + ] + }, + "attributes": { + "gml_id": "layer_lottery_pt.58836", + "Name": "彩票销售店", + "pyname": "cpxsd", + "kind": "AE04", + "zipcode": null, + "telephone": "027-83876450", + "display_x": "114.23746", + "display_y": "30.57435", + "side": "L", + "address": "汉宜路170号附近", + "mpLayer": 0 + } + } + ] + } + ] + queryService.applyEdits(edit,options).then(function (data){ + //在这里编写成功之后的操作 + console.log('新增成功') + console.log(data) + }) + //更新要素 + var edit = [ + { + //id即为layerId,必须带,否则不知道编辑哪一个图层 + "id" : 0, + //updates操作,[feature-object1,feature-object2,feature-object3,...] + updates: [ + { + "geometry": { + "points": [ + [ + 114.23201742000003, + 30.576808980000067 + ] + ] + }, + "attributes": { + "gml_id": "layer_lottery_pt.58836", + //objectId也必须要带 + "objectId":4013, + "Name": "彩票销售店", + "pyname": "cpxsd", + "kind": "AE04", + "zipcode": null, + "telephone": "027-83876450", + "display_x": "114.23746", + "display_y": "30.57435", + "side": "L", + "address": "汉宜路170号附近", + "mpLayer": 0 + } + } + ] + } + ] + queryService.applyEdits(edit,options).then(function (data){ + //在这里编写成功之后的操作 + console.log('更新成功') + console.log(data) + }) + //根据ObjectId删除要素 + var edit = [ + { + //id即为layerId,必须带,否则不知道编辑哪一个图层 + "id" : 0, + deletes: [4014] + } + ] + queryService.applyEdits(edit,options).then(function (data){ + //在这里编写成功之后的操作 + console.log('删除成功') + console.log(data) + }) + //新增、更新、删除同时进行,图层0、1分别进行操作 + var edit = [ + //对图层0进行操作 + { + //id即为layerId,必须带,否则不知道编辑哪一个图层 + "id" : 0, + adds:[ + { + "geometry": { + "points": [ + [ + 114.23201742000003, + 30.576808980000067 + ] + ] + }, + "attributes": { + "gml_id": "layer_lottery_pt.58836", + "Name": "彩票销售店", + "pyname": "cpxsd", + "kind": "AE04", + "zipcode": null, + "telephone": "027-83876450", + "display_x": "114.23746", + "display_y": "30.57435", + "side": "L", + "address": "汉宜路170号附近", + "mpLayer": 0 + } + } + ], + updates:[ + { + "geometry": { + "points": [ + [ + 114.23201742000003, + 30.576808980000067 + ] + ] + }, + "attributes": { + "gml_id": "layer_lottery_pt.58836", + "objectId":4017, + "Name": "彩票销售店", + "pyname": "cpxsd", + "kind": "AE04", + "zipcode": null, + "telephone": "027-83876450", + "display_x": "114.23746", + "display_y": "30.57435", + "side": "L", + "address": "汉宜路170号附近", + "mpLayer": 0 + } + } + ], + deletes:[4016] + }, + //对图层1进行操作 + { + id:1, + deletes: [155] + } + ] + queryService.applyEdits(edit,options).then(function (data){ + //在这里编写成功之后的操作 + console.log('编辑完成') + console.log(data) + }) + */ +ArcGisFeatureLayer.prototype.applyEdits = function (edits,options) { + return this[this._applyEditsService](edits,options); +} + +/** + * @function module:ArcGis.ArcGisFeatureLayer.prototype.queryFeatureCount + * @description 要素查询,仅返回要素数量 + * @author 基础平台-杨琨 + * @param query - {String} 必选项,查询参数。 + * @param options - {String} 可选项,是否取消异步操作。 + * @example 调用方法同queryObjectIds + */ +ArcGisFeatureLayer.prototype.queryFeatureCount = function (query,options) { + query.returnCountOnly = true; + return this[this._queryService](query); +} + +/** + * @function module:ArcGis.ArcGisFeatureLayer.prototype.queryObjectIds + * @description 要素查询,仅返回ObjectId + * @author 基础平台-杨琨 + * @param query - {String} 必选项,查询参数,参考queryFeatures方法。 + * @param options - {String} 可选项,是否取消异步操作。 + * @example + //加载地图容器 + map = new mapboxgl.Map({ + container: 'map', + crs: 'EPSG:4326', + minZoom: 3, + zoom: 6, + center: [(114.02942023086823 + 114.9174350782441)/2,(30.562371200134724 + 30.96640367892471)/2] + }); + //加载容器的级数控件,非必须 + var navigationControl = new mapboxgl.NavigationControl(); + map.addControl(navigationControl, 'top-left'); + //加载一个地图 + mapDocLayer = new mapboxgl.Zondy.Map.ArcGisTileLayer({ + url: 'http://219.142.81.85/arcgis/rest/services/10wanZH/MapServer', + mapgisOffset: -1 + }); + mapDocLayer.addToMap(map); + //<-----------------------------查询单个图层-------------------------------> + //初始化要素编辑对象 + var queryServiceByLayer = new Zondy.Service.ArcGisFeatureLayer({ + //要查询的图层url,记得发布地图时,勾选Feature Access + url: 'http://localhost:6080/arcgis/rest/services/wuhan_2/FeatureServer/1' + }); + //创建查询参数对象 + var queryParamsLayer = queryServiceByLayer.createQuery(); + //查询layerId为1,countyname为江夏区的要素,并返回其Id + queryParamsLayer.where = "countyname='江夏区'" + queryServiceByLayer.queryObjectIds(queryParamsLayer).then(function (data){ + console.log('查询单个图层') + console.log(JSON.parse(data)) + }) + //<-----------------------------查询整个地图-------------------------------> + //初始化要素编辑对象 + var queryServiceByMap = new Zondy.Service.ArcGisFeatureLayer({ + //要查询的图层url,记得发布地图时,勾选Feature Access + //此处url没有加layerId!!!,因此查询的是整个地图 + url: 'http://localhost:6080/arcgis/rest/services/wuhan_2/FeatureServer' + }); + //创建查询参数对象 + var queryParamsMap = queryServiceByLayer.createQuery(); + //查询layerId为1,countyname为江夏区的要素,并返回其Id + queryParamsMap.layerDefs = {"1":"countyname = '江夏区'"} + queryServiceByMap.queryObjectIds(queryParamsMap).then(function (data){ + console.log('查询整个地图') + console.log(JSON.parse(data)) + }) + */ +ArcGisFeatureLayer.prototype.queryObjectIds = function (query,options) { + query.returnIdsOnly = true; + return this[this._queryService](query); +} + +/** + * @function module:ArcGis.ArcGisFeatureLayer.prototype.queryExtent + * @description 要素查询,仅返回要素geometry数组 + * @author 基础平台-杨琨 + * @param query - {String} 必选项,查询参数。 + * @param options - {String} 可选项,是否取消异步操作。 + * @example 调用方法同queryObjectIds + */ +ArcGisFeatureLayer.prototype.queryExtent = function (query) { + query.returnExtentOnly = true; + return this[this._queryService](query); +} + +export {ArcGisFeatureLayer}; +Zondy.Service.ArcGisFeatureLayer = ArcGisFeatureLayer; \ No newline at end of file diff --git a/src/service/ArcGis/FindParameters.js b/src/service/ArcGis/FindParameters.js new file mode 100644 index 000000000..c76f28f41 --- /dev/null +++ b/src/service/ArcGis/FindParameters.js @@ -0,0 +1,30 @@ +import { + extend,Zondy +} from '../common'; +import {ArcGisBaseParam} from "./BaseParam"; + +/** + * @class module=ArcGis.ArcGisFindParameters + * @description find查询参数对象 + * @author 基础平台-杨琨 + */ +class ArcGisFindParameters extends ArcGisBaseParam{ + constructor(options) { + super(); + this.contains = true; + this.dynamicLayerInfos = null; + this.gdbVersion = null; + this.geometryPrecision = null; + this.layerDefinitions = null; + this.layerIds = null; + this.maxAllowableOffset = null; + this.outSpatialReference = null; + this.returnGeometry = true; + this.searchFields = null; + this.searchText = null; + extend(this,options); + } +} + +export {ArcGisFindParameters}; +Zondy.Service.ArcGisFindParameters = ArcGisFindParameters; \ No newline at end of file diff --git a/src/service/ArcGis/FindTask.js b/src/service/ArcGis/FindTask.js new file mode 100644 index 000000000..2b88bccd9 --- /dev/null +++ b/src/service/ArcGis/FindTask.js @@ -0,0 +1,75 @@ +import { + Zondy,extend,formatQuery +} from '../common'; +import {ArcGisServiceBase} from "./ServiceBase"; + +/** + * @class module:ArcGis.ArcGisFindTask + * @description find查询对象 + * @author 基础平台-杨琨 + * @param options - {Object} 必选项,初始化FindTask参数。 + * @param {String} [option.url] 必选项,地图服务url。 + * @param {String} [option.gdbVersion] 可选项,地理服务器版本。 + */ +class ArcGisFindTask{ + constructor(options){ + this.options = { + gdbVersion: null, + url: null + } + options.url = options.url + "/find?f=json"; + extend(this.options,options); + } +} + +/** + * @function module:ArcGis.ArcGisFindTask.prototype.execute + * @description 根据输入参数查询 + * @author 基础平台-杨琨 + * @param params - {Object} 必选项,查询参数。 + * @param {String} [params.searchText] 必选项,要查询的值,可不指定字段,在所有字段中查询。 + * @param {Boolean} [params.contains] 可选项,指定要查询的值是否大小写敏感,默认为true,查询值大小写敏感,可选值:true | false。 + * @param {Array} [params.layerIds] 必选项,要查询的图层Id数组,格式为:[layerId1,layerId2,layerId3,...]。 + * @param {Array} [params.searchFields] 可选项,要查询的字段名数组,格式为:[field1,field1,field1,...]。 + * @param {Boolean} [params.returnGeometry] 可选项,是否返回几何坐标集合,默认为true,返回几何坐标集合,可选值true | false。 + * @param {Number} [params.geometryPrecision] 可选项,指定返回的几何坐标集合的小数点位数,例如geometryPrecision=3,保留三位小数。 + * @param {Number} [params.maxAllowableOffset] 可选项,指定返回的几何坐标集合的最大偏移量,例如maxAllowableOffset=2。 + * @param {String} [params.outSpatialReference] 可选项,定义返回的几何坐标集合的空间坐标系,默认为地图坐标系。 + * @param {String} [params.gdbVersion] 可选项,定义地理数据库的版本号。 + * @example + * //初始化FindTask对象 + var FindTask = new Zondy.Service.ArcGisFindTask({ + url: 'http://localhost:6080/arcgis/rest/services/wuhan_2/MapServer' + }); + //初始化FindParameters查询参数对象 + var FindParameters = new Zondy.Service.ArcGisFindParameters({ + layerIds: [0], + searchText:'彩票销售店' + }); + //示例一:在图层0中,进行文本查询,对所有字段进行查询 + FindTask.execute(FindParameters).then(function (data) { + console.log("查询成功") + console.log(data) + }); + //示例二:在图层0和1中,对指定字段Name进行查询 + var FindParameters = new Zondy.Service.ArcGisFindParameters({ + layerIds: [0,1], + searchText:'滠口街道', + searchFields:['Name'], + }); + FindTask.execute(FindParameters).then(function (data) { + console.log("查询成功") + console.log(JSON.parse(data)) + }); + */ +ArcGisFindTask.prototype.execute = function (params, requestOptions) { + let url = this.options.url,formatObj = { + layerIds:"layers", + outSpatialReference:"sr" + },service = new ArcGisServiceBase(); + url = formatQuery(params,url,null,formatObj); + return service.getPromise(url); +} + +export {ArcGisFindTask}; +Zondy.Service.ArcGisFindTask = ArcGisFindTask; \ No newline at end of file diff --git a/src/service/ArcGis/Geometry.js b/src/service/ArcGis/Geometry.js new file mode 100644 index 000000000..96f5cb596 --- /dev/null +++ b/src/service/ArcGis/Geometry.js @@ -0,0 +1,34 @@ +import { + Zondy,extend +} from '../common'; +import {ArcGisBaseParam} from "./BaseParam"; +import {ArcGisSpatialReference} from "./SpatialReference"; + +/** + * @class module:ArcGis.ArcGisBaseParam + * @description ArcGis服务 + * @author 基础平台-杨琨 + */ + +class ArcGisGeometry extends ArcGisBaseParam{ + constructor(options) { + super(); + this.cache= {}; + this.extent= null; + this.hasM= false; + this.hasZ= false; + this.spatialReference = new ArcGisSpatialReference({ + wkid: 4326, + wkt: "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]]" + }); + this.type= null; + extend(this,options); + + if (options && options.hasOwnProperty("spatialReference")){ + options.spatialReference = new ArcGisSpatialReference(options.spatialReference); + } + } +} + +export {ArcGisGeometry}; +Zondy.Service.ArcGisGeometry = ArcGisGeometry; \ No newline at end of file diff --git a/src/service/ArcGis/Graphic.js b/src/service/ArcGis/Graphic.js new file mode 100644 index 000000000..62659ccb6 --- /dev/null +++ b/src/service/ArcGis/Graphic.js @@ -0,0 +1,65 @@ +import { + Zondy,extend +} from "../common"; +import {ArcGisBaseParam} from "./BaseParam"; + +/** + * @class module:ArcGis.ArcGisGraphic + * @description ArcGis服务 + * @author 基础平台-杨琨 + * @param options - {Object} 必选项,构造点对象参数。 + * @param {Object} [options.attributes] 必选项。要插入要素的字段值。 + * @param {Geometry} [options.geometry] 必选项。要插入的要素的几何坐标对象。 + */ + +class ArcGisGraphic extends ArcGisBaseParam{ + constructor(options) { + super(); + this.attributes = null; + this.geometry = null; + this.isAggregate = false; + this.layer = null; + this.popupTemplate = null; + this.symbol = null; + this.visible = true; + + extend(this,options); + } +} + +/** + * @function module:ArcGis.ArcGisGraphic.prototype.getAttribute + * @description 根据输入的字段名,查询attributes,返回所对应的值。 + * @param name - {String} 必选项,字段名。 + * @returns {String} 字段对应的值。 + */ +ArcGisGraphic.prototype.getAttribute = function (name){ + return this.attributes[name]; +} + +ArcGisGraphic.prototype.getEffectivePopupTemplate = function (defaultPopupTemplateEnabled){ + // return this.attributes[name]; +} + +/** + * @function module:ArcGis.ArcGisGraphic.prototype.getObjectId + * @description 返回objectId。 + * @returns {Number} objectId。 + */ +ArcGisGraphic.prototype.getObjectId = function (){ + return this.attributes["objectId"]; +} + +/** + * @function module:ArcGis.ArcGisGraphic.prototype.setAttribute + * @description 新增一个字段属性。 + * @param name - {String} 必选项,字段名。 + * @param newValue - {Object} 必选项,字段值。 + * @returns {String} 新加入的值。 + */ +ArcGisGraphic.prototype.setAttribute = function (name, newValue){ + return this.attributes[name] = newValue; +} + +export {ArcGisGraphic}; +Zondy.Service.ArcGisGraphic = ArcGisGraphic; \ No newline at end of file diff --git a/src/service/ArcGis/IdentifyParameters.js b/src/service/ArcGis/IdentifyParameters.js new file mode 100644 index 000000000..4baaaa4a2 --- /dev/null +++ b/src/service/ArcGis/IdentifyParameters.js @@ -0,0 +1,44 @@ +import { + extend,Zondy +} from '../common'; +import {ArcGisBaseParam} from "./BaseParam"; + +/** + * @class module=ArcGis.ArcGisIdentifyParameters + * @description find查询参数对象 + * @author 基础平台-杨琨 + */ +class ArcGisIdentifyParameters extends ArcGisBaseParam{ + constructor(options) { + super(); + this.dpi = 96; + this.dynamicLayerInfos = null; + this.gdbVersion = null; + this.geometry = null; + this.geometryPrecision = null; + this.height = 400; + this.layerDefinitions = null; + this.layerIds = null; + this.layerOption = "top"; + this.layerTimeOptions = null; + this.mapExtent = null; + this.maxAllowableOffset = null; + this.returnFieldName = !1; + this.returnGeometry = !1; + this.returnM = !1; + this.returnUnformattedValues = !1; + this.returnZ = !1; + this.spatialReference = null; + this.timeExtent = null; + this.tolerance = null; + this.width = 400; + extend(this,options); + + if(this.mapExtent){ + this.mapExtent = this.mapExtent.toString(); + } + } +} + +export {ArcGisIdentifyParameters}; +Zondy.Service.ArcGisIdentifyParameters = ArcGisIdentifyParameters; \ No newline at end of file diff --git a/src/service/ArcGis/IdentifyTask.js b/src/service/ArcGis/IdentifyTask.js new file mode 100644 index 000000000..819b22b7b --- /dev/null +++ b/src/service/ArcGis/IdentifyTask.js @@ -0,0 +1,77 @@ +import { + Zondy,extend,formatQuery +} from '../common'; +import {ArcGisServiceBase} from "./ServiceBase"; + +/** + * @class module:ArcGis.ArcGisIdentifyTask + * @description Identify查询对象 + * @author 基础平台-杨琨 + * @param options - {Object} 必选项,初始化IdentifyTask参数。 + * @param {String} [option.url] 必选项,地图服务url。 + * @param {String} [option.gdbVersion] 可选项,地理服务器版本。 + */ +class ArcGisIdentifyTask { + constructor(options) { + this.options = { + gdbVersion: null, + url: null + } + options.url = options.url + "/identify?f=json"; + extend(this.options,options); + } +} + +/** + * @function module:ArcGis.ArcGisIdentifyTask.prototype.execute + * @description 根据几何对象查询 + * @author 基础平台-杨琨 + * @param params - {Object} 必选项,查询参数。 + * @param requestOptions - {String} ke选项,查询参数。 + * @param {Geometry} [params.geometry] 必选项,几何查询条件。 + * @param {Number} [params.tolerance] 可选项,公差。 + * @param {String} [params.mapExtent] 必选项,地图范围,形式为mapExtent:“114.106,30.434,114.491,30.724”。 + * @param {Number} [params.width] 必选项,地图容器的的宽度。 + * @param {Number} [params.height] 必选项,地图容器的高度。 + * @param {Number} [params.dpi] 可选项,dpi值,默认为96。 + * @param {Array} [params.layerIds] 可选项,指定选择那些图层。 + * @param {String} [params.layerOption] 可选项,图层展示方式。 + * @param {Number} [params.geometryPrecision] 可选项,指定返回的几何对象的小数点位数。 + * @param {Number} [params.maxAllowableOffset] 可选项,最大偏移量。 + * @param {Boolean} [params.returnFieldName] 可选项,是否返回别名还是字段名。 + * @param {Boolean} [params.returnGeometry] 可选项,是否返回别几何坐标集合。 + * @param {Boolean} [params.returnM] 可选项,是否返回M值。 + * @param {Boolean} [params.returnUnformattedValues] 可选项,是否返回值是否格式化。 + * @param {Boolean} [params.returnZ] 可选项,是否返回Z值。 + * @param {String} [params.spatialReference] 可选项,指定空间坐标系。 + */ +ArcGisIdentifyTask.prototype.execute = function (params, requestOptions) { + let url = this.options.url, + formatObj = { + outSpatialReference:"sr" + }, + service = new ArcGisServiceBase(); + let trueParams = {}; + let type = params['geometry'].type; + let firstChar = type.substr(0,1).toUpperCase(); + let lastCher = type.substr(1,type.length); + params['geometryType'] = "esriGeometry" + firstChar + lastCher; + params['geometry'] = params['geometry'].toGeometryJSON(); + if(!trueParams['layers']){ + trueParams['layers'] = params['layerIds'] ? params['layerOption'] + ":" + String(params['layerIds']) : "layers=" + params['layerOption']; + delete params['layerOption']; + delete params['layerIds']; + } + if(!trueParams['imageDisplay']){ + trueParams['imageDisplay'] = params['width'] + "," + params['height'] + "," + params['dpi']; + delete params['width']; + delete params['height']; + delete params['dpi']; + } + extend(trueParams,params); + url = formatQuery(trueParams,url,null,formatObj); + return service.getPromise(url); +} + +export {ArcGisIdentifyTask}; +Zondy.Service.ArcGisIdentifyTask = ArcGisIdentifyTask; \ No newline at end of file diff --git a/src/service/ArcGis/Multipoint.js b/src/service/ArcGis/Multipoint.js new file mode 100644 index 000000000..92342c8c2 --- /dev/null +++ b/src/service/ArcGis/Multipoint.js @@ -0,0 +1,86 @@ +import { + Zondy,extend,cloneObject,returnPoint +} from "../common"; +import {ArcGisGeometry} from "./Geometry"; +import {ArcGisPoint} from "./Point"; + +/** + * @class module:ArcGis.ArcGisMultipoint + * @description ArcGis服务 + * @author 基础平台-杨琨 + * @param options - {Object} 必选项,构造点对象参数。 + * @param {String} [options.points] 可选项。点坐标数组, + * Example:[[x1,y1],[x2,y2]]。 + * @param {ArcGisSpatialReference} [options.spatialReference] 可选项。多边形的空间坐标系,默认4326。 + */ +class ArcGisMultipoint extends ArcGisGeometry{ + constructor(options) { + super(options); + this.points = []; + this.type = "multipoint"; + extend(this,options); + } +} + +/** + * @function module:ArcGis.ArcGisMultipoint.prototype.addPoint + * @description 添加点坐标,可以为[x,y]坐标或者ArcGisPoint对象 + * @param point - {ArcGisPoint} 必选项,要查询的多边形序号,可为点坐标数组或者坐标或者ArcGisPoint对象数组。 + */ +ArcGisMultipoint.prototype.addPoint = function (point){ + if(point instanceof Array){ + this.points.push(point); + }else if(point instanceof ArcGisPoint){ + this.points.push([point.x,point.y]); + } +} + +/** + * @function module:ArcGis.ArcGisMultipoint.prototype.getPoint + * @description 根据index返回ArcGisPoint对象 + * @param index - {Number} 必选项,要查询的点序号。 + * @returns ArcGisPoint,点对象 + */ +ArcGisMultipoint.prototype.getPoint = function (index){ + return returnPoint(ArcGisPoint,this,this.points[index]); +} + +/** + * @function module:ArcGis.ArcGisMultipoint.prototype.removePoint + * @description 根据index删除一个ArcGisPoint对象 + * @param index - {Number} 必选项,要查询的点序号。 + * @returns ArcGisPoint,点对象 + */ +ArcGisMultipoint.prototype.removePoint = function (index){ + let positionArr = this.points.splice(index,1); + return returnPoint(ArcGisPoint,this,positionArr); +} + +/** + * @function module:ArcGis.ArcGisMultipoint.prototype.setPoint + * @description 根据index,更新一个点对象 + * @param index - {Number} 必选项,在pointIndex处,更新这个点。 + * @returns ArcGisMultipoint,线对象 + */ +ArcGisMultipoint.prototype.setPoint = function (index,point){ + if(index >= this.points.length) + return null; + if(point instanceof Array){ + this.points[index] = [point[0],point[1]]; + }else if(point instanceof ArcGisPoint){ + this.points[index] = [point.x,point.y]; + } + return this; +} + +/** + * @function module:ArcGis.ArcGisMultipoint.prototype.toGeometryJSON + * @description 将点坐标转换为Json对象 + * @returns String + */ +ArcGisMultipoint.prototype.toGeometryJSON = function () { + return '{"points":[[' + this.points.join("],[") + ']]}'; +} + +export {ArcGisMultipoint}; +Zondy.Service.ArcGisMultipoint = ArcGisMultipoint; \ No newline at end of file diff --git a/src/service/ArcGis/Point.js b/src/service/ArcGis/Point.js new file mode 100644 index 000000000..1fc6519fb --- /dev/null +++ b/src/service/ArcGis/Point.js @@ -0,0 +1,153 @@ +import { + Zondy,extend +} from "../common"; +import {ArcGisGeometry} from "./Geometry"; +import proj4 from "proj4"; +import {ArcGisSpatialReference} from "./SpatialReference"; + +/** + * @class module:ArcGis.ArcGisPoint + * @description 生成Point对象 + * @author 基础平台-杨琨 + * @param options - {Object} 必选项,构造点对象参数。 + * @param {String} [options.latitude] 可选项。纬度。 + * @param {String} [options.longitude] 可选项。经度。 + * @param {String} [options.m] 可选项。m值。 + * @param {String} [options.x] 可选项。x值,单位米。 + * @param {String} [options.y] 可选项。y值,单位米。 + * @param {String} [options.z] 可选项。z值,单位米。 + */ +class ArcGisPoint extends ArcGisGeometry{ + constructor(options) { + super(); + this.hasM = false; + this.hasZ = false; + this.latitude = 0; + this.longitude = 0; + this.m = undefined; + this.x = 0; + this.y = 0; + this.z = undefined; + this.type = "point"; + + //保留原始坐标系 + let originalSR = this.spatialReference.wkid; + + extend(this,options); + + //options存才要做的处理 + if(options){ + if(!options.hasOwnProperty("spatialReference") + || (options.hasOwnProperty("spatialReference") && options.spatialReference.hasOwnProperty("wkid") && options.spatialReference.wkid === 4326)){ + //如果options里面的经纬度或者xy值没有,则为undefined + let me = this; + ["longitude","latitude","x","y"].forEach(function (key) { + if(!options.hasOwnProperty(key)) me[key] = undefined; + }) + + //如果x或y存在,增强行将xy的值传给经纬度 + if(options.hasOwnProperty("x"))this.longitude = this.x; + if(options.hasOwnProperty("y"))this.latitude = this.y; + if(!options.hasOwnProperty("x") && options.hasOwnProperty("longitude")) this.x = this.longitude; + if(!options.hasOwnProperty("y") && options.hasOwnProperty("latitude")) this.y = this.latitude; + }else if(options.hasOwnProperty("spatialReference") && options.spatialReference.hasOwnProperty("wkid") + && options.spatialReference.wkid === 3857){ + if(options.hasOwnProperty("longitude") && options.hasOwnProperty("latitude")){ + P(originalSR,"3857",[this.longitude,this.latitude],"x","y",this,options); + }else if(options.hasOwnProperty("x") && options.hasOwnProperty("y")){ + P("3857",originalSR,[this.x,this.y],"longitude","latitude",this,options); + }else { + if(!options.hasOwnProperty("x")){ + if(options.hasOwnProperty("longitude")) this.x = this.longitude; + if(!options.hasOwnProperty("longitude")) this.x = this.longitude = undefined; + } + if(!options.hasOwnProperty("y")){ + if(options.hasOwnProperty("latitude")) this.y = this.latitude; + if(!options.hasOwnProperty("latitude")) this.y = this.latitude = undefined; + } + P("3857",originalSR,[this.x,this.y],"longitude","latitude",this,options); + } + } + }else { + this.x = this.y = this.latitude = this.longitude = undefined; + } + + //只有m值存在,hasM才为true否则为false + this.hasM = !!this.m; + + //只有z值存在,hasZ才为true否则为false + this.hasZ = !!this.z; + } +} + +/** + * @function module:ArcGis.ArcGisPoint.prototype.toArray + * @description 返回[x,y]坐标数组,如果有z值,则返回[x,y,z] + * @author 基础平台-杨琨 + * @returns [x,y,z]坐标数组 + */ +ArcGisPoint.prototype.toArray = function () { + let position = []; + position.push(this.x); + position.push(this.y); + if(this.z) + position.push(this.z); + return position; +} + +/** + * @function module:ArcGis.ArcGisPoint.prototype.copy + * @description 复制point的所有值,并覆盖当前对象 + * @author 基础平台-杨琨 + * @param point - {ArcGisPoint} 必选项,查询参数。 + */ +ArcGisPoint.prototype.copy = function (point){ + extend(this,point); +} + +/** + * @function module:ArcGis.ArcGisPoint.prototype.distance + * @description 根据两个point的x、y、z值,算出两点的距离 + * @author 基础平台-杨琨 + * @param point - {ArcGisPoint} 必选项,查询参数。 + * @returns Number,两点距离 + */ +ArcGisPoint.prototype.distance = function (point){ + let width = Math.abs(this.x - point.x), + height = Math.abs(this.y - point.y), + zLength = 0; + if(this.hasZ && point.hasZ) zLength = Math.abs(this.z - point.z); + return Math.sqrt(Math.pow(width,2) + Math.pow(height,2) + Math.pow(zLength,2)); +} + +/** + * @function module:ArcGis.ArcGisPoint.prototype.equals + * @description 判断两个点是否相等,判断条件为x、y、z、m以及坐标系都相等 + * @author 基础平台-杨琨 + * @param point - {ArcGisPoint} 必选项,查询参数。 + * @returns Boolean,是否相等 + */ +ArcGisPoint.prototype.equals = function (point){ + return this.x === point.x && this.y === point.y && this.z === point.z && this.m === point.m + && this.spatialRefere.equals(point.spatialRefere) +} + +/** + * @function module:ArcGis.ArcGisPoint.prototype.toGeometryJSON + * @description 将坐标转为特定格式,供IdentifyTask使用 + * @author 基础平台-杨琨 + * @returns String,包含点坐标的JSON字符串 + */ +ArcGisPoint.prototype.toGeometryJSON = function () { + return '{"x":' + this.x + ',"y":' + this.y + '}'; +} +//转换坐标系 +function P(fromSR,toST,point,xName,yName,me,options) { + let arr = proj4("EPSG:" + fromSR, "EPSG:" + toST, [point[0], point[1]]); + me[xName] = isNaN(arr[0]) ? undefined : arr[0]; + me[yName] = isNaN(arr[1]) ? undefined : arr[1]; + me.spatialReference = new ArcGisSpatialReference(options.spatialReference); +} + +export {ArcGisPoint}; +Zondy.Service.ArcGisPoint = ArcGisPoint; \ No newline at end of file diff --git a/src/service/ArcGis/Polygon.js b/src/service/ArcGis/Polygon.js new file mode 100644 index 000000000..f060864a4 --- /dev/null +++ b/src/service/ArcGis/Polygon.js @@ -0,0 +1,214 @@ +import { + Zondy, extend, returnPoint,formatPoints +} from "../common"; +import {ArcGisGeometry} from "./Geometry"; +import {ArcGisPoint} from "./Point"; +import * as T from '@turf/turf' +import * as H from '@turf/helpers' + +/** + * @class module:ArcGis.ArcGisPolygon + * @description ArcGis服务 + * @author 基础平台-杨琨 + * @param options - {Object} 必选项,构造点对象参数。 + * @param {String} [options.rings] 可选项。构成多边形的点坐标,坐标必须闭合,可有多个矩形。 + * Example:rings:[[[x1,y1],[x2,y2],[x3,y3],[x1,y1]],[[x4,y4],[x5,y5],[x6,y6],[x4,y4]]] + * @param {ArcGisSpatialReference} [options.spatialReference] 可选项。多边形的空间坐标系,默认4326。 + */ +class ArcGisPolygon extends ArcGisGeometry{ + constructor(options) { + super(options); + this.centroid = null; + this.isSelfIntersecting = false; + this.rings = []; + this.type = "polygon"; + + extend(this,options); + + if(this.rings[0] && this.rings[0][0]){ + if(this.rings[0][0].length >= 3){ + this.hasZ = true; + } + } + } +} + +/** + * @function module:ArcGis.ArcGisPolygon.prototype.getPoint + * @description 根据ringIndex、pointIndex返回点对象 + * @param ringIndex - {Number} 必选项,要查询的多边形序号。 + * @param pointIndex - {Number} 必选项,要查询的点序号。 + * @returns ArcGisPoint,点对象 + */ +ArcGisPolygon.prototype.getPoint = function (ringIndex, pointIndex){ + if(ringIndex >= this.rings.length || pointIndex >= this.rings[ringIndex].length) + return null; + return returnPoint(ArcGisPoint,this,this.rings[ringIndex][pointIndex]); +} + +/** + * @function module:ArcGis.ArcGisPolygon.prototype.insertPoint + * @description 根据ringIndex、pointIndex,在pointIndex之后插入一个点对象 + * @param ringIndex - {Number} 必选项,要插入的多边形序号。 + * @param pointIndex - {Number} 必选项,在第pointIndex之后插入一个点,线标从0开始。 + * @param point - {Number} 必选项,要要插入的点对象。 + * @returns ArcGisPolygon,多边形对象 + */ +ArcGisPolygon.prototype.insertPoint = function (ringIndex, pointIndex, point){ + if(ringIndex < this.rings.length && pointIndex <= this.rings[ringIndex].length) { + if(point instanceof Array){ + this.rings[ringIndex].splice(pointIndex,0,point); + }else if(point instanceof ArcGisPoint){ + this.rings[ringIndex].splice(pointIndex,0,point.hasZ ? [point.x,point.y,point.z] : [point.x,point.y]); + } + } + return this; +} + +/** + * @function module:ArcGis.ArcGisPolygon.prototype.removePoint + * @description 根据ringIndex、pointIndex删除一个点,并返回该点对象 + * @param ringIndex - {Number} 必选项,要删除的点所在的多边形序号。 + * @param pointIndex - {Number} 必选项,在pointIndex处,删除这个点。 + * @returns ArcGisPoint,点对象 + */ +ArcGisPolygon.prototype.removePoint = function (ringIndex, pointIndex){ + if(ringIndex >= this.rings.length || pointIndex >= this.rings[ringIndex].length) + return null; + let positionArr = this.rings[ringIndex].splice(pointIndex,1)[0]; + return returnPoint(ArcGisPoint,this,positionArr); +} + +/** + * @function module:ArcGis.ArcGisPolygon.prototype.setPoint + * @description 根据ringIndex、pointIndex,更新一个点对象 + * @param ringIndex - {Number} 必选项,要更新的点所在的多边形序号。 + * @param pointIndex - {Number} 必选项,在pointIndex处,更新这个点。 + * @param point - {ArcGisPoint} 必选项,ArcGisPoint对象或者[x,y]或[x,y,z]数组,要更新的点。 + * @returns ArcGisPolygon,多边形对象 + */ +ArcGisPolygon.prototype.setPoint = function (ringIndex, pointIndex, point){ + if(ringIndex >= this.rings.length || pointIndex >= this.rings[ringIndex].length) + return null; + if(point instanceof Array){ + this.rings[ringIndex][pointIndex] = point; + }else if(point instanceof ArcGisPoint){ + let pointArr = [point.x,point.y]; + if(point.hasZ){ + pointArr.push(point.z); + }if(point.hasM){ + pointArr.push(point.m); + } + this.rings[ringIndex][pointIndex] = pointArr; + } + return this; +} + +/** + * @function module:ArcGis.ArcGisPolygon.prototype.addRing + * @description 根据ringIndex、pointIndex,更新一个多边形对象 + * @param points - {Array} 必选项,要插入的一组多边形点坐标数组, + * example:[[x1,y1],[x2,y2],[x3,y3],[x1,y1]]。 + * @returns ArcGisPolygon,多边形对象 + */ +ArcGisPolygon.prototype.addRing = function (points){ + if(points instanceof Array){ + this.rings.push(formatPoints(points)); + }else { + this.rings.push([]); + } + return this; +} + +/** + * @function module:ArcGis.ArcGisPolygon.prototype.removeRing + * @description 根据index,删除一个多边形点坐标数组 + * @param index - {Array} 必选项,要删除的多边形序号。 + * @returns [ArcGisPoint],被删除的多边形点对象数组 + */ +ArcGisPolygon.prototype.removeRing = function (index){ + if(index >= this.rings.length) return null; + let path = this.rings.splice(index,1)[0],point,pointArr = []; + for(let i = 0;i < path.length;i++){ + point = returnPoint(ArcGisPoint,this,path[i]); + pointArr.push(point); + } + return pointArr +} + +/** + * @function module:ArcGis.ArcGisPolygon.prototype.isClockwise + * @description 判断是否是顺时针。 + * @param ring - {Array} 必选项,[ArcGisPoint]或[[x,y,z]]或[x,y],输入值必须是一组点坐标或对象数组(就是一条线,封闭线就是多边形),不能是多维数组。 + * @returns {boolean} 是否是顺时针。 + */ +ArcGisPolygon.prototype.isClockwise = function (ring){ + let sum = 0,i = 1, + hasZ = false,//是否有值 + prev,//上一个点 + cur;//当前点 + hasZ = !!ring[0][2]; + while (i < ring.length) { + //第一次将ring[0]给prev,之后都是cur + prev = cur || ring[0]; + cur = ring[i]; + //根据两组坐标(x1 - x1) * (y1 + y0) * (z1 + z0)的值累计相加,最后的值大于0则是顺实战,否则逆时针 + sum += hasZ ? (cur[0] - prev[0]) * (cur[1] + prev[1]) * (cur[2] + prev[2]) + : (cur[0] - prev[0]) * (cur[1] + prev[1]); + i++; + } + return sum > 0; +} + +/** + * @function module:ArcGis.ArcGisPolygon.prototype.contains + * @description 判断多边形是否包含一个点。 + * @param point - {ArcGisPoint} 必选项,要检测的点对象。 + * @returns {boolean} 多边形是否包含点。 + */ +ArcGisPolygon.prototype.contains = function (point){ + if(point instanceof ArcGisPoint){ + let g = H.polygon(this.rings,{name:"_extentPlygon"}); + let p = H.point(point.toArray()); + return T.booleanContains(g,p); + }else { + return false; + } +} + +/** + * @function module:ArcGis.ArcGisPolygon.prototype.toGeometryJSON + * @description 将点坐标转换为Json对象 + * @returns String + */ +ArcGisPolygon.prototype.toGeometryJSON = function () { + let rings = this.rings; + let geometryStr = '{"rings":['; + for(let i = 0;i < rings.length;i++){ + geometryStr += "["; + for(let j = 0;j < rings[i].length;j++){ + geometryStr += "["; + geometryStr += rings[i][j].join(','); + geometryStr += "],"; + } + geometryStr = geometryStr.substr(0,geometryStr.length - 1); + geometryStr += "],"; + } + geometryStr = geometryStr.substr(0,geometryStr.length - 1); + geometryStr += ']}'; + return geometryStr; +} + +/** + * @function module:ArcGis.ArcGisPolygon.prototype.fromExtent + * @description 输入一个Extent对象返回一个多边形对象 + * @param Extent - {ArcGisExtent} 必选项,要输入的ArcGisExtent对象。 + * @returns {ArcGisPolygon} 新的多边形对象。 + */ +ArcGisPolygon.prototype.fromExtent = function (Extent) { + return new ArcGisPolygon({ + rings:Extent._extentPolygon.geometry.coordinates + }); +} +export {ArcGisPolygon}; +Zondy.Service.ArcGisPolygon = ArcGisPolygon; \ No newline at end of file diff --git a/src/service/ArcGis/Polyline.js b/src/service/ArcGis/Polyline.js new file mode 100644 index 000000000..859318190 --- /dev/null +++ b/src/service/ArcGis/Polyline.js @@ -0,0 +1,153 @@ +import { + Zondy, extend, returnPoint,formatPoints +} from "../common"; +import {ArcGisGeometry} from "./Geometry"; +import {ArcGisPoint} from "./Point"; +/** + * @class module:ArcGis.ArcGisPolyline + * @description ArcGis服务 + * @author 基础平台-杨琨 + * @param options - {Object} 必选项,构造点对象参数。 + * @param {String} [options.paths] 可选项。构成线的点坐标,可有多条。 + * Example: [[[x1,y1],[x2,y2],[x3,y3]],[[x4,y4],[x5,y5],[x6,y6]]] + * @param {ArcGisSpatialReference} [options.spatialReference] 可选项。多边形的空间坐标系,默认4326。 + */ +class ArcGisPolyline extends ArcGisGeometry{ + constructor(options) { + super(options); + this.paths = []; + this.type = "polyline"; + + extend(this,options); + } +} + +/** + * @function module:ArcGis.ArcGisPolyline.prototype.getPoint + * @description 根据pathIndex和pointIndex返回ArcGisPoint对象 + * @param pathIndex - {Number} 必选项,要查询的多边形序号。 + * @param pointIndex - {Number} 必选项,要查询的点序号。 + * @returns ArcGisPoint,点对象 + */ +ArcGisPolyline.prototype.getPoint = function (pathIndex,pointIndex){ + if(pathIndex >= this.paths.length || pointIndex >= this.paths[pathIndex].length) + return null; + return returnPoint(ArcGisPoint,this,this.paths[pathIndex][pointIndex]); +} + +/** + * @function module:ArcGis.ArcGisPolyline.prototype.removePoint + * @description 根据ringIndex、pointIndex删除一个点,并返回该点对象 + * @param pathIndex - {Number} 必选项,要删除的点所在的多边形序号。 + * @param pointIndex - {Number} 必选项,在pointIndex处,删除这个点。 + * @returns ArcGisPoint,点对象 + */ +ArcGisPolyline.prototype.removePoint = function (pathIndex,pointIndex){ + if(pathIndex >= this.paths.length || pointIndex >= this.paths[pathIndex].length) + return null; + let positionArr = this.paths[pathIndex].splice(pointIndex,1)[0]; + return returnPoint(ArcGisPoint,this,positionArr); +} + +/** + * @function module:ArcGis.ArcGisPolyline.prototype.setPoint + * @description 根据ringIndex、pointIndex,更新一个点对象 + * @param pathIndex - {Number} 必选项,要删除的点所在的多边形序号。 + * @param pointIndex - {Number} 必选项,在pointIndex处,删除这个点。 + * @param point - {ArcGisPoint} 必选项,ArcGisPoint对象或者[x,y]或[x,y,z]数组,要更新的点。 + * @returns ArcGisPolyline,线对象 + */ +ArcGisPolyline.prototype.setPoint = function (pathIndex, pointIndex, point){ + if(pathIndex >= this.paths.length || pointIndex >= this.paths[pathIndex].length) + return null; + if(point instanceof Array){ + this.paths[pathIndex][pointIndex] = point; + }else if(point instanceof ArcGisPoint){ + let pointArr = [point.x,point.y]; + if(point.hasZ){ + pointArr.push(point.z); + }if(point.hasM){ + pointArr.push(point.m); + } + this.paths[pathIndex][pointIndex] = pointArr; + } + return this; +} + +/** + * @function module:ArcGis.ArcGisPolyline.prototype.addRing + * @description 传入坐标数组或者[ArcGisPoint]数组,新增一条线 + * @param points - {Array} 必选项,要插入的一组多边形点坐标数组, + * example:[[x1,y1],[x2,y2],[x3,y3]]。 + * @returns ArcGisPolyline,线对象 + */ +ArcGisPolyline.prototype.addPath = function (points){ + if(points instanceof Array){ + this.paths.push(formatPoints(points)); + }else { + this.paths.push([]); + } + return this; +} + +/** + * @function module:ArcGis.ArcGisPolyline.prototype.removeRing + * @description 根据index删除一条线,并返回点对象数组 + * @param index - {Array} 必选项,要删除的多边形序号。 + * @returns [ArcGisPoint],被删除的线的点对象数组 + */ +ArcGisPolyline.prototype.removePath = function (index){ + if(index >= this.path.length) return null; + let path = this.paths.splice(index,1)[0],point,pointArr = []; + for(let i = 0;i < path.length;i++){ + point = returnPoint(ArcGisPoint,this,path[i]); + pointArr.push(point); + } + return pointArr +} + +/** + * @function module:ArcGis.ArcGisPolyline.prototype.insertPoint + * @description 根据ringIndex、pointIndex,在pointIndex之后插入一个点对象 + * @param pathIndex - {Number} 必选项,要插入的多边形序号。 + * @param pointIndex - {Number} 必选项,在第pointIndex之后插入一个点,线标从0开始。 + * @param point - {Number} 必选项,要要插入的点对象。 + * @returns ArcGisPolyline,线对象 + */ +ArcGisPolyline.prototype.insertPoint = function (pathIndex, pointIndex, point){ + if(pathIndex < this.paths.length && pointIndex <= this.paths[pathIndex].length) { + if(point instanceof Array){ + this.paths[pathIndex].splice(pointIndex,0,point); + }else if(point instanceof ArcGisPoint){ + this.paths[pathIndex].splice(pointIndex,0,point.hasZ ? [point.x,point.y,point.z] : [point.x,point.y]); + } + } + + return this; +} + +/** + * @function module:ArcGis.ArcGisPolyline.prototype.toGeometryJSON + * @description 将点坐标转换为Json对象 + * @returns String + */ +ArcGisPolyline.prototype.toGeometryJSON = function () { + let paths = this.paths; + let geometryStr = '{"paths":['; + for(let i = 0;i < paths.length;i++){ + geometryStr += "["; + for(let j = 0;j < paths[i].length;j++){ + geometryStr += "["; + geometryStr += paths[i][j].join(','); + geometryStr += "],"; + } + geometryStr = geometryStr.substr(0,geometryStr.length - 1); + geometryStr += "],"; + } + geometryStr = geometryStr.substr(0,geometryStr.length - 1); + geometryStr += ']}'; + return geometryStr; +} + +export {ArcGisPolyline}; +Zondy.Service.ArcGisPolyline = ArcGisPolyline; \ No newline at end of file diff --git a/src/service/ArcGis/Query.js b/src/service/ArcGis/Query.js new file mode 100644 index 000000000..dd65ef93b --- /dev/null +++ b/src/service/ArcGis/Query.js @@ -0,0 +1,58 @@ +import { + extend,Zondy +} from '../common'; +import {ArcGisBaseParam} from "./BaseParam"; + +/** + * @class module:ArcGis.ArcGisQuery + * @description ArcGis服务 + * @author 基础平台-杨琨 + */ +class ArcGisQuery extends ArcGisBaseParam{ + constructor(options) { + super(); + this.aggregateIds = null; + this.cacheHint = null; + this.datumTransformation = null; + this.distance = null; + this.gdbVersion = null; + this.geometry = null; + this.geometryPrecision = null; + this.groupByFieldsForStatistics = null; + this.having = null; + this.historicMoment = null; + this.maxAllowableOffset = null; + this.maxRecordCountFactor = 1; + this.multipatchOption = null; + this.num = null; + this.objectIds = null; + this.orderByFields = null; + this.outFields = null; + this.outSpatialReference = null; + this.outStatistics = null; + this.parameterValues = null; + this.pixelSize = null; + this.quantizationParameters = null; + this.rangeValues = null; + this.relationParameter = null; + this.returnCentroid = false; + this.returnDistinctValues = false; + this.returnExceededLimitFeatures = true; + this.returnGeometry = false; + this.returnM = null; + this.returnQueryGeometry = true; + this.returnZ = null; + this.spatialRelationship = "intersects"; + this.sqlFormat = null; + this.start = null; + this.text = null; + this.timeExtent = null; + this.units = null; + this.where = null; + + extend(this,options); + } +} + +export {ArcGisQuery}; +Zondy.Service.ArcGisQuery = ArcGisQuery; \ No newline at end of file diff --git a/src/service/ArcGis/QueryTask.js b/src/service/ArcGis/QueryTask.js new file mode 100644 index 000000000..6a7db4785 --- /dev/null +++ b/src/service/ArcGis/QueryTask.js @@ -0,0 +1,24 @@ +import {Zondy} from '../common/Base'; +import { + getPromise,getPromiseP,formatQuery,formatEdits,extend +} from '../common'; + +class ArcGisQueryTask { + constructor(options) { + this.options = { + url: null, + gdbVersion: null + } + extend(this.options,options); + } +} + +ArcGisQueryTask.prototype.execute = function (query, requestOptions) {} +ArcGisQueryTask.prototype.executeAttachmentQuery = function () {} +ArcGisQueryTask.prototype.executeForCount = function () {} +ArcGisQueryTask.prototype.executeForExtent = function () {} +ArcGisQueryTask.prototype.executeForIds = function () {} +ArcGisQueryTask.prototype.executeRelationshipQuery = function () {} + +export {ArcGisQueryTask}; +Zondy.Service.ArcGisQueryTask = ArcGisQueryTask; \ No newline at end of file diff --git a/src/service/ArcGis/ServiceBase.js b/src/service/ArcGis/ServiceBase.js new file mode 100644 index 000000000..c95a6f836 --- /dev/null +++ b/src/service/ArcGis/ServiceBase.js @@ -0,0 +1,77 @@ +import {Zondy,extend} from "../common"; + +var queryExtraOarams = { + displayFieldName:null, + geometryType:null, + hasM:false, + hasZ:false, + queryGeometry:null, + spatialReference:null, + transform:null +}; + +/** + * @class module:ArcGis.ArcGisServiceBase + * @description ArcGis服务 + * @author 基础平台-杨琨 + */ +class ArcGisServiceBase { + getPromise(url) { + let me = this; + return new Promise(function (resolve,reject) { + me.get(url,function (data) { + data = JSON.parse(data); + if(url.indexOf("FeatureServer") > -1 && url.indexOf("query") > -1){ + data = extend(data,queryExtraOarams); + } + resolve(data); + },function (data) { + reject(JSON.parse(data)); + }) + }); + } + + getPromiseP(url,dataStr) { + let me = this; + return new Promise(function (resolve,reject) { + me.post(url,dataStr,function (data) { + resolve(JSON.parse(data)); + },function (data) { + reject(JSON.parse(data)); + }); + }); + } + + get(url, fn,error) { + // XMLHttpRequest对象用于在后台与服务器交换数据 + var xhr = new XMLHttpRequest(); + xhr.open('GET', url, true); + xhr.onreadystatechange = function() { + // readyState == 4说明请求已完成 + if (xhr.readyState == 4 && xhr.status == 200 || xhr.status == 304) { + // 从服务器获得数据 + fn.call(this, xhr.responseText); + }else if(xhr.readyState === 4 && xhr.status !== 200 && xhr.status !== 304 ) { + error.call(this, xhr.responseText); + } + }; + xhr.send(); + } + // datat应为'a=a1&b=b1'这种字符串格式,在jq里如果data为对象会自动将对象转成这种字符串格式 + post(url, data, fn,error) { + var xhr = new XMLHttpRequest(); + xhr.open("POST", url, true); + // 添加http头,发送信息至服务器时内容编码类型 + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.onreadystatechange = function(data) { + if (xhr.readyState === 4 && (xhr.status === 200 || xhr.status === 304)) { + fn.call(this, xhr.responseText); + }else if(xhr.readyState === 4 && xhr.status !== 200 && xhr.status !== 304 ) { + error.call(this, xhr.responseText); + } + }; + xhr.send(data); + } +} +export {ArcGisServiceBase}; +Zondy.Service.ArcGisServiceBase = ArcGisServiceBase; \ No newline at end of file diff --git a/src/service/ArcGis/SpatialReference.js b/src/service/ArcGis/SpatialReference.js new file mode 100644 index 000000000..86cc61b3d --- /dev/null +++ b/src/service/ArcGis/SpatialReference.js @@ -0,0 +1,54 @@ +import { + Zondy,extend +} from "../common"; +import {ArcGisBaseParam} from "./BaseParam"; + +/** + * @class module:ArcGis.ArcGisSpatialReference + * @description ArcGis服务 + * @author 基础平台-杨琨 + * @param options - {Object} 必选项,构造点对象参数。 + * @param {Number} [options.wkid] 可选项。空间坐标系编号。如:4326、3857。 + * @param {String} [options.wkt] 可选项。空间坐标系的描述信息。 + */ +class ArcGisSpatialReference extends ArcGisBaseParam{ + constructor(options) { + super(); + this.imageCoordinateSystem = null; + this.isGeographic = false; + this.isWebMercator = false; + this.isWGS84 = false; + this.isWrappable = false; + this.WebMercator = null; + this.WGS84 = null; + this.latestVcsWkid = null; + this.latestWkid = null; + this.vcsWkid = null; + this.wkid = undefined; + this.wkt = null; + + extend(this,options); + + if(this.wkid === 3857){ + this.isWebMercator = true; + this.isWrappable = true; + }else if(this.wkid === 4326){ + this.sGeographic = true; + this.isWGS84 = true; + this.isWrappable = true; + } + } +} + +/** + * @function module:ArcGis.ArcGisSpatialReference.prototype.equals + * @description 比较两个空间坐标系对象是否相等,如果wkid和wkt相等,怎犯规true。 + * @param sr - {ArcGisSpatialReference} 必选项,要比较的ArcGisSpatialReference对象。 + * @returns {boolean} 是否相等。 + */ +ArcGisSpatialReference.prototype.equals = function (sr) { + return sr.wkid === this.wkid || sr.wkt === this.wkt; +} + +export {ArcGisSpatialReference}; +Zondy.Service.ArcGisSpatialReference = ArcGisSpatialReference; \ No newline at end of file diff --git a/src/service/ArcGis/index.js b/src/service/ArcGis/index.js new file mode 100644 index 000000000..8732a18b3 --- /dev/null +++ b/src/service/ArcGis/index.js @@ -0,0 +1,34 @@ +/** + *@module ArcGis + */ + +import { ArcGisFeatureLayer } from './FeatureLayer'; +import { ArcGisFindParameters } from './FindParameters'; +import { ArcGisFindTask } from './FindTask'; +import { ArcGisIdentifyTask } from './IdentifyTask'; +import { ArcGisIdentifyParameters } from './IdentifyParameters'; +import { ArcGisGeometry } from './Geometry'; +import { ArcGisQuery } from './Query'; +import { ArcGisQueryTask } from './QueryTask'; +import { ArcGisPolygon } from './Polygon'; +import { ArcGisPoint } from './Point'; +import { ArcGisMultipoint } from './Multipoint'; +import { ArcGisPolyline } from './Polyline'; +import { ArcGisGraphic } from './Graphic'; +import { ArcGisExtent } from './Extent'; + +export { + ArcGisFeatureLayer, + ArcGisFindParameters, + ArcGisFindTask,ArcGisIdentifyTask, + ArcGisIdentifyParameters, + ArcGisGeometry, + ArcGisQuery, + ArcGisQueryTask, + ArcGisPoint, + ArcGisMultipoint, + ArcGisPolyline, + ArcGisPolygon, + ArcGisGraphic, + ArcGisExtent +}; diff --git a/src/service/common/PolyLine.js b/src/service/common/PolyLine.js index d086975b4..84dadb58b 100644 --- a/src/service/common/PolyLine.js +++ b/src/service/common/PolyLine.js @@ -70,8 +70,6 @@ class PolyLine extends Tangram { if (this.nearDis !== undefined && this.nearDis !== null) { str += ";" + this.nearDis; - } else { - str = str.substring(0, str.length - 1); } return this.Trim(str, "g"); } diff --git a/src/service/common/Util.js b/src/service/common/Util.js index 1c3f4ba21..7811f6795 100644 --- a/src/service/common/Util.js +++ b/src/service/common/Util.js @@ -1020,6 +1020,135 @@ var createCanvasContext2D = function (opt_width, opt_height) { return canvas.getContext('2d'); }; +/* + * APIMethod: formatQuery + * 转换参数对象为url字符串 + * + * Parameters: + * query - {Object} 要转换的参数对象。 + * url - {String} url字符串。 + * paramArr - {Array} 要转化为json字符串的参数。 + * formatObj - {Object} 要改名的参数对象 + * + * Returns: + * url - {String} url字符串。 + */ +var formatQuery = function (query,url,paramArr,formatObj) { + Object.keys(query).forEach(function (key) { + let param = query[key],keyStr = key; + //拼接url参数,param不能为空或者function + if(notNULL(param) && typeof(param) !== 'function'){ + //当参数为geometry时,要转换格式 + if(paramArr && paramArr.indexOf(key) > -1){ + let geometry = {}; + if(key === "geometry"){ + if(param.type === "polygon"){ + geometry["rings"] = query[key]["rings"]; + } + if(param.type === "multipoint"){ + geometry["points"] = query[key]["points"]; + } + if(param.type === "point"){ + if(query[key]["x"] && query[key]["y"]){ + geometry["y"] = query[key]["y"]; + geometry["x"] = query[key]["x"]; + } + } + if(param.type === "polyline"){ + geometry["paths"] = query[key]["paths"]; + } + geometry["spatialReference"] = query[key]["spatialReference"]; + param = geometry; + url += "&geometryType=esriGeometry" + query[key]["type"].charAt(0).toUpperCase() + query[key]["type"].slice(1); + } + param = JSON.stringify(param); + } + if(formatObj && formatObj.hasOwnProperty(key)){ + keyStr = formatObj[key]; + } + url += "&" + keyStr + "=" + param; + } + }); + return url; +} + +/* + * APIMethod: formatEdits + * 转换参数对象为url字符串 + * + * Parameters: + * params - {Object} 要转换的参数对象。 + * dataStr - {String} url字符串。 + * editArr - {Array} 要转化名字的方法。 + * + * Returns: + * dataStr - {String} url字符串。 + */ +var formatEdits = function (dataStr,params,editArr) { + Object.keys(params).forEach(function (key) { + if(editArr && editArr.indexOf(key) > -1) { + let keyStr = key; + keyStr = key.substring(0,keyStr.length - 'Features'.length) + "s"; + //add、update、delete都需要json格式,并进行转义 + dataStr += keyStr + "=" + encodeURIComponent(params[key] instanceof Object ? JSON.stringify(params[key]) : params[key]) + "&"; + }else { + //不需要处理 + dataStr += key + "=" + params[key] + "&"; + } + + }); + return dataStr; +} + +/* + * APIMethod: returnPoint + * 输入坐标数组[x,y],将某个几何对象d的hasM、hasZ、spatialReference传给ArcGisPoint对象,并返回该对象 + * + * Parameters: + * constructor - {Function} ArcGisPoint构造函数。 + * geometry - {Object} 几何对象。 + * point - {Array} 数组坐标。 + * + * Returns: + * ArcGisPoint - {Object} ArcGisPoint对象。 + */ +var returnPoint = function (constructor,geometry,point) { + return new constructor({ + longitude: point[0], + latitude: point[1], + z: point[2], + spatialReference: cloneObject(geometry.spatialReference) + }); +} + +//递归处理数据 +var formatPoints = function (points) { + for(let i = 0; i < points.length; i++){ + if(points[i] instanceof Array){ + formatPoints(points[i]); + }else { + if(points[i] instanceof Object){ + points[i] = points[i].toArray(); + } + } + } + return points; +} + +/* + * APIMethod: notNULL + * 判断对象是否为""、null、undefined + * + * Parameters: + * obj - {Object} 要判断的对象。 + * + * Returns: + * isNull - {Boolean} 是否为空。 + */ +var notNULL = function (obj) { + return obj !== "" && obj !== null && obj !== undefined; +} + export { extend, isArray, @@ -1056,7 +1185,12 @@ export { DeepMerge, merge, mixin, - createCanvasContext2D + createCanvasContext2D, + formatQuery, + formatEdits, + returnPoint, + formatPoints, + notNULL }; Zondy.Util.extend = extend; Zondy.Util.isArray = isArray; @@ -1093,4 +1227,9 @@ Zondy.Util.ChineseToUtf8 = ChineseToUtf8; Zondy.Util.DeepMerge = DeepMerge; Zondy.Util.merge = merge; Zondy.Util.mixin = mixin; -Zondy.Util.createCanvasContext2D = createCanvasContext2D; \ No newline at end of file +Zondy.Util.createCanvasContext2D = createCanvasContext2D; +Zondy.Util.formatQuery = formatQuery; +Zondy.Util.formatEdits = formatEdits; +Zondy.Util.returnPoint = returnPoint; +Zondy.Util.returnPoint = formatPoints; +Zondy.Util.returnPoint = notNULL; \ No newline at end of file diff --git a/src/service/common/index.js b/src/service/common/index.js index edab58da2..e0ad79c22 100644 --- a/src/service/common/index.js +++ b/src/service/common/index.js @@ -90,7 +90,12 @@ import { DeepMerge, merge, mixin, - createCanvasContext2D + createCanvasContext2D, + formatQuery, + formatEdits, + returnPoint, + formatPoints, + notNULL } from './Util'; export {AnyLine}; @@ -185,6 +190,11 @@ export { DeepMerge, merge, mixin, - createCanvasContext2D + createCanvasContext2D, + formatQuery, + formatEdits, + returnPoint, + formatPoints, + notNULL } ; diff --git a/src/service/index.js b/src/service/index.js index 50af381ba..a010eca41 100644 --- a/src/service/index.js +++ b/src/service/index.js @@ -469,7 +469,40 @@ export const DataStore = { EsSpaceTimeQueryByAgg }; +import { + ArcGisFeatureLayer, + ArcGisFindParameters, + ArcGisFindTask, + ArcGisIdentifyTask, + ArcGisIdentifyParameters, + ArcGisGeometry, + ArcGisQuery, + ArcGisQueryTask, + ArcGisPoint, + ArcGisMultipoint, + ArcGisPolyline, + ArcGisPolygon, + ArcGisGraphic, + ArcGisExtent +} from './ArcGis' +export const ArcGis = { + ArcGisFeatureLayer, + ArcGisFindParameters, + ArcGisFindTask, + ArcGisIdentifyTask, + ArcGisIdentifyParameters, + ArcGisGeometry, + ArcGisQuery, + ArcGisQueryTask, + ArcGisPoint, + ArcGisMultipoint, + ArcGisPolyline, + ArcGisPolygon, + ArcGisGraphic, + ArcGisExtent +}; export default { MRFS, - MRFWS + MRFWS, + ArcGis };