Skip to content

Commit 65d90a1

Browse files
author
潘卓然 Parn Deedlit
authored
Merge pull request #45 from MapGIS/dev_yangkun
Dev yangkun
2 parents 2c1e1fd + 53ce4ae commit 65d90a1

22 files changed

+2419
-7
lines changed

src/service/ArcGis/BaseParam.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import {
2+
Zondy,cloneObject
3+
} from '../common';
4+
5+
/**
6+
* @class module:ArcGis.ArcGisBaseParam
7+
* @description ArcGis服务
8+
* @author 基础平台-杨琨
9+
*/
10+
class ArcGisBaseParam {
11+
clone(){
12+
//完全返回一个新对象
13+
return cloneObject(this);
14+
}
15+
16+
//接收一个参数对象,如果参数对象里的值,本身也含有,则赋值,否则不赋值
17+
static fromJSON(JSON){
18+
let me = new this();
19+
if(JSON instanceof Object){
20+
for(let key in JSON){
21+
if(me.hasOwnProperty(key)){
22+
me[key] = JSON[key];
23+
}
24+
}
25+
}
26+
return me;
27+
}
28+
29+
toJSON(){
30+
//按照arcgis的tiJson编写,因为只接受对象类型,因此不做其他类型判断,返回一个对象
31+
let objInn = this;
32+
let returnObj = {};
33+
for (let attr in objInn) {
34+
if (typeof objInn[attr] !== "function" && attr !== "CLASS_NAME") {
35+
if(objInn[attr]) returnObj[attr] = objInn[attr];
36+
}
37+
}
38+
returnObj["spatialRel"] = "esriSpatialRelIntersects";
39+
return returnObj;
40+
}
41+
}
42+
43+
export {ArcGisBaseParam};
44+
Zondy.Service.ArcGisBaseParam = ArcGisBaseParam;

