@@ -5,6 +5,7 @@ import { FetchRequest } from '../../../src/common/util/FetchRequest';
5
5
6
6
describe ( 'mapboxgl_InitMap' , ( ) => {
7
7
let originalTimeout , testDiv ;
8
+ const tokenQuery = 'token=opbFn8Nl5zUs2xhuCQ..' ;
8
9
9
10
beforeEach ( ( ) => {
10
11
spyOn ( mapboxgl , 'Map' ) . and . callFake ( mbglmap ) ;
@@ -251,7 +252,128 @@ describe('mapboxgl_InitMap', () => {
251
252
} ;
252
253
initMap ( tilesetServeRequest ) . then ( ( { map } ) => {
253
254
expect ( map ) . not . toBeNull ( ) ;
255
+ delete mapboxgl . CRS ;
256
+ delete mapboxgl . proj4 ;
254
257
done ( ) ;
255
258
} ) ;
256
259
} ) ;
260
+
261
+ it ( 'initMap raster when carring on token' , async ( ) => {
262
+ const restMapUrl = 'http:/fake:8090/iserver/iserver/services/map-china400/rest/maps/China' ;
263
+ const url = `${ restMapUrl } ?${ tokenQuery } ` ;
264
+ const mapServiceInfo = {
265
+ dynamicProjection : false ,
266
+ prjCoordSys : {
267
+ epsgCode : 3857
268
+ } ,
269
+ bounds : {
270
+ top : 20037508.342789087 ,
271
+ left : - 20037508.342789248 ,
272
+ bottom : - 20037508.34278914 ,
273
+ leftBottom : {
274
+ x : - 20037508.342789248 ,
275
+ y : - 20037508.34278914
276
+ } ,
277
+ right : 20037508.342789244 ,
278
+ rightTop : {
279
+ x : 20037508.342789244 ,
280
+ y : 20037508.342789087
281
+ }
282
+ } ,
283
+ center : {
284
+ x : - 7.450580596923828e-9 ,
285
+ y : - 2.60770320892334e-8
286
+ }
287
+ } ;
288
+ spyOn ( FetchRequest , 'get' ) . and . callFake ( ( url ) => {
289
+ expect ( url ) . toContain ( tokenQuery ) ;
290
+ if ( url . indexOf ( '/tilesets' ) > - 1 ) {
291
+ return Promise . resolve ( new Response ( tilesetInfo_1 ) ) ;
292
+ }
293
+ return Promise . resolve ( new Response ( JSON . stringify ( mapServiceInfo ) ) ) ;
294
+ } ) ;
295
+ const resData = await initMap ( url ) ;
296
+ const map = resData . map ;
297
+ expect ( map ) . not . toBeUndefined ( ) ;
298
+ expect ( map . options . crs ) . toBe ( `EPSG:${ mapServiceInfo . prjCoordSys . epsgCode } ` ) ;
299
+ expect ( map . options . center ) . toEqual ( [ - 6.692970425781022e-14 , - 2.2899993706537323e-13 ] ) ;
300
+ expect ( Object . values ( map . options . style . sources ) . length ) . toBe ( 1 ) ;
301
+ expect ( map . options . style . layers . length ) . toBe ( 1 ) ;
302
+ expect ( Object . values ( map . options . style . sources ) [ 0 ] . tiles . length ) . toBe ( 1 ) ;
303
+ expect ( Object . values ( map . options . style . sources ) [ 0 ] . tiles [ 0 ] ) . toBe (
304
+ `${ restMapUrl } /zxyTileImage.png?${ tokenQuery } &z={z}&x={x}&y={y}&width=256&height=256&transparent=true`
305
+ ) ;
306
+ } ) ;
307
+
308
+ it ( 'initMap vector tile when carring on token' , async ( ) => {
309
+ const restMapUrl = 'http:/fake:8090/iserver/services/map-mvt-landuse/rest/maps/landuse' ;
310
+ const url = `${ restMapUrl } ?${ tokenQuery } ` ;
311
+ const mapServiceInfo = {
312
+ dynamicProjection : false ,
313
+ prjCoordSys : {
314
+ epsgCode : 4326
315
+ } ,
316
+ center : {
317
+ x : 116 ,
318
+ y : 39
319
+ } ,
320
+ bounds : {
321
+ top : 90.00000000000001 ,
322
+ left : - 180 ,
323
+ bottom : - 90.00000000003598 ,
324
+ leftBottom : { x : - 180 , y : - 90.00000000003598 } ,
325
+ right : 180.00000000007202 ,
326
+ rightTop : { x : 180.00000000007202 , y : 90.00000000000001 }
327
+ }
328
+ } ;
329
+ const vectorStyleUrl =
330
+ `${ restMapUrl } /tileFeature/vectorstyles.json?${ tokenQuery } &type=MapBox_GL&styleonly=true&tileURLTemplate=ZXY` ;
331
+ const WKT =
332
+ 'GEOGCS["China Geodetic Coordinate System 2000",DATUM["China_2000",SPHEROID["CGCS2000",6378137,298.257222101,AUTHORITY["EPSG","1024"]],AUTHORITY["EPSG","1043"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4490"]]' ;
333
+ spyOn ( FetchRequest , 'get' ) . and . callFake ( ( acceptUrl ) => {
334
+ if ( acceptUrl === `${ restMapUrl } /prjCoordSys.wkt?${ tokenQuery } ` ) {
335
+ return Promise . resolve ( new Response ( WKT ) ) ;
336
+ }
337
+ if ( acceptUrl === vectorStyleUrl ) {
338
+ return Promise . resolve ( new Response ( JSON . stringify ( { } ) ) ) ;
339
+ }
340
+ if ( acceptUrl === `${ restMapUrl } /prjCoordSys/projection/extent.json?${ tokenQuery } ` ) {
341
+ return Promise . resolve (
342
+ new Response (
343
+ JSON . stringify ( {
344
+ top : 2.0037508342789244e7 ,
345
+ left : - 2.0037508342789244e7 ,
346
+ bottom : - 2.0037508342789244e7 ,
347
+ leftBottom : {
348
+ x : - 2.0037508342789244e7 ,
349
+ y : - 2.0037508342789244e7
350
+ } ,
351
+ right : 2.0037508342789244e7 ,
352
+ rightTop : {
353
+ x : 2.0037508342789244e7 ,
354
+ y : 2.0037508342789244e7
355
+ } ,
356
+ center : [ 120 , 39 ]
357
+ } )
358
+ )
359
+ ) ;
360
+ }
361
+ return Promise . resolve ( new Response ( JSON . stringify ( mapServiceInfo ) ) ) ;
362
+ } ) ;
363
+ mapboxgl . CRS = function ( ) {
364
+ return {
365
+ code : mapServiceInfo . prjCoordSys . epsgCode
366
+ } ;
367
+ } ;
368
+ mapboxgl . proj4 = function ( ) {
369
+ return [ 0 , 0 ] ;
370
+ } ;
371
+ const resData = await initMap ( url , { type : 'vector-tile' } ) ;
372
+ const map = resData . map ;
373
+ expect ( map ) . not . toBeUndefined ( ) ;
374
+ expect ( map . options . crs . code ) . toBe ( mapServiceInfo . prjCoordSys . epsgCode ) ;
375
+ expect ( map . options . style ) . toBe ( vectorStyleUrl ) ;
376
+ delete mapboxgl . CRS ;
377
+ delete mapboxgl . proj4 ;
378
+ } ) ;
257
379
} ) ;
0 commit comments