1+ import mapboxgl from 'mapbox-gl' ;
12import { WebMap } from '../../../src/mapboxgl/mapping/WebMap' ;
23import { WebMap as WebMapV3 } from '../../../src/mapboxgl/mapping/webmap/v3/WebMap' ;
34import '../../resources/WebMapV3.js' ;
@@ -22,9 +23,9 @@ describe('mapboxgl-webmap3.0', () => {
2223 } ) ;
2324 afterEach ( ( ) => {
2425 if ( mapstudioWebmap && mapstudioWebmap . map ) {
25- const webMapV3 = mapstudioWebmap . _getWebMapInstance ? mapstudioWebmap . _getWebMapInstance ( ) : mapstudioWebmap ;
26- webMapV3 . clean && webMapV3 . clean ( ) ;
27- mapstudioWebmap = null ;
26+ const webMapV3 = mapstudioWebmap . _getWebMapInstance ? mapstudioWebmap . _getWebMapInstance ( ) : mapstudioWebmap ;
27+ webMapV3 . clean && webMapV3 . clean ( ) ;
28+ mapstudioWebmap = null ;
2829 }
2930 window . document . body . removeChild ( testDiv ) ;
3031 jasmine . DEFAULT_TIMEOUT_INTERVAL = originalTimeout ;
@@ -50,7 +51,7 @@ describe('mapboxgl-webmap3.0', () => {
5051 expect ( mapstudioWebmap . map ) . toEqual ( map ) ;
5152 expect ( mapstudioWebmap . mapParams . title ) . toBe ( '空地图' ) ;
5253 expect ( mapstudioWebmap . mapParams . description ) . toBe ( '' ) ;
53- var style = map . getStyle ( ) ;
54+ const style = map . getStyle ( ) ;
5455 expect ( style . name ) . toBe ( mapstudioWebmap . mapParams . title ) ;
5556 expect ( style . layers . length ) . toBe ( 1 ) ;
5657 expect ( style . sources ) . toEqual ( { } ) ;
@@ -85,7 +86,7 @@ describe('mapboxgl-webmap3.0', () => {
8586 expect ( + center . lng . toFixed ( 4 ) ) . toEqual ( 116.3949 ) ;
8687 expect ( mapstudioWebmap . mapParams . title ) . toBe ( 'restmap服务' ) ;
8788 expect ( mapstudioWebmap . mapParams . description ) . toBe ( '' ) ;
88- var style = map . getStyle ( ) ;
89+ const style = map . getStyle ( ) ;
8990 expect ( style . name ) . toBe ( mapstudioWebmap . mapParams . title ) ;
9091 expect ( style . layers . length ) . toBe ( 2 ) ;
9192 done ( ) ;
@@ -110,14 +111,13 @@ describe('mapboxgl-webmap3.0', () => {
110111 mapstudioWebmap . on ( 'addlayerssucceeded' , ( { map } ) => {
111112 expect ( map ) . not . toBeUndefined ( ) ;
112113 expect ( mapstudioWebmap . map ) . toEqual ( map ) ;
113- var style = map . getStyle ( ) ;
114+ const style = map . getStyle ( ) ;
114115 const webMapV3 = mapstudioWebmap . _getWebMapInstance ( ) ;
115116 const mapInfo = JSON . parse ( mapstudioWebMap_symbol ) ;
116117 expect ( style . layers . length ) . toBe ( mapInfo . layers . length ) ;
117118 expect ( webMapV3 . getAppreciableLayers ( ) . length ) . toBeGreaterThanOrEqual ( mapInfo . layers . length ) ;
118119 expect ( webMapV3 . getLegendInfo ( ) . length ) . not . toBe ( 0 ) ;
119120 expect ( webMapV3 . getLayerCatalog ( ) . length ) . not . toBe ( 0 ) ;
120- expect ( webMapV3 . getLegendInfo ( ) . length ) . not . toBe ( 0 ) ;
121121 done ( ) ;
122122 } ) ;
123123 } ) ;
@@ -139,7 +139,7 @@ describe('mapboxgl-webmap3.0', () => {
139139 mapstudioWebmap . on ( 'addlayerssucceeded' , ( { map } ) => {
140140 expect ( map ) . not . toBeUndefined ( ) ;
141141 expect ( mapstudioWebmap . map ) . toEqual ( map ) ;
142- var style = map . getStyle ( ) ;
142+ const style = map . getStyle ( ) ;
143143 expect ( style . layers . length ) . toBe ( mapInfo . layers . length ) ;
144144 const appreciableLayers = mapstudioWebmap . getAppreciableLayers ( ) ;
145145 const layerCatalogs = mapstudioWebmap . getLayerCatalog ( ) ;
@@ -159,4 +159,124 @@ describe('mapboxgl-webmap3.0', () => {
159159 done ( ) ;
160160 } ) ;
161161 } ) ;
162+
163+ it ( 'projection is 4490 and not include mapbox-gl-enhance' , ( done ) => {
164+ const mapInfo = JSON . parse ( mapstudioWebMap_symbol ) ;
165+ const nextMapInfo = {
166+ ...mapInfo ,
167+ crs : {
168+ name : 'EPSG:4490' ,
169+ extent : [ - 180 , - 270 , 180 , 90 ] ,
170+ wkt : 'GEOGCS["China Geodetic Coordinate System 2000", DATUM["China 2000", SPHEROID["CGCS2000", 6378137.0, 298.257222101, AUTHORITY["EPSG","1024"]], AUTHORITY["EPSG","1043"]], PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], UNIT["degree", 0.017453292519943295], AXIS["Geodetic latitude", NORTH], AXIS["Geodetic longitude", EAST], AUTHORITY["EPSG","4490"]]'
171+ }
172+ } ;
173+ mapstudioWebmap = new WebMapV3 ( nextMapInfo , {
174+ server : server ,
175+ target : 'map'
176+ } ) ;
177+ mapstudioWebmap . on ( 'getmapinfofailed' , ( { error } ) => {
178+ const throwError = `The EPSG code ${ nextMapInfo . crs . name } needs to include mapbox-gl-enhance.js. Refer to the example: https://iclient.supermap.io/examples/mapboxgl/editor.html#mvtVectorTile_2362` ;
179+ expect ( mapstudioWebmap . map ) . toBeUndefined ( ) ;
180+ expect ( error ) . toBe ( throwError ) ;
181+ done ( ) ;
182+ } ) ;
183+ mapstudioWebmap . initializeMap ( nextMapInfo ) ;
184+ } ) ;
185+
186+ it ( 'projection is 4490 and include mapbox-gl-enhance' , ( done ) => {
187+ spyOn ( FetchRequest , 'get' ) . and . callFake ( ( url ) => {
188+ if ( url . indexOf ( '/sprite' ) > - 1 ) {
189+ return Promise . resolve ( new Response ( msSpriteInfo ) ) ;
190+ }
191+ return Promise . resolve ( ) ;
192+ } ) ;
193+ const mapInfo = JSON . parse ( mapstudioWebMap_symbol ) ;
194+ const nextMapInfo = {
195+ ...mapInfo ,
196+ crs : {
197+ name : 'EPSG:4490' ,
198+ extent : [ - 180 , - 270 , 180 , 90 ] ,
199+ wkt : 'GEOGCS["China Geodetic Coordinate System 2000", DATUM["China 2000", SPHEROID["CGCS2000", 6378137.0, 298.257222101, AUTHORITY["EPSG","1024"]], AUTHORITY["EPSG","1043"]], PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], UNIT["degree", 0.017453292519943295], AXIS["Geodetic latitude", NORTH], AXIS["Geodetic longitude", EAST], AUTHORITY["EPSG","4490"]]'
200+ }
201+ } ;
202+ mapboxgl . CRS = function ( epsgCode , wkt , bounds , unit ) {
203+ expect ( epsgCode ) . toBe ( nextMapInfo . crs . name ) ;
204+ expect ( wkt ) . toBe ( nextMapInfo . crs . wkt ) ;
205+ expect ( bounds ) . toEqual ( nextMapInfo . crs . extent ) ;
206+ expect ( unit ) . toBe ( nextMapInfo . crs . extent [ 2 ] > 180 ? 'meter' : 'degree' ) ;
207+ } ;
208+ mapboxgl . CRS . set = function ( ) { } ;
209+ mapstudioWebmap = new WebMapV3 ( nextMapInfo , {
210+ server : server ,
211+ target : 'map'
212+ } ) ;
213+ mapstudioWebmap . initializeMap ( nextMapInfo ) ;
214+
215+ mapstudioWebmap . on ( 'addlayerssucceeded' , ( { map } ) => {
216+ expect ( map ) . not . toBeUndefined ( ) ;
217+ expect ( mapstudioWebmap . map ) . toEqual ( map ) ;
218+ const style = map . getStyle ( ) ;
219+ expect ( style . layers . length ) . toBe ( nextMapInfo . layers . length ) ;
220+ const appreciableLayers = mapstudioWebmap . getAppreciableLayers ( ) ;
221+ const layerCatalogs = mapstudioWebmap . getLayerCatalog ( ) ;
222+ expect ( appreciableLayers . length ) . toBeGreaterThanOrEqual ( nextMapInfo . layers . length ) ;
223+ expect ( layerCatalogs . length ) . toBeLessThanOrEqual ( appreciableLayers . length ) ;
224+ expect ( mapstudioWebmap . getLegendInfo ( ) . length ) . toBe ( 0 ) ;
225+ delete mapboxgl . CRS ;
226+ done ( ) ;
227+ } ) ;
228+ } ) ;
229+
230+ it ( 'overlayLayersManager' , ( done ) => {
231+ spyOn ( FetchRequest , 'get' ) . and . callFake ( ( url ) => {
232+ if ( url . indexOf ( '/sprite' ) > - 1 ) {
233+ return Promise . resolve ( new Response ( msSpriteInfo ) ) ;
234+ }
235+ return Promise . resolve ( ) ;
236+ } ) ;
237+ const mapInfo = JSON . parse ( mapstudioWebMap_symbol ) ;
238+ mapstudioWebmap = new WebMapV3 ( mapInfo , {
239+ server : server ,
240+ target : 'map'
241+ } ) ;
242+ mapstudioWebmap . initializeMap ( mapInfo ) ;
243+
244+ mapstudioWebmap . on ( 'addlayerssucceeded' , ( { map } ) => {
245+ expect ( map ) . not . toBeUndefined ( ) ;
246+ expect ( mapstudioWebmap . map ) . toEqual ( map ) ;
247+ const style = map . getStyle ( ) ;
248+ expect ( style . layers . length ) . toBe ( mapInfo . layers . length ) ;
249+ const appreciableLayers = mapstudioWebmap . getAppreciableLayers ( ) ;
250+ const layerCatalogs = mapstudioWebmap . getLayerCatalog ( ) ;
251+ expect ( appreciableLayers . length ) . toBeGreaterThanOrEqual ( mapInfo . layers . length ) ;
252+ expect ( layerCatalogs . length ) . toBeLessThanOrEqual ( appreciableLayers . length ) ;
253+ expect ( mapstudioWebmap . getLegendInfo ( ) . length ) . toBe ( 0 ) ;
254+ map . overlayLayersManager = {
255+ GraticuleLayer : {
256+ id : 'GraticuleLayer' ,
257+ overlay : true ,
258+ sourceId : 'GraticuleLayer' ,
259+ visible : true
260+ } ,
261+ EchartLayer : {
262+ id : 'EchartLayer' ,
263+ visibility : 'visible' ,
264+ source : {
265+ type : 'geoJSON' ,
266+ data : null
267+ }
268+ } ,
269+ GraticuleLayer1 : {
270+ id : 'GraticuleLayer' ,
271+ overlay : true ,
272+ sourceId : 'GraticuleLayer'
273+ }
274+ } ;
275+ const appreciableLayers2 = mapstudioWebmap . getAppreciableLayers ( ) ;
276+ expect ( appreciableLayers2 . length ) . toBe ( appreciableLayers . length + 2 ) ;
277+ expect ( mapstudioWebmap . getLayerCatalog ( ) . length ) . toBe ( layerCatalogs . length + 2 ) ;
278+ expect ( appreciableLayers2 . find ( ( item ) => item . renderSource . id === 'EchartLayer' ) ) . toBeTruthy ( ) ;
279+ done ( ) ;
280+ } ) ;
281+ } ) ;
162282} ) ;
0 commit comments