src/service/ArcGis/Extent.js

Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
import {extend, Zondy,notNULL} from "../common";
2+
import {ArcGisGeometry} from "./Geometry";
3+
import {ArcGisPoint} from "./Point";
4+
import * as T from '@turf/turf'
5+
import * as H from '@turf/helpers'
6+
7+
/**
8+
* @class module:ArcGis.ArcGisExtent
9+
* @description ArcGisExtent对象
10+
* @author 基础平台-杨琨
11+
* @param options - {Object} 必选项,构造Extent对象参数。
12+
* @param {String} [query.xmin] 可选项,x轴最小坐标。
13+
* @param {String} [query.ymin] 可选项,x轴最大坐标。
14+
* @param {String} [query.ymin] 可选项,y轴最小坐标。
15+
* @param {String} [query.ymax] 可选项,y轴最小坐标。
16+
* @param {String} [query.zmin] 可选项,z轴最小坐标。
17+
* @param {String} [query.zmax] 可选项,z轴最小坐标。
18+
* @param {String} [query.mmin] 可选项,m轴最小坐标。
19+
* @param {String} [query.mmax] 可选项,m轴最小坐标。
20+
*/
21+
22+
class ArcGisExtent extends ArcGisGeometry{
23+
constructor(options) {
24+
super(options);
25+
this.center = undefined;
26+
this.hasM = false;
27+
this.hasZ = false;
28+
this.height = 0;
29+
this.mmax = undefined;
30+
this.mmin = undefined;
31+
this.type = "extent";
32+
this.width = 0;
33+
this.xmax = 0;
34+
this.xmin = 0;
35+
this.ymax = 0;
36+
this.ymin = 0;
37+
this.zmax = undefined;
38+
this.zmin = undefined;
39+
this.extent = this;
40+
41+
//确保私有变量不能被options修改
42+
this.private = ["center","hasM","hasZ","height","width","type","extent"];
43+
for (let key in this.private){
44+
if(notNULL(options[this.private[key]])){
45+
throw new Error("[accessor] cannot assign to read-only property '" + this.private[key] + "' of ArcGisExtent");
46+
}
47+
}
48+
49+
extend(this,options);
50+
51+
//如果z、m有值,hasZ、hasM采薇true
52+
if(this.zmax || this.zmin){
53+
this.hasZ = true;
54+
}
55+
if(this.mmax || this.mmin){
56+
this.hasM = true;
57+
}
58+
59+
//生成bbox
60+
this._extentPolygon = T.polygon([[
61+
[this.xmin, this.ymin],
62+
[this.xmin, this.ymax],
63+
[this.xmax, this.ymax],
64+
[this.ymax, this.ymin],
65+
[this.xmin, this.ymin]
66+
]],{name:"_extentPlygon"});
67+
68+
//生成中心点
69+
this.center = initCenter(this);
70+
71+
//计算width,height
72+
this.width = this.xmax - this.xmin;
73+
this.height = this.ymax - this.ymin;
74+
}
75+
}
76+
77+
function initCenter(me){
78+
let points = [
79+
H.point( [me.xmin, me.ymin]),
80+
H.point( [me.xmin, me.ymax]),
81+
H.point( [me.xmax, me.ymax]),
82+
H.point( [me.ymax, me.ymin]),
83+
H.point( [me.xmin, me.ymin])
84+
];
85+
let featureCollection = H.featureCollection(points);
86+
let coordinates = T.center(featureCollection).geometry.coordinates;
87+
return new ArcGisPoint({
88+
longitude: coordinates[0],
89+
latitude: coordinates[1]
90+
});
91+
}
92+
93+
/**
94+
* @function module:ArcGis.ArcGisExtent.prototype.equals
95+
* @description 比较两个Extent对象是否相等
96+
* @param extent - {ArcGisExtent} 必选项,要比较的ArcGisExtent对象。
97+
* @returns Boolean,对象是否相等
98+
*/
99+
ArcGisExtent.prototype.equals = function (extent){
100+
return this.mmax === extent.mmax &&
101+
this.mmin === extent.mmin &&
102+
this.xmax === extent.xmax &&
103+
this.xmin === extent.xmin &&
104+
this.ymax === extent.ymax &&
105+
this.ymin === extent.ymin &&
106+
this.zmax === extent.zmax &&
107+
this.zmin === extent.zmin;
108+
}
109+
110+
/**
111+
* @function module:ArcGis.ArcGisExtent.prototype.contains
112+
* @description 判断是否包含一个点或者一个ArcGisExtent对象
113+
* @param geometry - {Geometry} 必选项,要比较的ArcGisExtent对象或者ArcGisPoint对象。
114+
* @returns Boolean,是否包含
115+
*/
116+
ArcGisExtent.prototype.contains = function (geometry){
117+
if(geometry.type === "point"){
118+
let point = geometry.toArray();
119+
point = T.point([point[0], point[1]]);
120+
return T.booleanContains(this._extentPolygon,point)
121+
}
122+
if(geometry.type === "extent"){
123+
return T.booleanContains(this._extentPolygon,geometry._extentPolygon)
124+
}
125+
return false;
126+
}
127+
128+
/**
129+
* @function module:ArcGis.ArcGisExtent.prototype.expand
130+
* @description 根据输入的值,扩大或缩小一个ArcGisExtent
131+
* @param factor - {Number} 必选项,放大或缩小系数。
132+
* @returns ArcGisExtent,缩放后的ArcGisExtent
133+
*/
134+
ArcGisExtent.prototype.expand = function (factor){
135+
if(factor instanceof Number){
136+
factor = Math.abs(factor);
137+
this.width = this.width * factor;
138+
this.height = this.height * factor;
139+
this.xmin = this.center.x - this.width / 2;
140+
this.xmax = this.center.x + this.width / 2;
141+
this.ymin = this.center.y - this.height / 2;
142+
this.ymax = this.center.y + this.height / 2;
143+
return this;
144+
}else {
145+
throw new Error("require is not defined");
146+
}
147+
}
148+
149+
/**
150+
* @function module:ArcGis.ArcGisExtent.prototype.intersects
151+
* @description 比较点、多点、线、多边形、extent是否与当前extent相交
152+
* @param geometry - {Geometry} 必选项,要比较的几何对象。
153+
* @returns Boolean,是否相交
154+
*/
155+
ArcGisExtent.prototype.intersects = function (geometry){
156+
if(!geometry.type){
157+
return false;
158+
}
159+
let geom;
160+
if(geometry.type === "polyline"){
161+
geom = H.multiLineString(geometry.paths);
162+
}else if(geometry.type === "point"){
163+
geom = H.point(geometry.toArray());
164+
}else if(geometry.type === "multipoint"){
165+
geom = H.multiPoint(geometry.points);
166+
}else if(geometry.type === "extent"){
167+
geom = geometry._extentPolygon;
168+
}else if(geometry.type === "polygon"){
169+
geom = H.polygon(geometry.rings);
170+
}
171+
return !T.booleanDisjoint(geom,this._extentPolygon);
172+
}
173+
174+
/**
175+
* @function module:ArcGis.ArcGisExtent.prototype.offset
176+
* @description 根据输入的dx, dy, dz值,平移extend
177+
* @param dx - {Number} 必选项,要平移的x值。
178+
* @param dx - {Number} 必选项,要平移的y值。
179+
* @param dx - {Number} 必选项,要平移的z值。
180+
* @returns ArcGisExtent,平移后的ArcGisExtent对象
181+
*/
182+
ArcGisExtent.prototype.offset = function (dx, dy, dz){
183+
this.xmax += dx;
184+
this.xmin += dx;
185+
this.ymax += dy;
186+
this.ymin += dy;
187+
if(this.hasZ){
188+
this.zmax += dz;
189+
this.zmin += dz;
190+
}else {
191+
this.hasZ = true;
192+
this.zmax = 0;
193+
this.zmin = 0;
194+
}
195+
return this;
196+
}
197+
198+
/**
199+
* @function module:ArcGis.ArcGisExtent.prototype.centerAt
200+
* @description 根据输入的ArcGisPoint对象,生成衣蛾新的中心点
201+
* @param point - {ArcGisPoint} 必选项,新的中心点。
202+
* @returns ArcGisExtent
203+
*/
204+
ArcGisExtent.prototype.centerAt = function (point){
205+
if(point instanceof ArcGisPoint){
206+
this.center = new ArcGisPoint({
207+
longitude: point.x,
208+
latitude: point.y
209+
});
210+
this.xmin = this.center.x - this.width / 2;
211+
this.xmax = this.center.x + this.width / 2;
212+
this.ymin = this.center.y - this.height / 2;
213+
this.ymax = this.center.y + this.height / 2;
214+
return this;
215+
}
216+
}
217+
218+
ArcGisExtent.prototype.normalize = function (){
219+
return [this];
220+
}
221+
222+
/**
223+
* @function module:ArcGis.ArcGisExtent.prototype.union
224+
* @description 输入一个ArcGisExtent对象,与原extent对象合并,生成一个新的extent
225+
* @param extent - {ArcGisExtent} 必选项,要合并的ArcGisExtent对象。
226+
* @returns ArcGisExtent,新的Extent对象
227+
*/
228+
ArcGisExtent.prototype.union = function (extent){
229+
let cur = this.center;
230+
let nex = extent.center;
231+
if(((nex.x - cur.x) > 0 && (nex.y - cur.y) > 0) || ((nex.x - cur.x) === 0 && (nex.y - cur.y) > 0)
232+
|| ((nex.x - cur.x) === 0 && (nex.y - cur.y) === 0)
233+
|| ((nex.x - cur.x) > 0 && (nex.y - cur.y) === 0)){
234+
this.xmax = extent.xmax;
235+
this.ymax = extent.ymax;
236+
}else if((nex.x - cur.x) > 0 && (nex.y - cur.y) < 0 || ((nex.x - cur.x) === 0 && (nex.y - cur.y) < 0)){
237+
this.xmax = extent.xmax;
238+
this.ymin = extent.ymin;
239+
}else if((nex.x - cur.x) < 0 && (nex.y - cur.y) < 0){
240+
this.xmin = extent.xmin;
241+
this.ymin = extent.ymin;
242+
}else if((nex.x - cur.x) < 0 && (nex.y - cur.y || ((nex.x - cur.x) < 0 && (nex.y - cur.y) < 0)) === 0){
243+
this.xmin = extent.xmin;
244+
this.ymax = extent.ymax;
245+
}
246+
this.center = initCenter(this);
247+
//计算width,height
248+
this.width = this.xmax - this.xmin;
249+
this.height = this.ymax - this.ymin;
250+
return this;
251+
}
252+
253+
/**
254+
* @function module:ArcGis.ArcGisExtent.prototype.toString
255+
* @description 返回如下格式的字符串:"xmin,ymin,xmax,ymax"
256+
* @returns Sting
257+
*/
258+
ArcGisExtent.prototype.toString = function (){
259+
return this.xmin + "," + this.ymin + "," + this.xmax + "," + this.ymax;
260+
}
261+
262+
export {ArcGisExtent};
263+
Zondy.Service.ArcGisExtent = ArcGisExtent;

0 commit comments

Comments
 (0)