@@ -7,6 +7,7 @@ import View from 'ol/View';
77import MVT from 'ol/format/MVT' ;
88import Feature from 'ol/Feature' ;
99import VectorTileLayer from 'ol/layer/VectorTile' ;
10+ import TileGrid from 'ol/tilegrid/TileGrid' ;
1011
1112var url = GlobeParameter . ChinaURL ;
1213const mapObject = {
@@ -105,7 +106,7 @@ describe('openlayers_VectorTileSuperMapRest', () => {
105106 map . removeLayer ( vectorLayer ) ;
106107 }
107108 jasmine . DEFAULT_TIMEOUT_INTERVAL = originalTimeout ;
108- spyGet . calls . reset ( ) ;
109+ spyGet && spyGet . calls . reset ( ) ;
109110 spyPost . calls . reset ( ) ;
110111 spyCommit . calls . reset ( ) ;
111112 } ) ;
@@ -294,4 +295,93 @@ describe('openlayers_VectorTileSuperMapRest', () => {
294295 } ) ;
295296 } ) ;
296297 } ) ;
298+ const style = {
299+ "version" : 8 ,
300+ "name" : "" ,
301+ "center" : [ 0 , 0 ] ,
302+ "zoom" : 2 ,
303+ "metadata" : {
304+ "indexbounds" : [ - 400000 , - 400000 , 400000 , 400000 ]
305+ } ,
306+ "sources" : {
307+ "aaa" : {
308+ "tiles" : [ "http://127.0.0.1:5566/tiles/{z}/{x}/{y}.mvt" ] ,
309+ "type" : "vector"
310+ }
311+ } ,
312+ "layers" : [ {
313+ "id" : "区级政面0_24" ,
314+ "source" : "矢量切片" ,
315+ "source-layer" : "区级政面@矢量" ,
316+ "minzoom" : 0.0 ,
317+ "maxzoom" : 24.0 ,
318+ "type" : "fill" ,
319+ "layout" : {
320+ "visibility" : "visible"
321+ }
322+ } ]
323+ } ;
324+ it ( 'initialize_with_tilegrid_and_metadata_indexbounds' , ( done ) => {
325+ map = new Map ( {
326+ target : 'map' ,
327+ view : new View ( {
328+ center : [ 0 , 0 ] ,
329+ zoom : 2
330+ } )
331+ } ) ;
332+ vectorTileOptions = {
333+ style : style ,
334+ tileGrid : new TileGrid ( {
335+ resolutions : [ 100000 , 50000 ] ,
336+ origin : [ - 4823200 , 6183000 ] ,
337+ tileSize : 512 ,
338+ } ) ,
339+ format : new ol . format . MVT ( ) ,
340+ }
341+ vectorTileOptions . tileLoadFunction = ( tile ) => {
342+ tile . setLoader ( ( ) => {
343+ tile . setFeatures ( [ ] ) ;
344+ } ) ;
345+ } ;
346+ vectorTileSource = new VectorTileSuperMapRest ( vectorTileOptions ) ;
347+ vectorTileSource . once ( 'tileloadstart' , ( ) => {
348+ expect ( vectorTileSource ) . not . toBeNull ( ) ;
349+ expect ( vectorTileSource . getTileGrid ( ) . getResolutions ( ) [ 0 ] ) . toBe ( 100000 )
350+ done ( ) ;
351+ } ) ;
352+ vectorLayer = new VectorTileLayer ( {
353+ source : vectorTileSource
354+ } ) ;
355+ map . addLayer ( vectorLayer ) ;
356+ } ) ;
357+
358+
359+ it ( 'initialize_without_tilegrid_but_metadata_indexbounds' , ( done ) => {
360+ map = new Map ( {
361+ target : 'map' ,
362+ view : new View ( {
363+ center : [ 0 , 0 ] ,
364+ zoom : 2
365+ } )
366+ } ) ;
367+ vectorTileOptions = {
368+ style : style ,
369+ format : new ol . format . MVT ( ) ,
370+ }
371+ vectorTileOptions . tileLoadFunction = ( tile ) => {
372+ tile . setLoader ( ( ) => {
373+ tile . setFeatures ( [ ] ) ;
374+ } ) ;
375+ } ;
376+ vectorTileSource = new VectorTileSuperMapRest ( vectorTileOptions ) ;
377+ vectorTileSource . once ( 'tileloadstart' , ( ) => {
378+ expect ( vectorTileSource ) . not . toBeNull ( ) ;
379+ expect ( vectorTileSource . getTileGrid ( ) . getResolutions ( ) [ 0 ] ) . toBe ( ( 400000 - ( - 400000 ) ) / 512 )
380+ done ( ) ;
381+ } ) ;
382+ vectorLayer = new VectorTileLayer ( {
383+ source : vectorTileSource
384+ } ) ;
385+ map . addLayer ( vectorLayer ) ;
386+ } ) ;
297387} ) ;
0 commit comments