1
1
/* Copyright© 2000 - 2020 SuperMap Software Co.Ltd. All rights reserved.
2
2
* This program are made available under the terms of the Apache License, Version 2.0
3
3
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
4
- import { SuperMap } from '../SuperMap' ;
5
- import { Point } from '../commontypes/geometry/Point' ;
6
- import { MultiPoint } from '../commontypes/geometry/MultiPoint' ;
7
- import { LinearRing } from '../commontypes/geometry/LinearRing' ;
8
- import { LineString } from '../commontypes/geometry/LineString' ;
9
- import { MultiLineString } from '../commontypes/geometry/MultiLineString' ;
10
- import { Polygon } from '../commontypes/geometry/Polygon' ;
11
- import { MultiPolygon } from '../commontypes/geometry/MultiPolygon' ;
12
- import { ServerStyle } from './ServerStyle' ;
13
- import { Route } from './Route' ;
14
- import { Util } from '../commontypes/Util' ;
15
- import { GeometryType } from '../REST' ;
4
+ import { SuperMap } from '../SuperMap' ;
5
+ import { Point } from '../commontypes/geometry/Point' ;
6
+ import { MultiPoint } from '../commontypes/geometry/MultiPoint' ;
7
+ import { LinearRing } from '../commontypes/geometry/LinearRing' ;
8
+ import { LineString } from '../commontypes/geometry/LineString' ;
9
+ import { MultiLineString } from '../commontypes/geometry/MultiLineString' ;
10
+ import { Polygon } from '../commontypes/geometry/Polygon' ;
11
+ import { MultiPolygon } from '../commontypes/geometry/MultiPolygon' ;
12
+ import { Collection } from '../commontypes/geometry/Collection' ;
13
+ import { ServerStyle } from './ServerStyle' ;
14
+ import { Route } from './Route' ;
15
+ import { Util } from '../commontypes/Util' ;
16
+ import { GeometryType } from '../REST' ;
16
17
17
18
/**
18
19
* @class SuperMap.ServerGeometry
19
- * @category iServer
20
+ * @category iServer
20
21
* @classdesc 服务端几何对象类。该类描述几何对象(矢量)的特征数据(坐标点对、几何对象的类型等)。基于服务端的空间分析、空间关系运算、查询等 GIS 服务功能使用服务端几何对象。
21
22
* @param {Object } options - 参数。
22
23
* @param {string } options.id - 服务端几何对象唯一标识符。
@@ -26,15 +27,13 @@ import {GeometryType} from '../REST';
26
27
* @param {SuperMap.ServerStyle } [options.style] - 服务端几何对象的风格。
27
28
*/
28
29
export class ServerGeometry {
29
-
30
30
constructor ( options ) {
31
-
32
31
/**
33
32
* @member {string} SuperMap.ServerGeometry.prototype.id
34
33
* @description 服务端几何对象唯一标识符。
35
34
*/
36
35
this . id = 0 ;
37
-
36
+
38
37
/**
39
38
* @member {SuperMap.ServerStyle} [SuperMap.ServerGeometry.prototype.style]
40
39
* @description 服务端几何对象的风格(ServerStyle)。
@@ -84,7 +83,7 @@ export class ServerGeometry {
84
83
Util . extend ( this , options ) ;
85
84
}
86
85
87
- this . CLASS_NAME = " SuperMap.ServerGeometry" ;
86
+ this . CLASS_NAME = ' SuperMap.ServerGeometry' ;
88
87
}
89
88
90
89
/**
@@ -125,6 +124,8 @@ export class ServerGeometry {
125
124
return me . toGeoLineEPS ( ) ;
126
125
case GeometryType . REGIONEPS :
127
126
return me . toGeoRegionEPS ( ) ;
127
+ case GeometryType . GEOCOMPOUND :
128
+ return me . transformGeoCompound ( ) ;
128
129
}
129
130
}
130
131
@@ -264,14 +265,9 @@ export class ServerGeometry {
264
265
var pointList = [ ] ;
265
266
if ( len == 1 ) {
266
267
for ( let i = 0 ; i < geoPoints . length ; i ++ ) {
267
- pointList . push (
268
- new Point ( geoPoints [ i ] . x , geoPoints [ i ] . y ) )
268
+ pointList . push ( new Point ( geoPoints [ i ] . x , geoPoints [ i ] . y ) ) ;
269
269
}
270
- polygonArray . push (
271
- new Polygon (
272
- [ new LinearRing ( pointList ) ]
273
- )
274
- ) ;
270
+ polygonArray . push ( new Polygon ( [ new LinearRing ( pointList ) ] ) ) ;
275
271
return new MultiPolygon ( polygonArray ) ;
276
272
}
277
273
//处理复杂面
@@ -283,17 +279,13 @@ export class ServerGeometry {
283
279
var CCWIdent = [ ] ;
284
280
for ( let i = 0 , pointIndex = 0 ; i < len ; i ++ ) {
285
281
for ( let j = 0 ; j < geoParts [ i ] ; j ++ ) {
286
- pointList . push (
287
- new Point ( geoPoints [ pointIndex + j ] . x , geoPoints [ pointIndex + j ] . y )
288
- ) ;
282
+ pointList . push ( new Point ( geoPoints [ pointIndex + j ] . x , geoPoints [ pointIndex + j ] . y ) ) ;
289
283
}
290
284
pointIndex += geoParts [ i ] ;
291
- var polygon = new Polygon (
292
- [ new LinearRing ( pointList ) ]
293
- ) ;
285
+ var polygon = new Polygon ( [ new LinearRing ( pointList ) ] ) ;
294
286
pointList = [ ] ;
295
287
polygonArrayTemp . push ( polygon ) ;
296
- if ( geoTopo . length === 0 ) {
288
+ if ( geoTopo . length === 0 ) {
297
289
polygonBounds . push ( polygon . getBounds ( ) ) ;
298
290
}
299
291
CCWIdent . push ( 1 ) ;
@@ -324,7 +316,9 @@ export class ServerGeometry {
324
316
if ( CCWIdent [ i ] > 0 ) {
325
317
polygonArray . push ( polygonArrayTemp [ i ] ) ;
326
318
} else {
327
- polygonArray [ targetArray [ i ] ] . components = polygonArray [ targetArray [ i ] ] . components . concat ( polygonArrayTemp [ i ] . components ) ;
319
+ polygonArray [ targetArray [ i ] ] . components = polygonArray [ targetArray [ i ] ] . components . concat (
320
+ polygonArrayTemp [ i ] . components
321
+ ) ;
328
322
//占位
329
323
polygonArray . push ( '' ) ;
330
324
}
@@ -338,22 +332,22 @@ export class ServerGeometry {
338
332
CCWArray = CCWArray . concat ( polygonArrayTemp [ i ] . components ) ;
339
333
} else {
340
334
if ( CCWArray . length > 0 && polygonArray . length > 0 ) {
341
- polygonArray [ polygonArray . length - 1 ] . components = polygonArray [ polygonArray . length - 1 ] . components . concat ( CCWArray ) ;
335
+ polygonArray [ polygonArray . length - 1 ] . components = polygonArray [
336
+ polygonArray . length - 1
337
+ ] . components . concat ( CCWArray ) ;
342
338
CCWArray = [ ] ;
343
339
}
344
- polygonArray . push (
345
- polygonArrayTemp [ i ]
346
- ) ;
340
+ polygonArray . push ( polygonArrayTemp [ i ] ) ;
347
341
}
348
342
if ( i == len - 1 ) {
349
343
var polyLength = polygonArray . length ;
350
344
if ( polyLength ) {
351
- polygonArray [ polyLength - 1 ] . components = polygonArray [ polyLength - 1 ] . components . concat ( CCWArray ) ;
345
+ polygonArray [ polyLength - 1 ] . components = polygonArray [ polyLength - 1 ] . components . concat (
346
+ CCWArray
347
+ ) ;
352
348
} else {
353
349
for ( let k = 0 , length = CCWArray . length ; k < length ; k ++ ) {
354
- polygonArray . push (
355
- new Polygon ( CCWArray )
356
- ) ;
350
+ polygonArray . push ( new Polygon ( CCWArray ) ) ;
357
351
}
358
352
}
359
353
}
@@ -382,16 +376,11 @@ export class ServerGeometry {
382
376
var lineEPS ;
383
377
if ( len == 1 ) {
384
378
for ( var i = 0 ; i < geoPoints . length ; i ++ ) {
385
- pointList . push (
386
- new Point ( geoPoints [ i ] . x , geoPoints [ i ] . y ) )
379
+ pointList . push ( new Point ( geoPoints [ i ] . x , geoPoints [ i ] . y ) ) ;
387
380
}
388
381
389
382
lineEPS = LineString . createLineEPS ( pointList ) ;
390
- polygonArray . push (
391
- new Polygon (
392
- [ new LinearRing ( lineEPS ) ]
393
- )
394
- ) ;
383
+ polygonArray . push ( new Polygon ( [ new LinearRing ( lineEPS ) ] ) ) ;
395
384
return new MultiPolygon ( polygonArray ) ;
396
385
}
397
386
//处理复杂面
@@ -403,19 +392,15 @@ export class ServerGeometry {
403
392
var CCWIdent = [ ] ;
404
393
for ( let i = 0 , pointIndex = 0 ; i < len ; i ++ ) {
405
394
for ( let j = 0 ; j < geoParts [ i ] ; j ++ ) {
406
- pointList . push (
407
- new Point ( geoPoints [ pointIndex + j ] . x , geoPoints [ pointIndex + j ] . y )
408
- ) ;
395
+ pointList . push ( new Point ( geoPoints [ pointIndex + j ] . x , geoPoints [ pointIndex + j ] . y ) ) ;
409
396
}
410
397
pointIndex += geoParts [ i ] ;
411
398
412
399
lineEPS = LineString . createLineEPS ( pointList ) ;
413
- var polygon = new Polygon (
414
- [ new LinearRing ( lineEPS ) ]
415
- ) ;
400
+ var polygon = new Polygon ( [ new LinearRing ( lineEPS ) ] ) ;
416
401
pointList = [ ] ;
417
402
polygonArrayTemp . push ( polygon ) ;
418
- if ( geoTopo . length === 0 ) {
403
+ if ( geoTopo . length === 0 ) {
419
404
polygonBounds . push ( polygon . getBounds ( ) ) ;
420
405
}
421
406
CCWIdent . push ( 1 ) ;
@@ -446,7 +431,9 @@ export class ServerGeometry {
446
431
if ( CCWIdent [ i ] > 0 ) {
447
432
polygonArray . push ( polygonArrayTemp [ i ] ) ;
448
433
} else {
449
- polygonArray [ targetArray [ i ] ] . components = polygonArray [ targetArray [ i ] ] . components . concat ( polygonArrayTemp [ i ] . components ) ;
434
+ polygonArray [ targetArray [ i ] ] . components = polygonArray [ targetArray [ i ] ] . components . concat (
435
+ polygonArrayTemp [ i ] . components
436
+ ) ;
450
437
//占位
451
438
polygonArray . push ( '' ) ;
452
439
}
@@ -459,29 +446,43 @@ export class ServerGeometry {
459
446
CCWArray = CCWArray . concat ( polygonArrayTemp [ i ] . components ) ;
460
447
} else {
461
448
if ( CCWArray . length > 0 && polygonArray . length > 0 ) {
462
- polygonArray [ polygonArray . length - 1 ] . components = polygonArray [ polygonArray . length - 1 ] . components . concat ( CCWArray ) ;
449
+ polygonArray [ polygonArray . length - 1 ] . components = polygonArray [
450
+ polygonArray . length - 1
451
+ ] . components . concat ( CCWArray ) ;
463
452
CCWArray = [ ] ;
464
453
}
465
- polygonArray . push (
466
- polygonArrayTemp [ i ]
467
- ) ;
454
+ polygonArray . push ( polygonArrayTemp [ i ] ) ;
468
455
}
469
456
if ( i == len - 1 ) {
470
457
var polyLength = polygonArray . length ;
471
458
if ( polyLength ) {
472
- polygonArray [ polyLength - 1 ] . components = polygonArray [ polyLength - 1 ] . components . concat ( CCWArray ) ;
459
+ polygonArray [ polyLength - 1 ] . components = polygonArray [ polyLength - 1 ] . components . concat (
460
+ CCWArray
461
+ ) ;
473
462
} else {
474
463
for ( let k = 0 , length = CCWArray . length ; k < length ; k ++ ) {
475
- polygonArray . push (
476
- new Polygon ( CCWArray )
477
- ) ;
464
+ polygonArray . push ( new Polygon ( CCWArray ) ) ;
478
465
}
479
466
}
480
467
}
481
468
}
482
469
}
483
470
return new MultiPolygon ( polygonArray ) ;
484
471
}
472
+ transformGeoCompound ( ) {
473
+ const me = this ,
474
+ geoParts = me . geoParts || [ ] ,
475
+ len = geoParts . length ;
476
+ if ( len <= 0 ) {
477
+ return null ;
478
+ }
479
+ const geometryList = [ ] ;
480
+ for ( let index = 0 ; index < len ; index ++ ) {
481
+ const geometry = geoParts [ index ] ;
482
+ geometryList . push ( new ServerGeometry ( geometry ) . toGeometry ( ) ) ;
483
+ }
484
+ return new Collection ( geometryList ) ;
485
+ }
485
486
486
487
/**
487
488
* @function SuperMap.ServerGeometry.prototype.fromJson
@@ -505,7 +506,6 @@ export class ServerGeometry {
505
506
minM : jsonObject . minM ,
506
507
type : jsonObject . type
507
508
} ) ;
508
-
509
509
}
510
510
511
511
/**
@@ -524,13 +524,17 @@ export class ServerGeometry {
524
524
type = null ,
525
525
icomponents = geometry . components ,
526
526
className = geometry . CLASS_NAME ,
527
- prjCoordSys = { " epsgCode" : geometry . SRID } ;
527
+ prjCoordSys = { epsgCode : geometry . SRID } ;
528
528
529
529
if ( ! isNaN ( geometry . id ) ) {
530
530
id = geometry . id ;
531
531
}
532
532
//坑爹的改法,没法,为了支持态势标绘,有时间就得全改
533
- if ( className != "SuperMap.Geometry.LinearRing" && className != "SuperMap.Geometry.LineString" && ( geometry instanceof MultiPoint || geometry instanceof MultiLineString ) ) {
533
+ if (
534
+ className != 'SuperMap.Geometry.LinearRing' &&
535
+ className != 'SuperMap.Geometry.LineString' &&
536
+ ( geometry instanceof MultiPoint || geometry instanceof MultiLineString )
537
+ ) {
534
538
let ilen = icomponents . length ;
535
539
for ( let i = 0 ; i < ilen ; i ++ ) {
536
540
let partPointsCount = icomponents [ i ] . getVertices ( ) . length ;
@@ -540,7 +544,7 @@ export class ServerGeometry {
540
544
}
541
545
}
542
546
//这里className不是多点就全部是算线
543
- type = ( className == " SuperMap.Geometry.MultiPoint" ) ? GeometryType . POINT : GeometryType . LINE ;
547
+ type = className == ' SuperMap.Geometry.MultiPoint' ? GeometryType . POINT : GeometryType . LINE ;
544
548
} else if ( geometry instanceof MultiPolygon ) {
545
549
let ilen = icomponents . length ;
546
550
for ( let i = 0 ; i < ilen ; i ++ ) {
@@ -551,9 +555,16 @@ export class ServerGeometry {
551
555
let partPointsCount = linearRingOfPolygon [ j ] . getVertices ( ) . length + 1 ;
552
556
parts . push ( partPointsCount ) ;
553
557
for ( let k = 0 ; k < partPointsCount - 1 ; k ++ ) {
554
- points . push ( new Point ( linearRingOfPolygon [ j ] . getVertices ( ) [ k ] . x , linearRingOfPolygon [ j ] . getVertices ( ) [ k ] . y ) ) ;
558
+ points . push (
559
+ new Point (
560
+ linearRingOfPolygon [ j ] . getVertices ( ) [ k ] . x ,
561
+ linearRingOfPolygon [ j ] . getVertices ( ) [ k ] . y
562
+ )
563
+ ) ;
555
564
}
556
- points . push ( new Point ( linearRingOfPolygon [ j ] . getVertices ( ) [ 0 ] . x , linearRingOfPolygon [ j ] . getVertices ( ) [ 0 ] . y ) ) ;
565
+ points . push (
566
+ new Point ( linearRingOfPolygon [ j ] . getVertices ( ) [ 0 ] . x , linearRingOfPolygon [ j ] . getVertices ( ) [ 0 ] . y )
567
+ ) ;
557
568
}
558
569
}
559
570
type = GeometryType . REGION ;
@@ -578,7 +589,7 @@ export class ServerGeometry {
578
589
geometryVerticesCount ++ ;
579
590
}
580
591
parts . push ( geometryVerticesCount ) ;
581
- type = ( geometry instanceof Point ) ? GeometryType . POINT : GeometryType . LINE ;
592
+ type = geometry instanceof Point ? GeometryType . POINT : GeometryType . LINE ;
582
593
}
583
594
584
595
return new ServerGeometry ( {
@@ -610,7 +621,7 @@ export class ServerGeometry {
610
621
return s * 0.5 ;
611
622
}
612
623
613
- static bubbleSort ( areaArray , pointList , geoTopo , polygonBounds ) {
624
+ static bubbleSort ( areaArray , pointList , geoTopo , polygonBounds ) {
614
625
for ( var i = 0 ; i < areaArray . length ; i ++ ) {
615
626
for ( var j = 0 ; j < areaArray . length ; j ++ ) {
616
627
if ( areaArray [ i ] > areaArray [ j ] ) {
@@ -634,7 +645,6 @@ export class ServerGeometry {
634
645
}
635
646
}
636
647
}
637
-
638
648
}
639
649
640
- SuperMap . ServerGeometry = ServerGeometry ;
650
+ SuperMap . ServerGeometry = ServerGeometry ;
0 commit comments