@@ -6,7 +6,7 @@ import VectorTileLayer from 'ol/layer/VectorTile';
6
6
7
7
var url = GlobeParameter . ChinaURL ;
8
8
describe ( 'openlayers_VectorTileSuperMapRest' , ( ) => {
9
- var testDiv , map , vectorTileOptions , vectorTileSource , originalTimeout ;
9
+ var testDiv , map , vectorTileOptions , vectorTileSource , originalTimeout , vectorLayer ;
10
10
beforeAll ( ( ) => {
11
11
testDiv = window . document . createElement ( "div" ) ;
12
12
testDiv . setAttribute ( "id" , "map" ) ;
@@ -16,6 +16,23 @@ describe('openlayers_VectorTileSuperMapRest', () => {
16
16
testDiv . style . width = "500px" ;
17
17
testDiv . style . height = "500px" ;
18
18
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 ) => {
19
36
new MapService ( url ) . getMapInfo ( ( serviceResult ) => {
20
37
map = new Map ( {
21
38
target : 'map' ,
@@ -26,24 +43,11 @@ describe('openlayers_VectorTileSuperMapRest', () => {
26
43
} ) ;
27
44
vectorTileOptions = VectorTileSuperMapRest . optionsFromMapJSON ( url , serviceResult . result ) ;
28
45
vectorTileSource = new VectorTileSuperMapRest ( vectorTileOptions ) ;
29
- var vectorLayer = new VectorTileLayer ( {
46
+ vectorLayer = new VectorTileLayer ( {
30
47
source : vectorTileSource
31
48
} ) ;
32
49
map . addLayer ( vectorLayer ) ;
33
50
} ) ;
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 ) => {
47
51
setTimeout ( ( ) => {
48
52
try {
49
53
expect ( vectorTileOptions ) . not . toBeNull ( ) ;
@@ -56,4 +60,35 @@ describe('openlayers_VectorTileSuperMapRest', () => {
56
60
}
57
61
} , 6000 ) ;
58
62
} ) ;
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
+ } ) ;
59
94
} ) ;
0 commit comments