1
- import { VectorTileSuperMapRest } from '../../../src/openlayers/overlay/VectorTileSuperMapRest' ;
2
- import { MapService } from '../../../src/openlayers/services/MapService' ;
1
+ import { VectorTileSuperMapRest } from '../../../src/openlayers/overlay/VectorTileSuperMapRest' ;
2
+ import {
3
+ FetchRequest
4
+ } from '@supermap/iclient-common/util/FetchRequest' ;
5
+ import { MapService } from '../../../src/openlayers/services/MapService' ;
3
6
import Map from 'ol/Map' ;
4
7
import View from 'ol/View' ;
5
8
import VectorTileLayer from 'ol/layer/VectorTile' ;
6
9
7
10
var url = GlobeParameter . ChinaURL ;
11
+ const mapObject = {
12
+ "viewBounds" : {
13
+ "top" : 1.0018754171380693E7 ,
14
+ "left" : - 1.0018754171380727E7 ,
15
+ "bottom" : - 1.0018754171380745E7 ,
16
+ "leftBottom" : {
17
+ "x" : - 1.0018754171380727E7 ,
18
+ "y" : - 1.0018754171380745E7
19
+ } ,
20
+ "right" : 1.0018754171380712E7 ,
21
+ "rightTop" : {
22
+ "x" : 1.0018754171380712E7 ,
23
+ "y" : 1.0018754171380693E7
24
+ }
25
+ } , "bounds" : {
26
+ "top" : 2.0037508342789087E7 ,
27
+ "left" : - 2.0037508342789248E7 ,
28
+ "bottom" : - 2.003750834278914E7 ,
29
+ "leftBottom" : {
30
+ "x" : - 2.0037508342789248E7 ,
31
+ "y" : - 2.003750834278914E7
32
+ } ,
33
+ "right" : 2.0037508342789244E7 ,
34
+ "rightTop" : {
35
+ "x" : 2.0037508342789244E7 ,
36
+ "y" : 2.0037508342789087E7
37
+ }
38
+ } , "viewer" : {
39
+ "leftTop" : {
40
+ "x" : 0 ,
41
+ "y" : 0
42
+ } ,
43
+ "top" : 0 ,
44
+ "left" : 0 ,
45
+ "bottom" : 256 ,
46
+ "rightBottom" : {
47
+ "x" : 256 ,
48
+ "y" : 256
49
+ } ,
50
+ "width" : 256 ,
51
+ "right" : 256 ,
52
+ "height" : 256
53
+ } , "coordUnit" : "METER" , visibleScales : [ ] ,
54
+ }
8
55
describe ( 'openlayers_VectorTileSuperMapRest' , ( ) => {
9
- var testDiv , map , vectorTileOptions , vectorTileSource , originalTimeout , vectorLayer ;
56
+ var testDiv , map , vectorTileOptions , vectorTileSource , originalTimeout , vectorLayer ;
10
57
beforeAll ( ( ) => {
11
58
testDiv = window . document . createElement ( "div" ) ;
12
59
testDiv . setAttribute ( "id" , "map" ) ;
@@ -16,11 +63,14 @@ describe('openlayers_VectorTileSuperMapRest', () => {
16
63
testDiv . style . width = "500px" ;
17
64
testDiv . style . height = "500px" ;
18
65
window . document . body . appendChild ( testDiv ) ;
19
-
66
+ spyOn ( FetchRequest , 'get' ) . and . callFake ( ( testUrl , params , options ) => {
67
+ return Promise . resolve ( new Response ( JSON . stringify ( mapObject ) ) ) ;
68
+ } ) ;
69
+
20
70
} ) ;
21
71
beforeEach ( ( ) => {
22
72
originalTimeout = jasmine . DEFAULT_TIMEOUT_INTERVAL ;
23
- jasmine . DEFAULT_TIMEOUT_INTERVAL = 50000 ;
73
+ jasmine . DEFAULT_TIMEOUT_INTERVAL = 5000 ;
24
74
} ) ;
25
75
afterEach ( ( ) => {
26
76
if ( vectorLayer ) {
@@ -42,26 +92,35 @@ describe('openlayers_VectorTileSuperMapRest', () => {
42
92
} )
43
93
} ) ;
44
94
vectorTileOptions = VectorTileSuperMapRest . optionsFromMapJSON ( url , serviceResult . result ) ;
95
+ vectorTileOptions . tileLoadFunction = ( tile ) => {
96
+ tile . setLoader ( ( ) => {
97
+ tile . setFeatures ( [ ] )
98
+ } )
99
+ } ;
45
100
vectorTileSource = new VectorTileSuperMapRest ( vectorTileOptions ) ;
101
+ vectorTileSource . once ( 'tileloadend' , ( ) => {
102
+ expect ( vectorTileOptions ) . not . toBeNull ( ) ;
103
+ expect ( vectorTileOptions . crossOrigin ) . toBe ( "anonymous" ) ;
104
+ expect ( vectorTileSource ) . not . toBeNull ( ) ;
105
+ done ( ) ;
106
+ } )
46
107
vectorLayer = new VectorTileLayer ( {
47
108
source : vectorTileSource
48
109
} ) ;
49
110
map . addLayer ( vectorLayer ) ;
111
+
112
+
50
113
} ) ;
51
- setTimeout ( ( ) => {
52
- try {
53
- expect ( vectorTileOptions ) . not . toBeNull ( ) ;
54
- expect ( vectorTileOptions . crossOrigin ) . toBe ( "anonymous" ) ;
55
- expect ( vectorTileSource ) . not . toBeNull ( ) ;
56
- done ( ) ;
57
- } catch ( exception ) {
58
- console . log ( "'initialize'案例失败:" + exception . name + ":" + exception . message ) ;
59
- expect ( false ) . toBeTruthy ( ) ;
60
- }
61
- } , 0 ) ;
114
+
62
115
} ) ;
63
116
it ( 'custom_tileLoadFunction' , ( done ) => {
64
- var tileLoadFunction = jasmine . createSpy ( 'tileLoadFunction' ) ;
117
+ var spy = jasmine . createSpy ( 'test' )
118
+ var tileLoadFunction = ( tile ) => {
119
+ tile . setLoader ( ( ) => {
120
+ spy ( ) ;
121
+ tile . setFeatures ( [ ] )
122
+ } )
123
+ } ;
65
124
new MapService ( url ) . getMapInfo ( ( serviceResult ) => {
66
125
map = new Map ( {
67
126
target : 'map' ,
@@ -77,18 +136,14 @@ describe('openlayers_VectorTileSuperMapRest', () => {
77
136
source : vectorTileSource
78
137
} ) ;
79
138
map . addLayer ( vectorLayer ) ;
80
- } ) ;
81
- setTimeout ( ( ) => {
82
- try {
139
+ vectorLayer . getSource ( ) . once ( 'tileloadend' , ( ) => {
83
140
expect ( vectorTileOptions ) . not . toBeNull ( ) ;
84
- expect ( vectorTileSource ) . not . toBeNull ( ) ;
85
- expect ( tileLoadFunction ) . toHaveBeenCalled ( ) ;
141
+ expect ( spy ) . toHaveBeenCalled ( ) ;
86
142
done ( ) ;
87
- } catch ( exception ) {
88
- console . log ( "'initialize'案例失败:" + exception . name + ":" + exception . message ) ;
89
- expect ( false ) . toBeTruthy ( ) ;
90
- done ( ) ;
91
- }
92
- } , 0 ) ;
143
+
144
+ } )
145
+ } ) ;
146
+
147
+
93
148
} ) ;
94
149
} ) ;
0 commit comments