1+
2+ import { ClientComputationLayer } from '../../../../src/leaflet/widgets/clientcomputation/clientComputationLayer' ;
3+ import { ClientComputationView } from '../../../../src/leaflet/widgets/clientcomputation/ClientComputationView'
4+ import { FetchRequest } from '../../../../src/common/util/FetchRequest' ;
5+ import { QueryBySQLService } from '../../../../src/common/iServer/QueryBySQLService' ;
6+ import { QueryBySQLParameters } from '../../../../src/common/iServer/QueryBySQLParameters' ;
7+ import { FilterParameter } from '../../../../src/common/iServer/FilterParameter' ;
8+ import { GeometryType } from '../../../../src/common/REST' ;
9+ import { QueryOption } from '../../../../src/common/REST' ;
10+ import '../../../../node_modules/leaflet.pm' ;
11+ import '../../../resources/QueryService.js' ;
12+
13+ var map , url = GlobeParameter . WorldURL , testDiv , clientComputation ;
14+ var dataServiceURL = GlobeParameter . wokerURL ;
15+ describe ( 'leaflet_clientcomputation_ClientComputationView' , ( ) => {
16+ var serviceResult , clientComputationLayer ;
17+ var originalTimeout , resultLayer , setLayer ;
18+ var queryFailedEventArgs = null , serviceSuccessEventArgs = null ;
19+ beforeAll ( ( ) => {
20+ testDiv = document . createElement ( "div" ) ;
21+ testDiv . id = 'map' ;
22+ testDiv . style . margin = "0 auto" ;
23+ testDiv . style . width = "800px" ;
24+ testDiv . style . height = "800px" ;
25+ document . body . appendChild ( testDiv ) ;
26+ map = L . map ( 'map' , {
27+ preferCanvas : true ,
28+ crs : L . CRS . EPSG4326 ,
29+ center : [ 20 , 80 ] ,
30+ maxZoom : 18 ,
31+ zoom : 2
32+ } ) ;
33+
34+ var wokerURL = "../../../base/libs/workers/TurfWorkerForTest.js" ;
35+ clientComputation = new ClientComputationView ( wokerURL ) ;
36+ clientComputation . addTo ( map ) ;
37+
38+ var queryUrl = "https://www.supermapol.com/iserver/services/map_ShiLiShuJu/rest/maps/中国历史5级以上地震_1900至2016@自然气候数据" ;
39+ spyOn ( FetchRequest , 'post' ) . and . callFake ( ( url , queryString ) => {
40+ // let param = JSON.parse(queryString.replace(/\'/g, "\""));
41+ console . log ( url ) ;
42+ if ( url . indexOf ( "/queryResults.json" ) > - 1 ) {
43+ var escapedJson = clientComputationViewJson ;
44+ return Promise . resolve ( new Response ( JSON . stringify ( escapedJson ) ) ) ;
45+
46+ }
47+ return Promise . resolve ( ) ;
48+ } ) ;
49+ var queryFailedEventArgs = null , serviceSuccessEventArgs = null ;
50+ var QueryBySQLFailed = ( serviceFailedEventArgs ) => {
51+ queryFailedEventArgs = serviceFailedEventArgs ;
52+ } ;
53+ var QueryBySQLCompleted = ( queryEventArgs ) => {
54+ serviceSuccessEventArgs = queryEventArgs ;
55+ } ;
56+ var options = {
57+ eventListeners : {
58+ 'processFailed' : QueryBySQLFailed ,
59+ 'processCompleted' : QueryBySQLCompleted
60+ }
61+ } ;
62+ var queryBySQLService = new QueryBySQLService ( queryUrl , options ) ;
63+ var params = new QueryBySQLParameters ( {
64+
65+ expectCount : 2 ,
66+ queryOption : QueryOption . ATTRIBUTEANDGEOMETRY ,
67+ queryParams : new Array ( new FilterParameter ( {
68+ attributeFilter : "SmID>0" ,
69+ name : "中国历史5级以上地震_1900至2016@自然气候数据" ,
70+ } ) )
71+ } )
72+ queryBySQLService . events . on ( { 'processCompleted' : QueryBySQLCompleted } ) ;
73+ queryBySQLService . processAsync ( params ) ;
74+
75+
76+ setTimeout ( ( ) => {
77+ try {
78+ var result = L . Util . transform ( serviceSuccessEventArgs . result . recordsets [ 0 ] . features , L . CRS . EPSG3857 , L . CRS . EPSG4326 ) ;
79+ resultLayer = L . geoJSON ( result , {
80+ style : { fillColor : '#ff7373' , color : '#ff7373' , opacity : 1 , fillOpacity : 0.8 } ,
81+ pointToLayer : function ( geoJsonPoint , latLng ) {
82+ return L . circleMarker ( latLng , { radius : 6 , color : '#ff7373' , fillColor : '#ff7373' } )
83+ }
84+ } ) . addTo ( map ) ;
85+ setLayer = {
86+ 'layerName' : "中国历史5级以上地震数据" ,
87+ 'layer' : resultLayer ,
88+ 'fields' : [ '震级' , '深度' , '经度' , '纬度' , 'SmID' , 'SmX' , 'SmY' ]
89+ } ;
90+ clientComputationLayer = new ClientComputationLayer ( setLayer ) ;
91+ clientComputation . addLayer ( clientComputationLayer ) ;
92+ } catch ( exception ) {
93+ expect ( false ) . toBeTruthy ( ) ;
94+ console . log ( "clientcomputation" + exception . name + ":" + exception . message ) ;
95+ queryBySQLService . destroy ( ) ;
96+ params . destroy ( ) ;
97+ queryFailedEventArgs = null ;
98+ serviceSuccessEventArgs = null ;
99+ }
100+ } , 2000 )
101+ } ) ;
102+
103+ beforeEach ( ( ) => {
104+ originalTimeout = jasmine . DEFAULT_TIMEOUT_INTERVAL ;
105+ jasmine . DEFAULT_TIMEOUT_INTERVAL = 50000 ;
106+ serviceResult = null ;
107+ } ) ;
108+ afterEach ( ( ) => {
109+ jasmine . DEFAULT_TIMEOUT_INTERVAL = originalTimeout ;
110+ } ) ;
111+
112+ it ( 'addLayer,isoline' , ( done ) => {
113+ setTimeout ( ( ) => {
114+ try {
115+ expect ( document . getElementById ( 'dropDownTop' ) . getAttribute ( 'data-value' ) ) . toBe ( "isolines" ) ;
116+ clientComputation . on ( 'analysissuccessed' , ( e ) => {
117+ try {
118+ if ( e . name . indexOf ( "等值线" ) > - 1 ) {
119+ expect ( e . layer . _layers ) . not . toBeNull ;
120+ expect ( e . layer . _layers ) . not . toBeUndefined ;
121+ done ( ) ;
122+ }
123+ else if ( e . name . indexOf ( "缓冲区" ) > - 1 ) {
124+ expect ( e . layer . _layers ) . not . toBeNull ;
125+ expect ( e . layer . _layers ) . not . toBeUndefined ;
126+ done ( ) ;
127+ }
128+ } catch ( exception ) {
129+ console . log ( "'isoline'案例失败:" + exception . name + ":" + exception . message ) ;
130+ expect ( false ) . toBeTruthy ( ) ;
131+ done ( ) ;
132+ }
133+ } ) ;
134+ var analysitBtn = document . getElementsByClassName ( 'analysis-btn' ) [ 0 ] ;
135+ analysitBtn . click ( ) ;
136+ } catch ( exception ) {
137+ expect ( false ) . toBeTruthy ( ) ;
138+ console . log ( "clientcomputation" + exception . name + ":" + exception . message ) ;
139+ done ( ) ;
140+ }
141+ } , 4000 )
142+
143+ } ) ;
144+
145+
146+ it ( 'addLayer,buffer' , ( done ) => {
147+ setTimeout ( ( ) => {
148+ try {
149+ document . getElementById ( 'dropDownTop' ) . click ( ) ;
150+ document . getElementsByClassName ( 'drop-down-item' ) [ 2 ] . click ( ) ;
151+ clientComputation . on ( 'analysissuccessed' , ( e ) => {
152+ try {
153+ if ( e . name . indexOf ( "等值线" ) > - 1 ) {
154+ expect ( e . layer . _layers ) . not . toBeNull ;
155+ expect ( e . layer . _layers ) . not . toBeUndefined ;
156+ done ( ) ;
157+ }
158+ else if ( e . name . indexOf ( "缓冲区" ) > - 1 ) {
159+
160+ expect ( e . layer . _layers ) . not . toBeNull ;
161+ expect ( e . layer . _layers ) . not . toBeUndefined ;
162+ done ( ) ;
163+ }
164+
165+ } catch ( exception ) {
166+ console . log ( "'isoline'案例失败:" + exception . name + ":" + exception . message ) ;
167+ expect ( false ) . toBeTruthy ( ) ;
168+ done ( ) ;
169+ }
170+ } ) ;
171+ expect ( document . getElementById ( 'bufferRadiusInput' ) . getAttribute ( 'placeholder' ) ) . toContain ( "10千米" ) ;
172+ var analysitBtn = document . getElementsByClassName ( 'analysis-btn' ) [ 0 ] ;
173+ analysitBtn . click ( ) ;
174+
175+ } catch ( exception ) {
176+ expect ( false ) . toBeTruthy ( ) ;
177+ console . log ( "clientcomputation" + exception . name + ":" + exception . message ) ;
178+ done ( ) ;
179+ }
180+ } , 4000 )
181+
182+ } ) ;
183+
184+ } )
0 commit comments