-
Notifications
You must be signed in to change notification settings - Fork 288
Expand file tree
/
Copy pathWebMapV2BaseSpec.js
More file actions
1417 lines (1358 loc) · 45.3 KB
/
WebMapV2BaseSpec.js
File metadata and controls
1417 lines (1358 loc) · 45.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { createWebMapV2BaseExtending } from '../../../src/common/mapping/WebMapV2Base';
import { FetchRequest } from '../../../src/common/util/FetchRequest';
import * as epsgDefine from '../../../src/common/mapping/utils/epsg-define';
import cloneDeep from 'lodash.clonedeep';
import { Canvg } from 'canvg';
describe('WebMapBaseSpec.js', () => {
const id = 123;
const options = {
credentialKey: undefined,
credentialValue: undefined,
excludePortalProxyUrl: undefined,
iportalServiceProxyUrlPrefix: undefined,
isSuperMapOnline: undefined,
proxy: undefined,
serverUrl: '/iportal',
target: 'map',
tiandituKey: undefined,
withCredentials: false
};
const mapOptions = {
style: {
layers: [],
sources: {},
version: 8
}
};
const map = {
getZoom: () => 2,
setZoom: () => {},
setMaxBounds: () => {},
setMinZoom: () => {},
setMaxZoom: () => {},
getSource: () => {
return {
_data: {
features: [
{
geometry: {}
}
]
}
};
}
};
const mock_geostats = class {
getClassEqInterval() {
return this.arrayData;
}
setSerie(arrayData) {
this.arrayData = arrayData;
}
};
const rankSymbolStyleParams = {
themeField: 'SmUserID',
features: [
{
type: 'Feature',
properties: {
SmUserID: 0,
col: '11111',
des: 'test1',
index: 0
},
geometry: {
type: 'Point',
coordinates: [116.36331703990744, 39.89942692791154]
}
},
{
type: 'Feature',
properties: {
SmUserID: 0,
col: '22222',
des: 'test2',
index: 1
},
geometry: {
type: 'Point',
coordinates: [116.37438913096268, 39.89976329032906]
}
},
{
type: 'Feature',
properties: {
SmUserID: 0,
col: '33333',
des: 'test3',
index: 2
},
geometry: {
type: 'Point',
coordinates: [116.38141290077355, 39.9767738835847]
}
}
],
parameters: {
layerType: 'RANK_SYMBOL',
visible: 'visible',
themeSetting: {
maxRadius: 12,
themeField: 'col',
customSettings: {
0: {
segment: {
start: 11111,
end: 22222
}
},
1: {
segment: {
start: 22222,
end: 33333.01
}
}
},
minRadius: 6,
segmentMethod: 'offset',
segmentCount: 2
},
filterCondition: "col != ''",
name: '站点1',
featureType: 'POINT',
style: {
strokeWidth: 1,
fillColor: '#24B391',
offsetX: 0,
offsetY: 0,
fillOpacity: 0.9,
radius: 9,
strokeColor: '#ffffff',
type: 'BASIC_POINT',
strokeOpacity: 1
},
projection: 'EPSG:4326',
enableFields: ['SmUserID', 'des', 'col'],
dataSource: {
accessType: 'DIRECT',
type: 'PORTAL_DATA',
serverId: '1170299840'
},
layerID: '站点1-1'
},
layerInfo: {
layerType: 'RANK_SYMBOL',
visible: 'visible',
themeSetting: {
maxRadius: 12,
themeField: 'SmUserID',
customSettings: {},
minRadius: 6,
segmentMethod: 'offset',
segmentCount: 2
},
filterCondition: "col != ''",
name: '站点1',
featureType: 'POINT',
style: {
strokeWidth: 1,
fillColor: '#24B391',
offsetX: 0,
offsetY: 0,
fillOpacity: 0.9,
radius: 9,
strokeColor: '#ffffff',
type: 'BASIC_POINT',
strokeOpacity: 1
},
projection: 'EPSG:4326',
enableFields: ['SmUserID', 'des', 'col'],
dataSource: {
accessType: 'DIRECT',
type: 'PORTAL_DATA',
serverId: '1170299840'
},
layerID: '站点1-1'
}
};
const rangeUniqueStyleParams = {
rangeLayer: {
layerType: 'RANGE',
visible: 'visible',
themeSetting: {
themeField: 'col',
customSettings: {
0: {
segment: {
start: 11111,
end: 22222.1
}
},
1: {
segment: {
start: 22222.1,
end: 33333.1
}
}
},
segmentMethod: 'offset',
segmentCount: 2,
colors: ['#ffc6c4', '#f4a3a8', '#e38191', '#cc607d', '#ad466c', '#8b3058', '#672044']
},
filterCondition: "col != ''",
name: '站点1',
featureType: 'POINT',
style: {
strokeWidth: 1,
fillColor: '#f4a3a8',
offsetX: 0,
offsetY: 0,
fillOpacity: 0.9,
radius: 8,
strokeColor: '#ffffff',
type: 'BASIC_POINT',
strokeOpacity: 1
},
projection: 'EPSG:4326',
enableFields: ['SmUserID', 'col'],
dataSource: {
accessType: 'DIRECT',
type: 'PORTAL_DATA',
serverId: '1170299840'
},
layerID: '站点1-1'
},
uniqueLayer: {
layerType: 'UNIQUE',
visible: 'visible',
themeSetting: {
themeField: 'col',
customSettings: {
11111: {
fillColor: '#D53E4F',
strokeWidth: 1,
offsetX: 0,
offsetY: 0,
fillOpacity: 0.9,
type: 'BASIC_POINT',
radius: 8,
strokeColor: '#ffffff',
strokeOpacity: 1
},
22222: {
fillColor: '#3288BD',
strokeWidth: 1,
offsetX: 0,
offsetY: 0,
fillOpacity: 0.9,
type: 'BASIC_POINT',
radius: 8,
strokeColor: '#ffffff',
strokeOpacity: 1
},
33333: {
fillColor: '#FC8D59',
strokeWidth: 1,
offsetX: 0,
offsetY: 0,
fillOpacity: 0.9,
type: 'BASIC_POINT',
radius: 8,
strokeColor: '#ffffff',
strokeOpacity: 1
}
},
colors: ['#D53E4F', '#FC8D59', '#FEE08B', '#FFFFBF', '#E6F598', '#99D594', '#3288BD']
},
name: '站点1',
featureType: 'POINT',
style: {
strokeWidth: 1,
offsetX: 0,
fillColor: '#FC8D59',
offsetY: 0,
fillOpacity: 0.9,
radius: 8,
strokeColor: '#ffffff',
type: 'BASIC_POINT',
strokeOpacity: 1
},
projection: 'EPSG:4326',
enableFields: ['SmUserID', 'col'],
dataSource: {
accessType: 'DIRECT',
type: 'PORTAL_DATA',
serverId: '1170299840'
},
layerID: '站点1-1'
}
};
const WebMapV2Base = createWebMapV2BaseExtending();
it('default SuperClass', (done) => {
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
expect(webMapBase.triggerEvent).not.toBeUndefined();
expect(webMapBase.fire).toBeUndefined();
done();
});
it('invoke attract methods', (done) => {
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
expect(() => webMapBase._initWebMap()).toThrow(new Error('_initWebMap is not implemented'));
expect(() => webMapBase._getMapInfo()).toThrow(new Error('_getMapInfo is not implemented'));
expect(() => webMapBase._createMap()).toThrow(new Error('_createMap is not implemented'));
expect(() => webMapBase._initBaseLayer()).toThrow(new Error('_initBaseLayer is not implemented'));
expect(() => webMapBase._initOverlayLayer()).toThrow(new Error('_initOverlayLayer is not implemented'));
expect(() => webMapBase._addLayerSucceeded()).toThrow(new Error('_addLayerSucceeded is not implemented'));
expect(() => webMapBase._unproject()).toThrow(new Error('_unproject is not implemented'));
expect(() => webMapBase.clean()).toThrow(new Error('clean is not implemented'));
done();
});
it('echartslayer', (done) => {
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
const chart = {
resize: () => {}
};
const spy = spyOn(chart, 'resize').and.callThrough();
webMapBase.echartslayer = [{ chart }];
webMapBase.echartsLayerResize();
expect(spy.calls.count()).toBe(1);
done();
});
it('setMapId mapId is number', (done) => {
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
webMapBase._initWebMap = () => {};
const spy = spyOn(webMapBase, '_initWebMap').and.callThrough();
jasmine.clock().install();
const changedMapId = 666;
expect(webMapBase.webMapInfo).toBeUndefined();
expect(webMapBase.mapId).toBe(id);
webMapBase.setMapId(changedMapId);
jasmine.clock().tick(10);
expect(spy.calls.count()).toBe(1);
expect(webMapBase.mapId).toBe(changedMapId);
expect(webMapBase.webMapInfo).toBeNull();
jasmine.clock().uninstall();
done();
});
it('setMapId mapId is obj', (done) => {
const mapId = {
value: 123
};
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
webMapBase._initWebMap = () => {};
const spy = spyOn(webMapBase, '_initWebMap').and.callThrough();
jasmine.clock().install();
expect(webMapBase.webMapInfo).toBeUndefined();
expect(webMapBase.mapId).toBe(id);
webMapBase.setMapId(mapId);
jasmine.clock().tick(10);
expect(spy.calls.count()).toBe(1);
expect(webMapBase.mapId).toBe('');
expect(webMapBase.webMapInfo).toEqual(mapId);
jasmine.clock().uninstall();
done();
});
it('setMapId mapId is empty', (done) => {
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
webMapBase._initWebMap = () => {};
const spy = spyOn(webMapBase, '_initWebMap').and.callThrough();
jasmine.clock().install();
expect(webMapBase.webMapInfo).toBeUndefined();
expect(webMapBase.mapId).toBe(id);
webMapBase.setMapId();
jasmine.clock().tick(10);
expect(spy.calls.count()).toBe(0);
expect(webMapBase.webMapInfo).toBeUndefined();
expect(webMapBase.mapId).toBe(id);
jasmine.clock().uninstall();
done();
});
it('serverUrl default', (done) => {
const webMapBase = new WebMapV2Base(id, { ...options, serverUrl: '' }, cloneDeep(mapOptions));
expect(webMapBase.serverUrl).not.toBe(options.serverUrl);
expect(webMapBase.serverUrl).toBe('https://www.supermapol.com');
done();
});
it('setServerUrl', (done) => {
const serverUrl = 'http://fake.iportal.com';
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
expect(webMapBase.serverUrl).toBe(options.serverUrl);
webMapBase.setServerUrl(serverUrl);
expect(webMapBase.serverUrl).toBe(serverUrl);
done();
});
it('withCredentials default', (done) => {
const webMapBase = new WebMapV2Base(id, { ...options, withCredentials: undefined }, cloneDeep(mapOptions));
expect(webMapBase.withCredentials).not.toBeUndefined();
expect(webMapBase.withCredentials).toBe(false);
done();
});
it('setWithCredentials', (done) => {
const withCredentials = true;
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
expect(webMapBase.withCredentials).toBe(false);
webMapBase.setWithCredentials(withCredentials);
expect(webMapBase.withCredentials).toBe(true);
done();
});
it('setProxy', (done) => {
const proxy = 'http://test';
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
expect(webMapBase.proxy).toBeUndefined();
webMapBase.setProxy(proxy);
expect(webMapBase.proxy).toBe(proxy);
done();
});
it('setZoom', (done) => {
const zoom = 3;
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
webMapBase.map = map;
const spy = spyOn(map, 'setZoom').and.callThrough();
expect(webMapBase.mapOptions.zoom).toBeUndefined();
webMapBase.setZoom(zoom);
expect(webMapBase.mapOptions.zoom).toBe(zoom);
expect(spy.calls.count()).toBe(1);
spy.calls.reset();
done();
});
//maxBounds真实值???
it('setMaxBounds', (done) => {
const maxBounds = 10;
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
webMapBase.map = map;
const spy = spyOn(map, 'setMaxBounds').and.callThrough();
expect(webMapBase.mapOptions.maxBounds).toBeUndefined();
webMapBase.setMaxBounds(maxBounds);
expect(webMapBase.mapOptions.maxBounds).toBe(maxBounds);
expect(spy.calls.count()).toBe(1);
spy.calls.reset();
done();
});
it('setMinZoom', (done) => {
const minZoom = 1;
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
webMapBase.map = map;
const spy = spyOn(map, 'setMinZoom').and.callThrough();
expect(webMapBase.mapOptions.minZoom).toBeUndefined();
webMapBase.setMinZoom(minZoom);
expect(webMapBase.mapOptions.minZoom).toBe(minZoom);
expect(spy.calls.count()).toBe(1);
spy.calls.reset();
done();
});
it('setMinZoom minZoom is undefined', (done) => {
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
webMapBase.map = map;
const spy = spyOn(map, 'setMinZoom').and.callThrough();
expect(webMapBase.mapOptions.minZoom).toBeUndefined();
webMapBase.setMinZoom();
expect(webMapBase.mapOptions.minZoom).toBeUndefined();
expect(spy.calls.count()).toBe(0);
spy.calls.reset();
done();
});
it('setMaxZoom', (done) => {
const maxZoom = 19;
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
webMapBase.map = map;
const spy = spyOn(map, 'setMaxZoom').and.callThrough();
expect(webMapBase.mapOptions.maxZoom).toBeUndefined();
webMapBase.setMaxZoom(maxZoom);
expect(webMapBase.mapOptions.maxZoom).toBe(maxZoom);
expect(spy.calls.count()).toBe(1);
spy.calls.reset();
done();
});
it('setMaxZoom maxZoom is undefined', (done) => {
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
webMapBase.map = map;
const spy = spyOn(map, 'setMaxZoom').and.callThrough();
expect(webMapBase.mapOptions.maxZoom).toBeUndefined();
webMapBase.setMaxZoom();
expect(webMapBase.mapOptions.maxZoom).toBeUndefined();
expect(spy.calls.count()).toBe(0);
spy.calls.reset();
done();
});
it('initWebMap for empty map', (done) => {
const webMapBase = new WebMapV2Base('', options, cloneDeep(mapOptions));
webMapBase.clean = () => {};
webMapBase._createMap = () => {};
const spy = spyOn(webMapBase, '_createMap').and.callThrough();
webMapBase.initWebMap();
expect(webMapBase.serverUrl).toBe(`${options.serverUrl}/`);
expect(spy.calls.count()).toBe(1);
done();
});
it('initWebMap for mapJson', (done) => {
const webMapBase = new WebMapV2Base('', options, cloneDeep(mapOptions));
webMapBase.clean = () => {};
webMapBase._getMapInfo = () => {};
webMapBase.webMapInfo = datavizWebMap_MVT;
const spy = spyOn(webMapBase, '_getMapInfo').and.callThrough();
expect(webMapBase.mapParams).toBeUndefined();
webMapBase.initWebMap();
expect(webMapBase.serverUrl).toBe(`${options.serverUrl}/`);
expect(webMapBase.mapParams).toEqual({
title: datavizWebMap_MVT.title,
description: datavizWebMap_MVT.description
});
expect(spy.calls.count()).toBe(1);
done();
});
it('initWebMap for webmap success', (done) => {
spyOn(FetchRequest, 'get').and.callFake((url) => {
if (url.indexOf('map.json') > -1) {
return Promise.resolve(new Response(JSON.stringify(datavizWebMap_MVT)));
}
return Promise.resolve(new Response(JSON.stringify(iportal_serviceProxy)));
});
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
webMapBase.clean = () => {};
webMapBase._getMapInfo = (mapInfo, _taskID) => {
expect(mapInfo).toEqual(datavizWebMap_MVT);
expect(webMapBase._taskID).toEqual(_taskID);
expect(webMapBase.mapParams).toEqual({
title: datavizWebMap_MVT.title,
description: datavizWebMap_MVT.description
});
done();
};
expect(webMapBase.mapParams).toBeUndefined();
webMapBase.initWebMap();
expect(webMapBase.serverUrl).toBe(`${options.serverUrl}/`);
});
it('initWebMap for webmap catch', (done) => {
const errorMsg = '未匹配到https://fakeiportal.supermap.io/iportal/web/maps/123/map.json';
spyOn(FetchRequest, 'get').and.callFake((url) => {
return Promise.reject(errorMsg);
});
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
webMapBase.clean = () => {};
webMapBase.on({
mapcreatefailed: ({ error }) => {
expect(error).toBe(errorMsg);
expect(webMapBase.mapParams).toBeUndefined();
done();
}
});
expect(webMapBase.mapParams).toBeUndefined();
webMapBase.initWebMap();
expect(webMapBase.serverUrl).toBe(`${options.serverUrl}/`);
});
it('getBaseLayerType layerType', (done) => {
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
expect(webMapBase.getBaseLayerType({ layerType: 'TIANDITU_TER' })).toBe('TIANDITU');
expect(webMapBase.getBaseLayerType({ layerType: 'TILE' })).toBe('TILE');
expect(webMapBase.getBaseLayerType({ layerType: 'SUPERMAP_REST' })).toBe('TILE');
expect(webMapBase.getBaseLayerType({ layerType: 'CLOUD_BLACK' })).toBe('CLOUD');
expect(webMapBase.getBaseLayerType({ layerType: 'CLOUD' })).toBe('CLOUD');
expect(webMapBase.getBaseLayerType({ layerType: 'OSM' })).toBe('XYZ');
expect(webMapBase.getBaseLayerType({ layerType: 'JAPAN_ORT' })).toBe('XYZ');
expect(webMapBase.getBaseLayerType({ layerType: 'JAPAN_RELIEF' })).toBe('XYZ');
expect(webMapBase.getBaseLayerType({ layerType: 'JAPAN_PALE' })).toBe('XYZ');
expect(webMapBase.getBaseLayerType({ layerType: 'JAPAN_STD' })).toBe('XYZ');
expect(webMapBase.getBaseLayerType({ layerType: 'GOOGLE_CN' })).toBe('XYZ');
expect(webMapBase.getBaseLayerType({ layerType: 'GOOGLE' })).toBe('XYZ');
expect(webMapBase.getBaseLayerType({ layerType: 'MAPBOXSTYLE' })).toBe('MAPBOXSTYLE');
done();
});
it('getMapurls is default', (done) => {
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
expect(webMapBase.getMapurls().CLOUD).toBe(
'http://t2.dituhui.com/FileService/image?map=quanguo&type=web&x={x}&y={y}&z={z}'
);
const testUrl = 'http://fake.url';
expect(webMapBase.getMapurls({ CLOUD: testUrl }).CLOUD).toBe(testUrl);
expect(webMapBase.getMapurls().CLOUD_BLACK).toBe('http://t3.dituhui.com/MapService/getGdp?x={x}&y={y}&z={z}');
expect(webMapBase.getMapurls({ CLOUD_BLACK: testUrl }).CLOUD_BLACK).toBe(testUrl);
expect(webMapBase.getMapurls().OSM).toBe('https://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png');
expect(webMapBase.getMapurls({ OSM: testUrl }).OSM).toBe(testUrl);
expect(webMapBase.getMapurls().JAPAN_ORT).toBe('https://cyberjapandata.gsi.go.jp/xyz/ort/{z}/{x}/{y}.jpg');
done();
});
it('getLayerFeatures success', (done) => {
const wktResponse = `PROJCS["China_2000_3_DEGREE_GK_Zone_39N",GEOGCS["GCS_China_2000",DATUM["D_China_2000",SPHEROID["CGCS2000",6378137.0,298.257222101,AUTHORITY["EPSG","7044"]]],PRIMEM["Greenwich",0.0,AUTHORITY["EPSG","8901"]],UNIT["DEGREE",0.017453292519943295],AUTHORITY["EPSG","4490"]],PROJECTION["Transverse_Mercator",AUTHORITY["EPSG","9807"]],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",117.0],PARAMETER["Latitude_Of_Origin",0.0],PARAMETER["Scale_Factor",1.0],UNIT["METER",1.0],AUTHORITY["EPSG","4548"]]`;
spyOn(FetchRequest, 'get').and.callFake(() => {
return Promise.resolve(new Response(JSON.stringify({ wkt: wktResponse })));
});
const layer = {
dataSource: { accessType: 'DIRECT', type: 'PORTAL_DATA', serverId: '366831804' },
enableFields: ['SmID', '标准名称', '起点x', '起点y', '终点x', '终点y'],
featureType: 'LINE',
layerID: '北京市轨道交通线路',
layerType: 'UNIQUE',
name: '北京市轨道交通线路',
projection: 'EPSG:2362',
style: { strokeWidth: 6, lineDash: 'solid', strokeColor: '#3288bd', type: 'LINE', strokeOpacity: 1 },
themeSetting: { themeField: 'SmID', customSettings: {}, colors: [] },
visible: true
};
const _taskID = '123';
const type = 'hosted';
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
webMapBase._taskID = _taskID;
const response1 = { type: 'feature', features: [] };
const response2 = wktResponse;
const spy1 = spyOn(webMapBase.webMapService, 'getLayerFeatures').and.callFake(() => {
return {
then: (resolveCb) => {
resolveCb(response1).then(() => {
expect(webMapBase._initOverlayLayer).toHaveBeenCalledWith(layer, response1.features);
const params = spy2.calls.allArgs()[0];
expect(params[0]).toBe(layer.projection);
expect(params[1]).toEqual(response2);
spy1.calls.reset();
spy2.calls.reset();
done();
});
return {
catch: () => {}
};
}
};
});
const spy2 = spyOn(epsgDefine, 'registerProjection').and.callThrough();
webMapBase._initOverlayLayer = jasmine.createSpy('callback');
webMapBase.getLayerFeatures(layer, _taskID, type);
});
it('getLayerFeatures failure', (done) => {
const layer = {
dataSource: { accessType: 'DIRECT', type: 'PORTAL_DATA', serverId: '366831804' },
enableFields: ['SmID', '标准名称', '起点x', '起点y', '终点x', '终点y'],
featureType: 'LINE',
layerID: '北京市轨道交通线路',
layerType: 'UNIQUE',
name: '北京市轨道交通线路',
projection: 'EPSG:2362',
style: { strokeWidth: 6, lineDash: 'solid', strokeColor: '#3288bd', type: 'LINE', strokeOpacity: 1 },
themeSetting: { themeField: 'SmID', customSettings: {}, colors: [] },
visible: true
};
const errorMsg = 'ooh error';
spyOn(FetchRequest, 'get').and.callFake(() => {
return Promise.reject(errorMsg);
});
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
webMapBase._addLayerSucceeded = jasmine.createSpy('callback');
const spy = spyOn(webMapBase, '_getLayerFeaturesSucceeded').and.callThrough();
webMapBase.on({
layercreatefailed: ({ error }) => {
expect(error.message).toBe(errorMsg);
expect(webMapBase._addLayerSucceeded).toHaveBeenCalledTimes(1);
expect(spy.calls.count()).toBe(0);
done();
}
});
webMapBase.getLayerFeatures(layer, undefined, 'hosted');
});
it('setFeatureInfo feature comes from dataViz', (done) => {
let feature = {
dv_v5_markerInfo: {
dataViz_title: 'jiuzhaigou',
title: '老虎海',
subtitle: '树正沟景点-老虎海'
},
geometry: { type: 'Point', coordinates: [0, 1] },
properties: {
title: '老虎海1',
subtitle: '树正沟景点-老虎海1',
imgUrl: './laohuhai.png',
description: '老虎海海拔2298米',
index: 1
},
type: 'Feature'
};
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
let res = webMapBase.setFeatureInfo(feature);
expect(res).toEqual(feature.dv_v5_markerInfo);
expect(res.title).toBe('老虎海1');
expect(feature.properties.title).toBeUndefined();
expect(res.title).toBe(feature.dv_v5_markerInfo.title);
expect(res.subtitle).toBe('树正沟景点-老虎海1');
expect(feature.properties.subtitle).toBeUndefined();
expect(res.subtitle).toBe(feature.dv_v5_markerInfo.subtitle);
expect(feature.properties.description).not.toBeUndefined();
expect(feature.properties.imgUrl).not.toBeUndefined();
expect(feature.properties.index).not.toBeUndefined();
feature = {
dv_v5_markerInfo: {
title: '老虎海',
subtitle: '树正沟景点-老虎海'
},
geometry: { type: 'Point', coordinates: [0, 1] },
properties: {
title: '老虎海1',
subtitle: '树正沟景点-老虎海1',
imgUrl: './laohuhai.png',
description: '老虎海海拔2298米',
index: 1
},
type: 'Feature'
};
res = webMapBase.setFeatureInfo(feature);
expect(res).toEqual(feature.dv_v5_markerInfo);
expect(res.title).toBe('老虎海');
expect(feature.properties.title).not.toBeUndefined();
expect(res.title).toBe(feature.dv_v5_markerInfo.title);
expect(res.subtitle).toBe('树正沟景点-老虎海');
expect(feature.properties.subtitle).not.toBeUndefined();
expect(res.subtitle).toBe(feature.dv_v5_markerInfo.subtitle);
feature = {
geometry: { type: 'Point', coordinates: [0, 1] },
properties: {
title: '老虎海',
subtitle: '树正沟景点-老虎海',
imgUrl: './laohuhai.png',
description: '老虎海海拔2298米',
index: 1
},
type: 'Feature'
};
res = webMapBase.setFeatureInfo(feature);
expect(res).toBeUndefined();
done();
});
it('setFeatureInfo feature not comes from dataViz', (done) => {
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
const feature = {
geometry: { type: 'Point', coordinates: [0, 1] },
properties: {
title: '老虎海',
subtitle: '树正沟景点-老虎海',
imgUrl: './laohuhai.png',
description: '老虎海海拔2298米',
index: 1
},
type: 'Feature'
};
expect(webMapBase.setFeatureInfo(feature)).toBeUndefined();
done();
});
it('getRankStyleGroup filter invalid fieldValue', (done) => {
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
window.geostats = mock_geostats;
const parameters = cloneDeep(rankSymbolStyleParams.parameters);
parameters.themeSetting.customSettings = {};
expect(webMapBase.getRankStyleGroup('des', rankSymbolStyleParams.features, parameters)).toBe(false);
window.geostats = undefined;
done();
});
it('getRankStyleGroup success', (done) => {
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
window.geostats = mock_geostats;
const res = webMapBase.getRankStyleGroup(
rankSymbolStyleParams.themeField,
rankSymbolStyleParams.features,
rankSymbolStyleParams.parameters
);
expect(res.length).toBe(2);
window.geostats = undefined;
done();
});
it('createRankStyleSource', (done) => {
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
window.geostats = mock_geostats;
const parameters = { ...rankSymbolStyleParams.parameters, filterCondition: '' };
const res = webMapBase.createRankStyleSource(parameters, rankSymbolStyleParams.features);
expect(res.styleGroups.length).toBe(2);
expect(res.parameters).toEqual(parameters);
window.geostats = undefined;
done();
});
it('getRestMapLayerInfo', (done) => {
const restMapInfo = {
bounds: {
left: 10,
top: 10,
bottom: 10,
right: 10
},
coordUnit: 'm',
visibleScales: 18,
url: 'http://test'
};
const layer = {
layerType: '',
orginEpsgCode: '',
units: '',
extent: '',
visibleScales: '',
url: '',
sourceType: ''
};
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
expect(webMapBase.getRestMapLayerInfo(restMapInfo, layer).layerType).toBe('TILE');
done();
});
it('handleLayerFeatures', (done) => {
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
const res = webMapBase.handleLayerFeatures(rankSymbolStyleParams.features, rankSymbolStyleParams.layerInfo);
expect(res).toEqual(rankSymbolStyleParams.features);
done();
});
it('getFilterFeatures no mock jsonsql', (done) => {
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
const res = webMapBase.getFilterFeatures('col > 11111', rankSymbolStyleParams.features);
expect(res.length).toBe(0);
done();
});
it('getFilterFeatures mock jsonsql', (done) => {
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
window.jsonsql = {
query: (sql, { attributes }) => {
if (+attributes.col > 11111) {
return [attributes];
}
return;
}
};
const res = webMapBase.getFilterFeatures('col > 11111', rankSymbolStyleParams.features);
expect(res.length).toBe(rankSymbolStyleParams.features.length - 1);
window.jsonsql = undefined;
done();
});
it('getEchartsLayerOptions', (done) => {
const layerInfo = {
layerType: 'MIGRATION',
labelSetting: {
fontFamily: '微软雅黑',
color: '#62AD16',
show: false
},
visible: 'visible',
name: '国内航班数据_100',
featureType: 'POINT',
from: {
xField: 'X',
yField: 'Y',
type: 'XY_FIELD'
},
projection: 'EPSG:4326',
to: {
xField: '到达城市x',
yField: '到达城市y',
type: 'XY_FIELD'
},
enableFields: [
'出发城市',
'Y',
'X',
'到达城市',
'到达城市y',
'到达城市x',
'起飞机场',
'起飞机场y',
'起飞机场x',
'降落机场',
'降落机场y',
'降落机场x'
],
lineSetting: {
curveness: 0.2,
color: '#62AD16',
width: 1,
type: 'solid',
opacity: 0.6
},
dataSource: {
accessType: 'DIRECT',
type: 'PORTAL_DATA',
serverId: '1645576091'
},
animationSetting: {
symbol: 'arrow',
symbolSize: 17,
show: true,
constantSpeed: 40
},
layerID: '国内航班数据_100'
};
const features = [
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [80.293842, 41.188341]
},
properties: {
出发城市: '阿克苏',
Y: '41.188341',
X: '80.293842',
到达城市: '北京',
到达城市y: '39.92998578',
到达城市x: '116.395645',
起飞机场: '阿克苏机场',
起飞机场y: '41.26940127',
起飞机场x: '80.30091874',
降落机场: '首都机场',
降落机场y: '40.06248537',
降落机场x: '116.5992671',
index: '0'
}
}
];
const coordinateSystem = 'GLMap';
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
const res = webMapBase.getEchartsLayerOptions(layerInfo, features, coordinateSystem);
expect(res.series[0].effect.constantSpeed).toBe(layerInfo.animationSetting.constantSpeed);
done();
});
it('getDashStyle str is solid', () => {
const str = 'solid';
const strokeWidth = 2;
const type = 'array';
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
expect(webMapBase.getDashStyle(str, strokeWidth, type)).toEqual([]);
});
it('getDashStyle str is dot', () => {
const str = 'dot';
const strokeWidth = 2;
const type = 'array';
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
expect(webMapBase.getDashStyle(str, strokeWidth, type)).toEqual([1, 8]);
});
it('getDashStyle str is dash', () => {
const str = 'dash';
const strokeWidth = 2;
const type = 'array';
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
expect(webMapBase.getDashStyle(str, strokeWidth, type)).toEqual([8, 8]);
});
it('getDashStyle str is dashrailway', () => {
const str = 'dashrailway';
const strokeWidth = 2;
const type = 'array';
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
expect(webMapBase.getDashStyle(str, strokeWidth, type)).toEqual([16, 24]);
});
it('getDashStyle str is dashdot', () => {
const str = 'dashdot';
const strokeWidth = 2;
const type = 'array';
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
expect(webMapBase.getDashStyle(str, strokeWidth, type)).toEqual([8, 8, 2, 8]);
});
it('getDashStyle str is longdash', () => {
const str = 'longdash';
const strokeWidth = 2;
const type = 'array';
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
expect(webMapBase.getDashStyle(str, strokeWidth, type)).toEqual([16, 8]);
});
it('getDashStyle str is longdashdot', () => {
const str = 'longdashdot';
const strokeWidth = 2;
const type = 'array';
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
expect(webMapBase.getDashStyle(str, strokeWidth, type)).toEqual([16, 8, 1, 8]);
});
it('getDashStyle no params', () => {
const webMapBase = new WebMapV2Base(id, options, cloneDeep(mapOptions));
expect(webMapBase.getDashStyle()).toEqual([]);
});