1- import { VectorTileSuperMapRest } from '../../../src/openlayers/overlay/VectorTileSuperMapRest' ;
2- import { MapService } from '../../../src/openlayers/services/MapService' ;
1+ import { VectorTileSuperMapRest } from '../../../src/openlayers/overlay/VectorTileSuperMapRest' ;
2+ import {
3+ FetchRequest
4+ } from '@supermap/iclient-common/util/FetchRequest' ;
5+ import { MapService } from '../../../src/openlayers/services/MapService' ;
36import Map from 'ol/Map' ;
47import View from 'ol/View' ;
58import VectorTileLayer from 'ol/layer/VectorTile' ;
69
710var url = GlobeParameter . ChinaURL ;
11+ const mapObject = {
12+ "viewBounds" : {
13+ "top" : 1.0018754171380693E7 ,
14+ "left" : - 1.0018754171380727E7 ,
15+ "bottom" : - 1.0018754171380745E7 ,
16+ "leftBottom" : {
17+ "x" : - 1.0018754171380727E7 ,
18+ "y" : - 1.0018754171380745E7
19+ } ,
20+ "right" : 1.0018754171380712E7 ,
21+ "rightTop" : {
22+ "x" : 1.0018754171380712E7 ,
23+ "y" : 1.0018754171380693E7
24+ }
25+ } , "bounds" : {
26+ "top" : 2.0037508342789087E7 ,
27+ "left" : - 2.0037508342789248E7 ,
28+ "bottom" : - 2.003750834278914E7 ,
29+ "leftBottom" : {
30+ "x" : - 2.0037508342789248E7 ,
31+ "y" : - 2.003750834278914E7
32+ } ,
33+ "right" : 2.0037508342789244E7 ,
34+ "rightTop" : {
35+ "x" : 2.0037508342789244E7 ,
36+ "y" : 2.0037508342789087E7
37+ }
38+ } , "viewer" : {
39+ "leftTop" : {
40+ "x" : 0 ,
41+ "y" : 0
42+ } ,
43+ "top" : 0 ,
44+ "left" : 0 ,
45+ "bottom" : 256 ,
46+ "rightBottom" : {
47+ "x" : 256 ,
48+ "y" : 256
49+ } ,
50+ "width" : 256 ,
51+ "right" : 256 ,
52+ "height" : 256
53+ } , "coordUnit" : "METER" , visibleScales : [ ] ,
54+ }
855describe ( 'openlayers_VectorTileSuperMapRest' , ( ) => {
9- var testDiv , map , vectorTileOptions , vectorTileSource , originalTimeout , vectorLayer ;
56+ var testDiv , map , vectorTileOptions , vectorTileSource , originalTimeout , vectorLayer ;
1057 beforeAll ( ( ) => {
1158 testDiv = window . document . createElement ( "div" ) ;
1259 testDiv . setAttribute ( "id" , "map" ) ;
@@ -16,11 +63,14 @@ describe('openlayers_VectorTileSuperMapRest', () => {
1663 testDiv . style . width = "500px" ;
1764 testDiv . style . height = "500px" ;
1865 window . document . body . appendChild ( testDiv ) ;
19-
66+ spyOn ( FetchRequest , 'get' ) . and . callFake ( ( testUrl , params , options ) => {
67+ return Promise . resolve ( new Response ( JSON . stringify ( mapObject ) ) ) ;
68+ } ) ;
69+
2070 } ) ;
2171 beforeEach ( ( ) => {
2272 originalTimeout = jasmine . DEFAULT_TIMEOUT_INTERVAL ;
23- jasmine . DEFAULT_TIMEOUT_INTERVAL = 50000 ;
73+ jasmine . DEFAULT_TIMEOUT_INTERVAL = 5000 ;
2474 } ) ;
2575 afterEach ( ( ) => {
2676 if ( vectorLayer ) {
@@ -42,26 +92,35 @@ describe('openlayers_VectorTileSuperMapRest', () => {
4292 } )
4393 } ) ;
4494 vectorTileOptions = VectorTileSuperMapRest . optionsFromMapJSON ( url , serviceResult . result ) ;
95+ vectorTileOptions . tileLoadFunction = ( tile ) => {
96+ tile . setLoader ( ( ) => {
97+ tile . setFeatures ( [ ] )
98+ } )
99+ } ;
45100 vectorTileSource = new VectorTileSuperMapRest ( vectorTileOptions ) ;
101+ vectorTileSource . once ( 'tileloadend' , ( ) => {
102+ expect ( vectorTileOptions ) . not . toBeNull ( ) ;
103+ expect ( vectorTileOptions . crossOrigin ) . toBe ( "anonymous" ) ;
104+ expect ( vectorTileSource ) . not . toBeNull ( ) ;
105+ done ( ) ;
106+ } )
46107 vectorLayer = new VectorTileLayer ( {
47108 source : vectorTileSource
48109 } ) ;
49110 map . addLayer ( vectorLayer ) ;
111+
112+
50113 } ) ;
51- setTimeout ( ( ) => {
52- try {
53- expect ( vectorTileOptions ) . not . toBeNull ( ) ;
54- expect ( vectorTileOptions . crossOrigin ) . toBe ( "anonymous" ) ;
55- expect ( vectorTileSource ) . not . toBeNull ( ) ;
56- done ( ) ;
57- } catch ( exception ) {
58- console . log ( "'initialize'案例失败:" + exception . name + ":" + exception . message ) ;
59- expect ( false ) . toBeTruthy ( ) ;
60- }
61- } , 0 ) ;
114+
62115 } ) ;
63116 it ( 'custom_tileLoadFunction' , ( done ) => {
64- var tileLoadFunction = jasmine . createSpy ( 'tileLoadFunction' ) ;
117+ var spy = jasmine . createSpy ( 'test' )
118+ var tileLoadFunction = ( tile ) => {
119+ tile . setLoader ( ( ) => {
120+ spy ( ) ;
121+ tile . setFeatures ( [ ] )
122+ } )
123+ } ;
65124 new MapService ( url ) . getMapInfo ( ( serviceResult ) => {
66125 map = new Map ( {
67126 target : 'map' ,
@@ -77,18 +136,14 @@ describe('openlayers_VectorTileSuperMapRest', () => {
77136 source : vectorTileSource
78137 } ) ;
79138 map . addLayer ( vectorLayer ) ;
80- } ) ;
81- setTimeout ( ( ) => {
82- try {
139+ vectorLayer . getSource ( ) . once ( 'tileloadend' , ( ) => {
83140 expect ( vectorTileOptions ) . not . toBeNull ( ) ;
84- expect ( vectorTileSource ) . not . toBeNull ( ) ;
85- expect ( tileLoadFunction ) . toHaveBeenCalled ( ) ;
141+ expect ( spy ) . toHaveBeenCalled ( ) ;
86142 done ( ) ;
87- } catch ( exception ) {
88- console . log ( "'initialize'案例失败:" + exception . name + ":" + exception . message ) ;
89- expect ( false ) . toBeTruthy ( ) ;
90- done ( ) ;
91- }
92- } , 0 ) ;
143+
144+ } )
145+ } ) ;
146+
147+
93148 } ) ;
94149} ) ;
0 commit comments