@@ -3,7 +3,8 @@ import "../../../../src/mapboxgl/overlay/symbol/MapExtendSymbol";
3
3
import { FetchRequest } from '../../../../src/common/util/FetchRequest' ;
4
4
5
5
describe ( 'MapExtendSymbol' , ( ) => {
6
- var url = 'http://localhost:8099/s3h4sgb3/iserver/services/map-china400/rest/maps/China' ;
6
+ var url = GlobeParameter . ChinaURL ;
7
+ var populationUrl = GlobeParameter . populationURL ;
7
8
var testDiv , map ;
8
9
var originalTimeout ;
9
10
beforeAll ( ( done ) => {
@@ -27,7 +28,7 @@ describe('MapExtendSymbol', () => {
27
28
} ,
28
29
"全国人口密度空间分布图" : {
29
30
"tiles" : [
30
- "http:/fake:8090/iserver/services/map-Population/rest/maps/PopulationDistribution /tileFeature.mvt?z={z}&x={x}&y={y}"
31
+ populationUrl + " /tileFeature.mvt?z={z}&x={x}&y={y}"
31
32
] ,
32
33
"type" : "vector"
33
34
}
@@ -43,9 +44,9 @@ describe('MapExtendSymbol', () => {
43
44
center : [ 116.40 , 39.79 ] ,
44
45
zoom : 3
45
46
} ) ;
46
- map . on ( 'load' , function ( ) {
47
+ setTimeout ( ( ) => {
47
48
done ( ) ;
48
- } ) ;
49
+ } , 0 ) ;
49
50
} ) ;
50
51
beforeEach ( ( ) => {
51
52
originalTimeout = jasmine . DEFAULT_TIMEOUT_INTERVAL ;
@@ -58,6 +59,7 @@ describe('MapExtendSymbol', () => {
58
59
window . document . body . removeChild ( testDiv ) ;
59
60
map . remove ( ) ;
60
61
} ) ;
62
+
61
63
62
64
it ( 'map.loadSymbol point-1' , ( done ) => {
63
65
spyOn ( FetchRequest , 'get' ) . and . callFake ( ( path ) => {
@@ -101,178 +103,153 @@ describe('MapExtendSymbol', () => {
101
103
done ( ) ;
102
104
} ) ;
103
105
104
- it ( 'map.addLayer no symbol' , ( done ) => {
105
- map . addLayer ( {
106
- "id" : "PopDensity_R@Population" ,
107
- "source" : "全国人口密度空间分布图" ,
108
- "source-layer" : "PopDensity_R@Population" ,
109
- "type" : "fill" ,
110
- "paint" : {
111
- "fill-color" : "rgba(197,88,254,1.00)" ,
112
- "fill-antialias" : true
113
- }
106
+ it ( 'map.moveLayer' , ( ) => {
107
+ spyOn ( map . style , 'getLayer' ) . and . returnValue ( {
108
+ id : 'PopDensity_P@Population'
114
109
} ) ;
115
- const layer = map . getLayer ( "PopDensity_R@Population" ) ;
116
- expect ( layer ) . not . toBeNull ( ) ;
117
- expect ( layer . id ) . toBe ( "PopDensity_R@Population" ) ;
118
- done ( ) ;
110
+ spyOn ( map , 'moveLayerBySymbolBak' ) ;
111
+ map . moveLayer ( "PopDensity_P@Population" , "PopDensity_R@Population" ) ;
112
+ expect ( map . moveLayerBySymbolBak ) . toHaveBeenCalled ( ) ;
119
113
} ) ;
120
114
121
- it ( 'map.addLayer symbol' , ( done ) => {
122
- map . addSymbol ( "start" , { "layout" : { "icon-image" : "point-1" } } ) ;
123
- map . addLayer ( {
124
- "id" : "PopDensity_P@Population" ,
125
- "source" : "全国人口密度空间分布图" ,
126
- "source-layer" : "PopDensity_R@Population" ,
127
- "type" : "symbol" ,
128
- "symbol" : "start"
115
+ it ( 'map.moveLayer no beforeId' , ( ) => {
116
+ spyOn ( map . style , 'getLayer' ) . and . returnValue ( {
117
+ id : 'PopDensity_P@Population'
129
118
} ) ;
130
- const layer = map . getLayer ( "PopDensity_P@Population" ) ;
131
- expect ( layer ) . not . toBeNull ( ) ;
132
- expect ( layer . id ) . toBe ( "PopDensity_P@Population" ) ;
133
- expect ( layer . symbol ) . toBe ( "start" ) ;
134
- done ( ) ;
135
- } ) ;
136
-
137
- it ( 'map.moveLayer' , ( done ) => {
138
- const styleLayers = map . getStyle ( ) . layers ;
139
- expect ( styleLayers . length ) . toBe ( 3 ) ;
140
- expect ( styleLayers [ 1 ] . id ) . toBe ( "PopDensity_R@Population" ) ;
141
- expect ( styleLayers [ 2 ] . id ) . toBe ( "PopDensity_P@Population" ) ;
142
- map . moveLayer ( "PopDensity_P@Population" , "PopDensity_R@Population" ) ;
143
- const newLayers = map . getStyle ( ) . layers ;
144
- expect ( newLayers . length ) . toBe ( 3 ) ;
145
- expect ( newLayers [ 1 ] . id ) . toBe ( "PopDensity_P@Population" ) ;
146
- expect ( newLayers [ 2 ] . id ) . toBe ( "PopDensity_R@Population" ) ;
119
+ spyOn ( map , 'moveLayerBySymbolBak' ) ;
147
120
map . moveLayer ( "PopDensity_P@Population" ) ;
148
- done ( ) ;
121
+ expect ( map . moveLayerBySymbolBak ) . toHaveBeenCalled ( ) ;
149
122
} ) ;
150
123
151
- it ( 'map.moveLayer no beforeId' , ( done ) => {
124
+ it ( 'map.moveLayer no Layer' , ( ) => {
125
+ spyOn ( map . style , 'getLayer' ) . and . returnValue ( null ) ;
126
+ spyOn ( map , 'moveLayerBySymbolBak' ) ;
127
+ spyOn ( map , '_update' ) ;
152
128
map . moveLayer ( "PopDensity_P@Population" ) ;
153
- const newLayers = map . getStyle ( ) . layers ;
154
- expect ( newLayers . length ) . toBe ( 3 ) ;
155
- expect ( newLayers [ 2 ] . id ) . toBe ( "PopDensity_P@Population" ) ;
156
- done ( ) ;
129
+ expect ( map . moveLayerBySymbolBak ) . not . toHaveBeenCalled ( ) ;
130
+ expect ( map . _update ) . toHaveBeenCalled ( ) ;
157
131
} ) ;
158
132
159
- it ( 'map.moveLayer error id' , ( done ) => {
160
- map . moveLayer ( "PopDensity" ) ;
161
- const newLayers = map . getStyle ( ) . layers ;
162
- expect ( newLayers . length ) . toBe ( 3 ) ;
163
- done ( ) ;
164
- } ) ;
165
-
166
- it ( 'map.removeLayer error id' , ( done ) => {
167
- map . removeLayer ( "PopDensity" ) ;
168
- const newLayers = map . getStyle ( ) . layers ;
169
- expect ( newLayers . length ) . toBe ( 3 ) ;
170
- done ( ) ;
133
+ it ( 'map.removeLayer no Layer' , ( ) => {
134
+ spyOn ( map . style , 'getLayer' ) . and . returnValue ( null ) ;
135
+ spyOn ( map , 'removeLayerBySymbolBak' ) ;
136
+ map . removeLayer ( "PopDensity_P@Population" ) ;
137
+ expect ( map . removeLayerBySymbolBak ) . not . toHaveBeenCalled ( ) ;
171
138
} ) ;
172
139
173
- it ( 'map.removeLayer id' , ( done ) => {
140
+ it ( 'map.removeLayer id' , ( ) => {
141
+ spyOn ( map . style , 'getLayer' ) . and . returnValue ( {
142
+ id : 'PopDensity_P@Population'
143
+ } ) ;
144
+ spyOn ( map , 'removeLayerBySymbolBak' ) ;
145
+ spyOn ( map . symbolHandler , 'removeLayer' ) ;
174
146
map . removeLayer ( "PopDensity_P@Population" ) ;
175
- const newLayers = map . getStyle ( ) . layers ;
176
- expect ( newLayers . length ) . toBe ( 2 ) ;
177
- expect ( newLayers [ 1 ] . id ) . toBe ( "PopDensity_R@Population" ) ;
178
- done ( ) ;
147
+ expect ( map . removeLayerBySymbolBak ) . toHaveBeenCalled ( ) ;
179
148
} ) ;
180
149
181
- it ( 'map.setPaintProperty' , ( done ) => {
182
- map . setPaintProperty ( "PopDensity_P@Population" ) ;
183
- map . setPaintProperty ( "PopDensity_R@Population" , "fill-color" , "black" ) ;
184
- expect ( map . getPaintProperty ( "PopDensity_R@Population" , "fill-color" ) ) . toBe ( "black" ) ;
185
- done ( ) ;
150
+ it ( 'setLayerZoomRange' , ( ) => {
151
+ spyOn ( map . style , 'getLayer' ) . and . returnValue ( {
152
+ id : 'PopDensity_P@Population'
153
+ } ) ;
154
+ spyOn ( map . style , 'setLayerZoomRange' ) ;
155
+ spyOn ( map , '_update' ) ;
156
+ map . setLayerZoomRange ( 'PopDensity_R@Population' , 2 , 5 ) ;
157
+ expect ( map . style . setLayerZoomRange ) . toHaveBeenCalled ( ) ;
186
158
} ) ;
187
159
188
- it ( 'map.setLayoutProperty ' , ( done ) => {
189
- map . setLayoutProperty ( "PopDensity_P@Population" ) ;
190
- map . getLayoutProperty ( "PopDensity_P@Population" , "visibility" ) ;
191
- map . setLayoutProperty ( "PopDensity_R@Population" , "visibility" , "visible" ) ;
192
- expect ( map . getLayoutProperty ( " PopDensity_R@Population" , "visibility" ) ) . toBe ( "visible" ) ;
193
- done ( ) ;
160
+ it ( 'setLayerZoomRange-noLayer ' , ( ) => {
161
+ spyOn ( map . style , 'getLayer' ) . and . returnValue ( null ) ;
162
+ spyOn ( map . style , 'setLayerZoomRange' ) ;
163
+ spyOn ( map . symbolHandler , 'setLayerZoomRange' ) ;
164
+ map . setLayerZoomRange ( ' PopDensity_R@Population' , 2 , 5 ) ;
165
+ expect ( map . symbolHandler . setLayerZoomRange ) . toHaveBeenCalled ( ) ;
194
166
} ) ;
195
167
196
- it ( 'setLayerZoomRange' , ( ) => {
197
- map . setLayerZoomRange ( 'PopDensity_R@Population' , 2 , 5 ) ;
198
- expect ( map . getLayer ( 'PopDensity_R@Population' ) . minzoom ) . toBe ( 2 ) ;
199
- expect ( map . getLayer ( 'PopDensity_R@Population' ) . maxzoom ) . toBe ( 5 ) ;
168
+ it ( 'map.setSymbol' , ( ) => {
169
+ spyOn ( map . symbolHandler , 'setSymbol' ) ;
170
+ map . setSymbol ( "PopDensity_R@Population" , "polygon" ) ;
171
+ expect ( map . symbolHandler . setSymbol ) . toHaveBeenCalled ( ) ;
172
+ } ) ;
173
+ it ( 'map.addLayer no symbol' , ( ) => {
174
+ const mylayer = {
175
+ "id" : "PopDensity_R@Population" ,
176
+ "source" : "全国人口密度空间分布图" ,
177
+ "source-layer" : "PopDensity_R@Population" ,
178
+ "type" : "fill" ,
179
+ "paint" : {
180
+ "fill-color" : "rgba(197,88,254,1.00)" ,
181
+ "fill-antialias" : true
182
+ }
183
+ }
184
+ spyOn ( map . style , 'addLayer' ) ;
185
+ spyOn ( map . style , 'getLayer' )
186
+ . withArgs ( "PopDensity_R@Population" )
187
+ . and . returnValue ( mylayer ) ; ;
188
+ map . addLayer ( mylayer ) ;
189
+ const layer = map . getLayer ( "PopDensity_R@Population" ) ;
190
+ expect ( layer ) . not . toBeNull ( ) ;
200
191
} ) ;
192
+
193
+ it ( 'map.addLayer symbol' , ( ) => {
194
+ spyOn ( map . style , 'addLayer' ) ;
195
+ spyOn ( map . style , 'addImage' ) ;
196
+ const mylayer = {
197
+ "id" : "PopDensity_P@Population" ,
198
+ "source" : "全国人口密度空间分布图" ,
199
+ "source-layer" : "PopDensity_R@Population" ,
200
+ "type" : "symbol" ,
201
+ "symbol" : "start"
202
+ }
203
+ spyOn ( map . style , 'getLayer' ) . and . returnValue ( mylayer ) ;
201
204
205
+ map . addSymbol ( "start" , { "layout" : { "icon-image" : "point-1" } } ) ;
206
+ map . addLayer ( mylayer ) ;
207
+ const layer = map . getLayer ( "PopDensity_P@Population" ) ;
208
+ expect ( layer ) . not . toBeNull ( ) ;
209
+ } ) ;
210
+
202
211
it ( 'setFilter' , ( ) => {
203
- map . getFilter ( "PopDensity_P@Population" ) ;
204
- map . setFilter ( "PopDensity_P@Population" , [ ] ) ;
205
- expect ( map . getFilter ( 'PopDensity_R@Population' ) ) . toBe ( undefined ) ;
206
- map . setFilter ( 'PopDensity_R@Population' , [
207
- "all" ,
208
- [
209
- "==" ,
210
- "$type" ,
211
- "LineString"
212
- ]
213
- ] ) ;
214
- expect ( map . getFilter ( 'PopDensity_R@Population' ) ) . toEqual ( [
215
- "all" ,
216
- [
217
- "==" ,
218
- "$type" ,
219
- "LineString"
220
- ]
221
- ] ) ;
212
+ spyOn ( map . style , 'setFilter' ) ;
213
+ spyOn ( map . style , 'getFilter' )
214
+ . and . returnValue ( [ 'all' , [ '==' , '$type' , 'LineString' ] ] ) ;
215
+ spyOn ( map . style , 'getLayer' )
216
+ . and . returnValue ( {
217
+ "id" : "PopDensity_P@Population" ,
218
+ "source" : "全国人口密度空间分布图" ,
219
+ "source-layer" : "PopDensity_R@Population" ,
220
+ "type" : "symbol" ,
221
+ } ) ;
222
+ map . setFilter ( 'PopDensity_R@Population' , [ 'all' , [ '==' , '$type' , 'LineString' ] ] ) ;
223
+ expect ( map . getFilter ( 'PopDensity_R@Population' ) ) . toEqual ( [ 'all' , [ '==' , '$type' , 'LineString' ] ] ) ;
222
224
} ) ;
225
+ it ( 'map.setLayoutProperty' , ( ) => {
226
+ const layerId = 'Landuse_R2' ;
223
227
224
- it ( 'map.setSymbol' , ( ) => {
225
- map . addSymbol ( "polygon" , [
226
- {
227
- paint : {
228
- 'fill-color' : "rgba(255, 0, 0, 0.5)"
229
- }
230
- } ,
231
- {
232
- paint : {
233
- 'fill-color' : "rgba(0, 0, 255, 0.5)"
234
- }
235
- }
236
- ] )
237
- expect ( map . getLayer ( "PopDensity_R@Population" ) . symbol ) . toBe ( undefined ) ;
238
- map . setSymbol ( "PopDensity_R@Population" , "polygon" ) ;
239
- expect ( map . getLayer ( "PopDensity_R@Population" ) . symbol ) . toBe ( "polygon" ) ;
240
- map . setLayerZoomRange ( 'PopDensity_R@Population' , 2 , 5 ) ;
241
- } )
228
+ spyOn ( map . style , 'getLayer' )
229
+ . and . returnValue ( layerId ) ;
230
+ spyOn ( map . style , 'setLayoutProperty' )
231
+ . and . returnValue ( null ) ;
242
232
243
- it ( 'setStyle' , ( ) => {
244
- map . setStyle ( {
245
- "version" : 8 ,
246
- "sources" : {
247
- "raster-tiles" : {
248
- "type" : "raster" ,
249
- "tiles" : [ url + '/zxyTileImage.png?z={z}&x={x}&y={y}' ] ,
250
- "tileSize" : 256
251
- } ,
252
- "全国人口密度空间分布图" : {
253
- "tiles" : [
254
- "http:/fake:8090/iserver/services/map-Population/rest/maps/PopulationDistribution/tileFeature.mvt?z={z}&x={x}&y={y}"
255
- ] ,
256
- "type" : "vector"
257
- }
258
- } ,
259
- "layers" : [ {
260
- "id" : "simple-tiles" ,
261
- "type" : "raster" ,
262
- "source" : "raster-tiles" ,
263
- "minzoom" : 0 ,
264
- "maxzoom" : 22
265
- } , {
266
- "id" : "PopDensity_P@Population" ,
267
- "source" : "全国人口密度空间分布图" ,
268
- "source-layer" : "PopDensity_R@Population" ,
269
- "type" : "symbol" ,
270
- "symbol" : "start"
271
- } ]
233
+ map . setLayoutProperty ( layerId , "line-join" , "miter" ) ;
234
+ expect ( map . style . setLayoutProperty ) . toHaveBeenCalled ( ) ;
235
+
236
+ spyOn ( map . style , 'getLayoutProperty' )
237
+ . withArgs ( layerId , "line-join" )
238
+ . and . returnValue ( "miter" ) ;
239
+ map . getLayoutProperty ( layerId , "line-join" ) ;
240
+ expect ( map . style . getLayoutProperty ) . toHaveBeenCalled ( ) ;
241
+ } ) ;
242
+ it ( 'map.setPaintProperty' , ( ) => {
243
+ spyOn ( map . style , 'getLayer' ) . and . returnValue ( {
244
+ id : 'PopDensity_P@Population'
272
245
} ) ;
273
- const layers = map . getStyle ( ) . layers ;
274
- expect ( layers . length ) . toBe ( 2 ) ;
275
- expect ( layers [ 1 ] . symbol ) . toBe ( "start" ) ;
276
- expect ( layers [ 0 ] . id ) . toBe ( "simple-tiles" ) ;
246
+ spyOn ( map . style , 'setPaintProperty' ) ;
247
+ spyOn ( map . style , 'getPaintProperty' ) ;
248
+ spyOn ( map , '_update' ) ;
249
+ map . setPaintProperty ( "PopDensity_R@Population" , "fill-color" , "black" ) ;
250
+ map . getPaintProperty ( "PopDensity_P@Population" , "fill-color" ) ;
251
+ expect ( map . style . setPaintProperty ) . toHaveBeenCalled ( ) ;
252
+ expect ( map . style . getPaintProperty ) . toHaveBeenCalled ( ) ;
277
253
} ) ;
254
+
278
255
} ) ;
0 commit comments