1+ import { spatialAnalystService } from '../../../src/leaflet/services/SpatialAnalystService' ;
2+ import { GeometryBufferAnalystParameters } from '../../../src/common/iServer/GeometryBufferAnalystParameters' ;
3+ import { GeometryOverlayAnalystParameters } from '../../../src/common/iServer/GeometryOverlayAnalystParameters' ;
4+ import { BufferSetting } from '../../../src/common/iServer/BufferSetting' ;
5+ import { BufferDistance } from '../../../src/common/iServer/BufferDistance' ;
6+ import { BufferEndType } from '../../../src/common/REST' ;
7+ import { OverlayOperationType } from '../../../src/common/REST' ;
8+ import { FetchRequest } from "@supermap/iclient-common" ;
9+
10+ var serviceUrl = GlobeParameter . spatialAnalystURL ;
11+ describe ( 'leaflet_SpatialAnalystService_geometryBatchAnalysis' , ( ) => {
12+ var originalTimeout ;
13+ var serviceResult ;
14+ beforeEach ( ( ) => {
15+ originalTimeout = jasmine . DEFAULT_TIMEOUT_INTERVAL ;
16+ jasmine . DEFAULT_TIMEOUT_INTERVAL = 50000 ;
17+ serviceResult = null ;
18+ } ) ;
19+ afterEach ( ( ) => {
20+ jasmine . DEFAULT_TIMEOUT_INTERVAL = originalTimeout ;
21+ } ) ;
22+
23+ //空间关系分析
24+ it ( 'geometryBatchAnalysis' , ( done ) => {
25+ //缓冲区分析参数
26+ var bufferLine = {
27+ "type" : "Feature" ,
28+ "geometry" : {
29+ "type" : "LineString" ,
30+ "coordinates" : [ [ 117 , 40.50 ] , [ 118 , 40 ] ]
31+ }
32+ } ;
33+ var geoBufferAnalystParams = {
34+ analystName : "buffer" ,
35+ param : new GeometryBufferAnalystParameters ( {
36+ sourceGeometry : bufferLine ,
37+ sourceGeometrySRID : 4326 ,
38+ bufferSetting : new BufferSetting ( {
39+ endType : BufferEndType . ROUND ,
40+ leftDistance : new BufferDistance ( { value : 0.05 } ) ,
41+ rightDistance : new BufferDistance ( { value : 0.05 } ) ,
42+ semicircleLineSegment : 10
43+ } )
44+ } )
45+ } ;
46+
47+ //叠加分析参数
48+ var sourceGeometry = {
49+ "type" : "Feature" ,
50+ "geometry" : {
51+ "type" : "Polygon" ,
52+ "coordinates" : [ [ [ 116 , 39.75 ] ,
53+ [ 116 , 39.15 ] ,
54+ [ 117 , 39.15 ] ,
55+ [ 117 , 39.85 ] ,
56+ [ 116 , 39.85 ] ] ]
57+ }
58+ } ;
59+ var operateGeometry = {
60+ "type" : "Feature" ,
61+ "geometry" : {
62+ "type" : "Polygon" ,
63+ "coordinates" : [ [ [ 116.25 , 40.5 ] ,
64+ [ 116.25 , 38.5 ] ,
65+ [ 116.75 , 38.5 ] ,
66+ [ 116.75 , 40.5 ] ,
67+ [ 116.25 , 40.5 ] ] ]
68+ }
69+ } ;
70+ var OverlayBatchAnalystParameters = {
71+ analystName : "overlay" ,
72+ param : new GeometryOverlayAnalystParameters ( {
73+ sourceGeometry : sourceGeometry ,
74+ operateGeometry : operateGeometry ,
75+ operation : OverlayOperationType . CLIP
76+ } )
77+ } ;
78+
79+ //批量分析参数
80+ var paramter = [ geoBufferAnalystParams , OverlayBatchAnalystParameters ] ;
81+ //批量分析
82+ spyOn ( FetchRequest , 'commit' ) . and . callFake ( ( method , testUrl , params , options ) => {
83+ expect ( method ) . toBe ( "POST" ) ;
84+ expect ( testUrl ) . toBe ( serviceUrl + "/geometry/batchanalyst.json?returnContent=true&ignoreAnalystParam=true" ) ;
85+ var expectParams = `[{'analystName':"buffer",'param':{'analystParameter':{'endType':"ROUND",'leftDistance':{'exp':null,'value':0.05},'rightDistance':{'exp':null,'value':0.05},'semicircleLineSegment':10,'radiusUnit':"METER"},'sourceGeometry':{'id':0,'style':null,'parts':[2],'points':[{'id':"SuperMap.Geometry_25",'bounds':null,'SRID':null,'x':117,'y':40.5,'tag':null,'type':"Point"},{'id':"SuperMap.Geometry_26",'bounds':null,'SRID':null,'x':118,'y':40,'tag':null,'type':"Point"}],'type':"LINE",'prjCoordSys':{'epsgCode':4326}},'sourceGeometrySRID':4326}},{'analystName':"overlay",'param':{'operation':"CLIP",'sourceGeometry':{'id':0,'style':null,'parts':[6],'points':[{'id':"SuperMap.Geometry_27",'bounds':null,'SRID':null,'x':116,'y':39.75,'tag':null,'type':"Point"},{'id':"SuperMap.Geometry_28",'bounds':null,'SRID':null,'x':116,'y':39.15,'tag':null,'type':"Point"},{'id':"SuperMap.Geometry_29",'bounds':null,'SRID':null,'x':117,'y':39.15,'tag':null,'type':"Point"},{'id':"SuperMap.Geometry_30",'bounds':null,'SRID':null,'x':117,'y':39.85,'tag':null,'type':"Point"},{'id':"SuperMap.Geometry_31",'bounds':null,'SRID':null,'x':116,'y':39.85,'tag':null,'type':"Point"},{'id':"SuperMap.Geometry_32",'bounds':null,'SRID':null,'x':116,'y':39.75,'tag':null,'type':"Point"}],'type':"REGION",'prjCoordSys':{'epsgCode':null}},'operateGeometry':{'id':0,'style':null,'parts':[5],'points':[{'id':"SuperMap.Geometry_33",'bounds':null,'SRID':null,'x':116.25,'y':40.5,'tag':null,'type':"Point"},{'id':"SuperMap.Geometry_34",'bounds':null,'SRID':null,'x':116.25,'y':38.5,'tag':null,'type':"Point"},{'id':"SuperMap.Geometry_35",'bounds':null,'SRID':null,'x':116.75,'y':38.5,'tag':null,'type':"Point"},{'id':"SuperMap.Geometry_36",'bounds':null,'SRID':null,'x':116.75,'y':40.5,'tag':null,'type':"Point"},{'id':"SuperMap.Geometry_37",'bounds':null,'SRID':null,'x':116.25,'y':40.5,'tag':null,'type':"Point"}],'type':"REGION",'prjCoordSys':{'epsgCode':null}}}}]` ;
86+ expect ( params ) . toBe ( expectParams ) ;
87+ expect ( options ) . not . toBeNull ( ) ;
88+ var geometryBatchAnalystEscapedJson = `[{"image":null,"resultGeometry":{"center":{"x":117.50000000003955,"y":40.25000002045569},"parts":[23],"style":null,"prjCoordSys":null,"id":0,"type":"REGION","partTopo":[1],"points":[{"x":118.00000032273458,"y":40.000000396177164},{"x":118.0000004639434,"y":40.00000029515889},{"x":118.00000055482083,"y":40.000000164338125},{"x":118.00000058550799,"y":40.00000001790711},{"x":118.00000056027227,"y":39.999999889643746},{"x":118.0000004885416,"y":39.99999977223523},{"x":118.0000003571933,"y":39.99999966363337},{"x":118.00000018709451,"y":39.9999995937407},{"x":117.99999999669859,"y":39.99999957013961},{"x":117.99999982992506,"y":39.999999589548075},{"x":117.99999967726544,"y":39.999999644715196},{"x":116.99999968045223,"y":40.49999964203086},{"x":116.9999995367174,"y":40.49999974180941},{"x":116.99999944324225,"y":40.49999987182243},{"x":116.9999994101675,"y":40.50000001796533},{"x":116.99999943369343,"y":40.50000014642827},{"x":116.99999950421508,"y":40.500000264441226},{"x":116.999999634921,"y":40.50000037416583},{"x":116.99999980523283,"y":40.50000044552309},{"x":116.9999999966742,"y":40.50000047077176},{"x":117.0000001649555,"y":40.50000045281249},{"x":117.00000031954775,"y":40.50000039897753},{"x":118.00000032273458,"y":40.000000396177164}]},"succeed":true,"message":null},{"image":null,"resultGeometry":{"center":{"x":116.5,"y":39.5},"parts":[5],"style":null,"prjCoordSys":null,"id":0,"type":"REGION","partTopo":[1],"points":[{"x":116.25,"y":39.85},{"x":116.75,"y":39.85},{"x":116.75,"y":39.15},{"x":116.25,"y":39.15},{"x":116.25,"y":39.85}]},"succeed":true,"message":null}]` ;
89+ return Promise . resolve ( new Response ( geometryBatchAnalystEscapedJson ) ) ;
90+ } ) ;
91+ spatialAnalystService ( serviceUrl ) . geometrybatchAnalysis ( paramter , ( result ) => {
92+ serviceResult = result ;
93+ } ) ;
94+ setTimeout ( ( ) => {
95+ expect ( serviceResult ) . not . toBeNull ( ) ;
96+ expect ( serviceResult . type ) . toBe ( "processCompleted" ) ;
97+ expect ( serviceResult . result . succeed ) . toEqual ( true ) ;
98+ expect ( serviceResult . result . length ) . toEqual ( 2 ) ;
99+ for ( var i = 0 ; i < serviceResult . result . length ; i ++ ) {
100+ expect ( serviceResult . result [ i ] . resultGeometry ) . not . toBeNull ( ) ;
101+ expect ( serviceResult . result [ i ] . resultGeometry . geometry ) . not . toBeNull ( ) ;
102+ expect ( serviceResult . result [ i ] . resultGeometry . geometry . coordinates . length ) . toBeGreaterThan ( 0 ) ;
103+ expect ( serviceResult . result [ i ] . resultGeometry . geometry . type ) . toBe ( "MultiPolygon" ) ;
104+ expect ( serviceResult . result [ i ] . resultGeometry . type ) . toBe ( "Feature" ) ;
105+ expect ( serviceResult . result [ i ] . succeed ) . toBeTruthy ( ) ;
106+ }
107+ done ( ) ;
108+ } , 3000 )
109+ } ) ;
110+ } ) ;
0 commit comments