Skip to content

Commit 2a6dffa

Browse files
committed
【feature】支持iserver返回带有M值的geometry
1 parent bfccecb commit 2a6dffa

File tree

7 files changed

+604
-39
lines changed

7 files changed

+604
-39
lines changed

src/common/commontypes/geometry/Point.js

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,58 @@ import {Util} from '../Util';
2323
export class Point extends Geometry {
2424

2525

26-
constructor(x, y, type, tag) {
27-
super(x, y, type, tag);
26+
constructor(xOrCoordinates, yOrType, type, tag) {
27+
super();
2828
/**
2929
* @member {number} GeometryPoint.prototype.x
3030
* @description 横坐标。
3131
*/
32-
this.x = parseFloat(x);
32+
this.x;
3333

3434
/**
3535
* @member {number} GeometryPoint.prototype.y
3636
* @description 纵坐标。
3737
*/
38-
this.y = parseFloat(y);
38+
this.y;
3939

4040
/**
41-
* @member {string} GeometryPoint.prototype.tag
42-
* @description 用来存储额外的属性,比如插值分析中的 Z 值。
41+
* @member {number} GeometryPoint.prototype.z
42+
* @description Z 值。
43+
*/
44+
this.z;
45+
46+
/**
47+
* @member {number} GeometryPoint.prototype.m
48+
* @description M 值。
4349
*/
44-
this.tag = (tag || tag == 0) ? parseFloat(tag) : null;
50+
this.m;
4551

4652
/**
4753
* @member {string} GeometryPoint.prototype.type
4854
* @description 用来存储点的类型。
4955
*/
50-
this.type = type || "Point";
56+
this.type;
57+
if(Array.isArray(xOrCoordinates)){
58+
const [x,y,z,m] = xOrCoordinates;
59+
this.x = parseFloat(x);
60+
this.y = parseFloat(y);
61+
this.z = (z || z == 0) ? parseFloat(z) : null;
62+
this.m = (m || m == 0) ? parseFloat(m) : null;
63+
this.type = yOrType || "Point";
64+
}else{
65+
this.x = parseFloat(xOrCoordinates);
66+
this.y = parseFloat(yOrType);
67+
this.z = (tag || tag == 0) ? parseFloat(tag) : null;
68+
this.m = null;
69+
this.type = type || "Point";
70+
}
71+
/**
72+
* @member {string} GeometryPoint.prototype.tag
73+
* @deprecated
74+
* @description 用来存储额外的属性,比如插值分析中的 Z 值。
75+
*/
76+
this.tag = this.z;
77+
5178
this.CLASS_NAME = "SuperMap.Geometry.Point";
5279
this.geometryType = "Point";
5380
}
@@ -59,7 +86,7 @@ export class Point extends Geometry {
5986
*/
6087
clone(obj) {
6188
if (obj == null) {
62-
obj = new Point(this.x, this.y);
89+
obj = new Point([this.x, this.y, this.z, this.m]);
6390
}
6491

6592
// catch any randomly tagged-on properties
@@ -90,7 +117,7 @@ export class Point extends Geometry {
90117
equals(geom) {
91118
var equals = false;
92119
if (geom != null) {
93-
equals = ((this.x === geom.x && this.y === geom.y) ||
120+
equals = ((this.x === geom.x && this.y === geom.y && this.z === geom.z && this.m === geom.m) ||
94121
(isNaN(this.x) && isNaN(this.y) && isNaN(geom.x) && isNaN(geom.y)));
95122
}
96123
return equals;
@@ -115,7 +142,14 @@ export class Point extends Geometry {
115142
* @returns {string} 字符串代表点对象。(ex. <i>"5, 42"</i>)
116143
*/
117144
toShortString() {
118-
return (this.x + ", " + this.y);
145+
const arr = [this.x, this.y];
146+
if(this.z || this.z == 0){
147+
arr.push(this.z);
148+
}
149+
if(this.m || this.m == 0){
150+
arr.push(this.m);
151+
}
152+
return arr.join(", ");
119153
}
120154

121155
/**
@@ -126,6 +160,8 @@ export class Point extends Geometry {
126160
this.x = null;
127161
this.y = null;
128162
this.tag = null;
163+
this.z = null;
164+
this.m = null;
129165
super.destroy();
130166
}
131167

@@ -136,7 +172,5 @@ export class Point extends Geometry {
136172
*/
137173
getVertices() {
138174
return [this];
139-
}
140-
141-
175+
}
142176
}

src/common/format/GeoJSON.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class GeoJSON extends JSONFormat {
6767
* @member {boolean} [GeoJSONFormat.prototype.ignoreExtraDims=true]
6868
* @description 忽略维度超过 2 的几何要素。
6969
*/
70-
this.ignoreExtraDims = true;
70+
this.ignoreExtraDims = false;
7171

7272
this.CLASS_NAME = "SuperMap.Format.GeoJSON";
7373
/**
@@ -83,11 +83,10 @@ export class GeoJSON extends JSONFormat {
8383
* @returns {Geometry} 一个几何对象。
8484
*/
8585
"point": function (array) {
86-
if (this.ignoreExtraDims === false &&
87-
array.length != 2) {
88-
throw "Only 2D points are supported: " + array;
86+
if (this.ignoreExtraDims){
87+
return new Point(array[0], array[1]);
8988
}
90-
return new Point(array[0], array[1]);
89+
return new Point(array);
9190
},
9291

9392
/**
@@ -296,8 +295,17 @@ export class GeoJSON extends JSONFormat {
296295
*/
297296
'point': function (point) {
298297
var p = [point.x, point.y];
298+
if (point.z != null) {
299+
p.push(point.z);
300+
}
301+
if (point.m != null) {
302+
if(p.length === 2){
303+
p.push(null);
304+
}
305+
p.push(point.m);
306+
}
299307
for (var name in point) {
300-
if (name !== "x" && name !== "y" && point[name] !== null && !isNaN(point[name])) {
308+
if (['x', 'y', 'z', 'm'].indexOf(name) < 0 && point[name] !== null && !isNaN(point[name])) {
301309
p.push(point[name]);
302310
}
303311
}

src/common/iServer/ServerGeometry.js

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,13 @@ export class ServerGeometry {
143143
len = geoParts.length;
144144
if (len > 0) {
145145
if (len === 1) {
146-
return new Point(geoPoints[0].x, geoPoints[0].y);
146+
const {x, y, z, m} = geoPoints[0];
147+
return new Point([x, y, z, m]);
147148
} else {
148149
var pointList = [];
149150
for (let i = 0; i < len; i++) {
150-
pointList.push(new Point(geoPoints[i].x, geoPoints[i].y));
151+
const {x, y, z, m} = geoPoints[i];
152+
pointList.push(new Point([x, y, z, m]));
151153
}
152154
return new MultiPoint(pointList);
153155
}
@@ -170,7 +172,8 @@ export class ServerGeometry {
170172
if (len === 1) {
171173
let pointList = [];
172174
for (let i = 0; i < geoParts[0]; i++) {
173-
pointList.push(new Point(geoPoints[i].x, geoPoints[i].y));
175+
const {x, y, z, m} = geoPoints[i];
176+
pointList.push(new Point([x, y, z, m]));
174177
}
175178
//判断线是否闭合,如果闭合,则返回LinearRing,否则返回LineString
176179
if (pointList[0].equals(pointList[geoParts[0] - 1])) {
@@ -183,7 +186,8 @@ export class ServerGeometry {
183186
for (let i = 0; i < len; i++) {
184187
let pointList = [];
185188
for (let j = 0; j < geoParts[i]; j++) {
186-
pointList.push(new Point(geoPoints[j].x, geoPoints[j].y));
189+
const {x, y, z, m} = geoPoints[j];
190+
pointList.push(new Point([x, y, z, m]));
187191
}
188192
lineList.push(new LineString(pointList));
189193
geoPoints.splice(0, geoParts[i]);
@@ -213,7 +217,9 @@ export class ServerGeometry {
213217
if (len > 0) {
214218
if (len === 1) {
215219
for (i = 0, pointList = []; i < geoParts[0]; i++) {
216-
pointList.push(new Point(geoPoints[i].x, geoPoints[i].y, geoPoints[i].type));
220+
const {x, y, z, m, type} = geoPoints[i];
221+
const p = new Point([x, y, z, m], type);
222+
pointList.push(p);
217223
}
218224
//判断线是否闭合,如果闭合,则返回LinearRing,否则返回LineString
219225
if (pointList[0].equals(pointList[geoParts[0] - 1])) {
@@ -226,7 +232,8 @@ export class ServerGeometry {
226232
} else {
227233
for (i = 0, lineList = []; i < len; i++) {
228234
for (j = 0, pointList = []; j < geoParts[i]; j++) {
229-
pointList.push(new Point(geoPoints[j].x, geoPoints[j].y));
235+
const {x, y, z, m} = geoPoints[j];
236+
pointList.push(new Point([x, y, z, m]));
230237
}
231238
lineEPS = LineString.createLineEPS(pointList);
232239
lineList.push(new LineString(lineEPS));
@@ -267,7 +274,8 @@ export class ServerGeometry {
267274
var pointList = [];
268275
if (len == 1) {
269276
for (let i = 0; i < geoPoints.length; i++) {
270-
pointList.push(new Point(geoPoints[i].x, geoPoints[i].y));
277+
const {x, y, z, m} = geoPoints[i];
278+
pointList.push(new Point([x, y, z, m]));
271279
}
272280
polygonArray.push(new Polygon([new LinearRing(pointList)]));
273281
return new MultiPolygon(polygonArray);
@@ -281,7 +289,8 @@ export class ServerGeometry {
281289
var CCWIdent = [];
282290
for (let i = 0, pointIndex = 0; i < len; i++) {
283291
for (let j = 0; j < geoParts[i]; j++) {
284-
pointList.push(new Point(geoPoints[pointIndex + j].x, geoPoints[pointIndex + j].y));
292+
const {x, y, z, m} = geoPoints[pointIndex + j];
293+
pointList.push(new Point([x, y, z, m]));
285294
}
286295
pointIndex += geoParts[i];
287296
var polygon = new Polygon([new LinearRing(pointList)]);
@@ -374,7 +383,8 @@ export class ServerGeometry {
374383
var lineEPS;
375384
if (len == 1) {
376385
for (var i = 0; i < geoPoints.length; i++) {
377-
pointList.push(new Point(geoPoints[i].x, geoPoints[i].y));
386+
const {x, y, z, m} = geoPoints[i];
387+
pointList.push(new Point([x, y, z, m]));
378388
}
379389

380390
lineEPS = LineString.createLineEPS(pointList);
@@ -390,7 +400,8 @@ export class ServerGeometry {
390400
var CCWIdent = [];
391401
for (let i = 0, pointIndex = 0; i < len; i++) {
392402
for (let j = 0; j < geoParts[i]; j++) {
393-
pointList.push(new Point(geoPoints[pointIndex + j].x, geoPoints[pointIndex + j].y));
403+
const {x, y, z, m} = geoPoints[pointIndex + j];
404+
pointList.push(new Point([x, y, z, m]));
394405
}
395406
pointIndex += geoParts[i];
396407

@@ -536,7 +547,8 @@ export class ServerGeometry {
536547
let partPointsCount = vertices.length;
537548
parts.push(partPointsCount);
538549
for (let j = 0; j < partPointsCount; j++) {
539-
points.push(new Point(vertices[j].x, vertices[j].y));
550+
const {x, y, z, m} = vertices[j];
551+
points.push(new Point([x, y, z, m]));
540552
}
541553
}
542554
//这里className不是多点就全部是算线
@@ -552,11 +564,11 @@ export class ServerGeometry {
552564
const partPointsCount = vertices.length + 1;
553565
parts.push(partPointsCount);
554566
for (let k = 0; k < partPointsCount - 1; k++) {
555-
points.push(new Point(vertices[k].x, vertices[k].y));
567+
const {x, y, z, m} = vertices[k];
568+
points.push(new Point([x, y, z, m]));
556569
}
557-
points.push(
558-
new Point(vertices[0].x, vertices[0].y)
559-
);
570+
const {x, y, z, m} = vertices[0];
571+
points.push(new Point([x, y, z, m]));
560572
}
561573
}
562574
type = GeometryType.REGION;
@@ -567,19 +579,23 @@ export class ServerGeometry {
567579
let partPointsCount = vertices.length + 1;
568580
parts.push(partPointsCount);
569581
for (let j = 0; j < partPointsCount - 1; j++) {
570-
points.push(new Point(vertices[j].x, vertices[j].y));
582+
const {x, y, z, m} = vertices[j];
583+
points.push(new Point([x, y, z, m]));
571584
}
572-
points.push(new Point(vertices[0].x, vertices[0].y));
585+
const {x, y, z, m} = vertices[0];
586+
points.push(new Point([x, y, z, m]));
573587
}
574588
type = GeometryType.REGION;
575589
} else {
576590
const vertices = geometry.getVertices();
577591
let geometryVerticesCount = vertices.length;
578592
for (let j = 0; j < geometryVerticesCount; j++) {
579-
points.push(new Point(vertices[j].x, vertices[j].y));
593+
const {x, y, z, m} = vertices[j];
594+
points.push(new Point([x, y, z, m]));
580595
}
581596
if (geometry instanceof LinearRing) {
582-
points.push(new Point(vertices[0].x, vertices[0].y));
597+
const {x, y, z, m} = vertices[0];
598+
points.push(new Point([x, y, z, m]));
583599
geometryVerticesCount++;
584600
}
585601
parts.push(geometryVerticesCount);

0 commit comments

Comments
 (0)