@@ -3,8 +3,9 @@ import mbglmap from '../../tool/mock_mapboxgl_map';
33import { initMap } from '../../../src/mapboxgl/mapping/InitMap' ;
44import { FetchRequest } from '../../../src/common/util/FetchRequest' ;
55
6- describe ( 'InitMap' , ( ) => {
6+ describe ( 'mapboxgl InitMap' , ( ) => {
77 let originalTimeout , testDiv ;
8+ const tokenQuery = 'token=opbFn8Nl5zUs2xhuCQ..' ;
89
910 beforeEach ( ( ) => {
1011 spyOn ( mapboxgl , 'Map' ) . and . callFake ( mbglmap ) ;
@@ -223,4 +224,120 @@ describe('InitMap', () => {
223224 delete mapboxgl . CRS ;
224225 delete mapboxgl . proj4 ;
225226 } ) ;
227+
228+ it ( 'initMap raster when carring on token' , async ( ) => {
229+ const restMapUrl = 'http:/fake:8090/iserver/iserver/services/map-china400/rest/maps/China' ;
230+ const url = `${ restMapUrl } ?${ tokenQuery } ` ;
231+ const mapServiceInfo = {
232+ dynamicProjection : false ,
233+ prjCoordSys : {
234+ epsgCode : 3857
235+ } ,
236+ bounds : {
237+ top : 20037508.342789087 ,
238+ left : - 20037508.342789248 ,
239+ bottom : - 20037508.34278914 ,
240+ leftBottom : {
241+ x : - 20037508.342789248 ,
242+ y : - 20037508.34278914
243+ } ,
244+ right : 20037508.342789244 ,
245+ rightTop : {
246+ x : 20037508.342789244 ,
247+ y : 20037508.342789087
248+ }
249+ } ,
250+ center : {
251+ x : - 7.450580596923828e-9 ,
252+ y : - 2.60770320892334e-8
253+ }
254+ } ;
255+ spyOn ( FetchRequest , 'get' ) . and . callFake ( ( url ) => {
256+ expect ( url ) . toContain ( tokenQuery ) ;
257+ return Promise . resolve ( new Response ( JSON . stringify ( mapServiceInfo ) ) ) ;
258+ } ) ;
259+ const resData = await initMap ( url ) ;
260+ const map = resData . map ;
261+ expect ( map ) . not . toBeUndefined ( ) ;
262+ expect ( map . options . crs ) . toBe ( 'EPSG:3857' ) ;
263+ expect ( map . options . center ) . toEqual ( [ - 6.692970425781022e-14 , - 2.2899993706537323e-13 ] ) ;
264+ expect ( Object . values ( map . options . style . sources ) . length ) . toBe ( 1 ) ;
265+ expect ( map . options . style . layers . length ) . toBe ( 1 ) ;
266+ expect ( Object . values ( map . options . style . sources ) [ 0 ] . tiles . length ) . toBe ( 1 ) ;
267+ expect ( Object . values ( map . options . style . sources ) [ 0 ] . tiles [ 0 ] ) . toBe (
268+ `${ restMapUrl } /zxyTileImage.png?${ tokenQuery } &z={z}&x={x}&y={y}&width=256&height=256&transparent=true`
269+ ) ;
270+ } ) ;
271+
272+ it ( 'initMap vector tile when carring on token' , async ( ) => {
273+ const restMapUrl = 'http:/fake:8090/iserver/services/map-mvt-landuse/rest/maps/landuse' ;
274+ const url = `${ restMapUrl } ?${ tokenQuery } ` ;
275+ const mapServiceInfo = {
276+ dynamicProjection : false ,
277+ prjCoordSys : {
278+ epsgCode : 4326
279+ } ,
280+ center : {
281+ x : 116 ,
282+ y : 39
283+ } ,
284+ bounds : {
285+ top : 90.00000000000001 ,
286+ left : - 180 ,
287+ bottom : - 90.00000000003598 ,
288+ leftBottom : { x : - 180 , y : - 90.00000000003598 } ,
289+ right : 180.00000000007202 ,
290+ rightTop : { x : 180.00000000007202 , y : 90.00000000000001 }
291+ }
292+ } ;
293+ const vectorStyleUrl =
294+ `${ restMapUrl } /tileFeature/vectorstyles.json?${ tokenQuery } &type=MapBox_GL&styleonly=true&tileURLTemplate=ZXY` ;
295+ const WKT =
296+ '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"]]' ;
297+ spyOn ( FetchRequest , 'get' ) . and . callFake ( ( acceptUrl ) => {
298+ if ( acceptUrl === `${ restMapUrl } /prjCoordSys.wkt?${ tokenQuery } ` ) {
299+ return Promise . resolve ( new Response ( WKT ) ) ;
300+ }
301+ if ( acceptUrl === vectorStyleUrl ) {
302+ return Promise . resolve ( new Response ( JSON . stringify ( { } ) ) ) ;
303+ }
304+ if ( acceptUrl === `${ restMapUrl } /prjCoordSys/projection/extent.json?${ tokenQuery } ` ) {
305+ return Promise . resolve (
306+ new Response (
307+ JSON . stringify ( {
308+ top : 2.0037508342789244e7 ,
309+ left : - 2.0037508342789244e7 ,
310+ bottom : - 2.0037508342789244e7 ,
311+ leftBottom : {
312+ x : - 2.0037508342789244e7 ,
313+ y : - 2.0037508342789244e7
314+ } ,
315+ right : 2.0037508342789244e7 ,
316+ rightTop : {
317+ x : 2.0037508342789244e7 ,
318+ y : 2.0037508342789244e7
319+ } ,
320+ center : [ 120 , 39 ]
321+ } )
322+ )
323+ ) ;
324+ }
325+ return Promise . resolve ( new Response ( JSON . stringify ( mapServiceInfo ) ) ) ;
326+ } ) ;
327+ mapboxgl . CRS = function ( ) {
328+ return {
329+ code : mapServiceInfo . prjCoordSys . epsgCode
330+ } ;
331+ } ;
332+ mapboxgl . proj4 = function ( ) {
333+ return [ 0 , 0 ] ;
334+ } ;
335+ const resData = await initMap ( url , { type : 'vector-tile' } ) ;
336+ const map = resData . map ;
337+ expect ( map ) . not . toBeUndefined ( ) ;
338+ expect ( map . options . crs . code ) . toBe ( mapServiceInfo . prjCoordSys . epsgCode ) ;
339+ expect ( map . options . style ) . toBe ( vectorStyleUrl ) ;
340+ delete mapboxgl . CRS ;
341+ delete mapboxgl . proj4 ;
342+ } ) ;
226343} ) ;
0 commit comments