@@ -6,7 +6,7 @@ import VectorTileLayer from 'ol/layer/VectorTile';
66
77var url = GlobeParameter . ChinaURL ;
88describe ( 'openlayers_VectorTileSuperMapRest' , ( ) => {
9- var testDiv , map , vectorTileOptions , vectorTileSource , originalTimeout ;
9+ var testDiv , map , vectorTileOptions , vectorTileSource , originalTimeout , vectorLayer ;
1010 beforeAll ( ( ) => {
1111 testDiv = window . document . createElement ( "div" ) ;
1212 testDiv . setAttribute ( "id" , "map" ) ;
@@ -16,6 +16,23 @@ describe('openlayers_VectorTileSuperMapRest', () => {
1616 testDiv . style . width = "500px" ;
1717 testDiv . style . height = "500px" ;
1818 window . document . body . appendChild ( testDiv ) ;
19+
20+ } ) ;
21+ beforeEach ( ( ) => {
22+ originalTimeout = jasmine . DEFAULT_TIMEOUT_INTERVAL ;
23+ jasmine . DEFAULT_TIMEOUT_INTERVAL = 50000 ;
24+ } ) ;
25+ afterEach ( ( ) => {
26+ if ( vectorLayer ) {
27+ map . removeLayer ( vectorLayer ) ;
28+ }
29+ jasmine . DEFAULT_TIMEOUT_INTERVAL = originalTimeout ;
30+ } ) ;
31+ afterAll ( ( ) => {
32+ window . document . body . removeChild ( testDiv ) ;
33+ } ) ;
34+
35+ it ( 'initialize' , ( done ) => {
1936 new MapService ( url ) . getMapInfo ( ( serviceResult ) => {
2037 map = new Map ( {
2138 target : 'map' ,
@@ -26,24 +43,11 @@ describe('openlayers_VectorTileSuperMapRest', () => {
2643 } ) ;
2744 vectorTileOptions = VectorTileSuperMapRest . optionsFromMapJSON ( url , serviceResult . result ) ;
2845 vectorTileSource = new VectorTileSuperMapRest ( vectorTileOptions ) ;
29- var vectorLayer = new VectorTileLayer ( {
46+ vectorLayer = new VectorTileLayer ( {
3047 source : vectorTileSource
3148 } ) ;
3249 map . addLayer ( vectorLayer ) ;
3350 } ) ;
34- } ) ;
35- beforeEach ( ( ) => {
36- originalTimeout = jasmine . DEFAULT_TIMEOUT_INTERVAL ;
37- jasmine . DEFAULT_TIMEOUT_INTERVAL = 50000 ;
38- } ) ;
39- afterEach ( ( ) => {
40- jasmine . DEFAULT_TIMEOUT_INTERVAL = originalTimeout ;
41- } ) ;
42- afterAll ( ( ) => {
43- window . document . body . removeChild ( testDiv ) ;
44- } ) ;
45-
46- it ( 'initialize' , ( done ) => {
4751 setTimeout ( ( ) => {
4852 try {
4953 expect ( vectorTileOptions ) . not . toBeNull ( ) ;
@@ -56,4 +60,35 @@ describe('openlayers_VectorTileSuperMapRest', () => {
5660 }
5761 } , 6000 ) ;
5862 } ) ;
63+ it ( 'custom_tileLoadFunction' , ( done ) => {
64+ var tileLoadFunction = jasmine . createSpy ( 'tileLoadFunction' ) ;
65+ new MapService ( url ) . getMapInfo ( ( serviceResult ) => {
66+ map = new Map ( {
67+ target : 'map' ,
68+ view : new View ( {
69+ center : [ 12957388 , 4853991 ] ,
70+ zoom : 11
71+ } )
72+ } ) ;
73+ vectorTileOptions = VectorTileSuperMapRest . optionsFromMapJSON ( url , serviceResult . result ) ;
74+ vectorTileOptions . tileLoadFunction = tileLoadFunction ;
75+ vectorTileSource = new VectorTileSuperMapRest ( vectorTileOptions ) ;
76+ vectorLayer = new VectorTileLayer ( {
77+ source : vectorTileSource
78+ } ) ;
79+ map . addLayer ( vectorLayer ) ;
80+ } ) ;
81+ setTimeout ( ( ) => {
82+ try {
83+ expect ( vectorTileOptions ) . not . toBeNull ( ) ;
84+ expect ( vectorTileSource ) . not . toBeNull ( ) ;
85+ expect ( tileLoadFunction ) . toHaveBeenCalled ( ) ;
86+ done ( ) ;
87+ } catch ( exception ) {
88+ console . log ( "'initialize'案例失败:" + exception . name + ":" + exception . message ) ;
89+ expect ( false ) . toBeTruthy ( ) ;
90+ done ( ) ;
91+ }
92+ } , 6000 ) ;
93+ } ) ;
5994} ) ;
0 commit comments