1+ import ol from 'openlayers' ;
2+ import * as oldebug from 'openlayers/dist/ol-debug' ;
3+ import '../../../libs/openlayers/plugins/ol-mapbox-style/2.11.2/olms' ;
4+ import { MapboxStyles } from '../../../../src/openlayers/overlay/vectortile/MapboxStyles' ;
5+ import { MapService } from '../../../../src/openlayers/services/MapService' ;
6+ import { VectorTileSuperMapRest } from '../../../../src/openlayers/overlay/VectorTileSuperMapRest' ;
7+ import { FetchRequest } from '../../../../src/common/util/FetchRequest' ;
8+
9+ ol . render . canvas = oldebug . render . canvas ;
10+ ol . geom . flat = oldebug . geom . flat ;
11+
12+ describe ( 'openlayers_MapboxStyles' , ( ) => {
13+ var url = GlobeParameter . californiaURL
14+ var testDiv , map , mapboxStyles , originalTimeout ;
15+ beforeAll ( ( ) => {
16+ testDiv = window . document . createElement ( "div" ) ;
17+ testDiv . setAttribute ( "id" , "map" ) ;
18+ testDiv . style . styleFloat = "left" ;
19+ testDiv . style . marginLeft = "8px" ;
20+ testDiv . style . marginTop = "50px" ;
21+ testDiv . style . width = "500px" ;
22+ testDiv . style . height = "500px" ;
23+ window . document . body . appendChild ( testDiv ) ;
24+
25+ map = new ol . Map ( {
26+ target : 'map' ,
27+ view : new ol . View ( {
28+ center : [ - 122.228687503369 , 38.1364932162598 ] ,
29+ zoom : 10 ,
30+ minZoom : 10 ,
31+ maxZoom : 14 ,
32+ projection : 'EPSG:4326' ,
33+ } )
34+ } ) ;
35+ spyOn ( FetchRequest , 'get' ) . and . callFake ( ( testUrl , params , options ) => {
36+ expect ( testUrl ) . toBe ( url + "/tileFeature/vectorstyles.json?type=MapBox_GL&styleonly=true" ) ;
37+ return Promise . resolve ( new Response ( vectorstylesEscapedJson ) ) ;
38+ } ) ;
39+
40+ } ) ;
41+ beforeEach ( ( ) => {
42+ originalTimeout = jasmine . DEFAULT_TIMEOUT_INTERVAL ;
43+ jasmine . DEFAULT_TIMEOUT_INTERVAL = 50000 ;
44+ } ) ;
45+ afterEach ( ( ) => {
46+ jasmine . DEFAULT_TIMEOUT_INTERVAL = originalTimeout ;
47+ } ) ;
48+ afterAll ( ( ) => {
49+ window . document . body . removeChild ( testDiv ) ;
50+ } ) ;
51+
52+ it ( 'getStyleFunction' , ( done ) => {
53+ var stylesOptions = {
54+ url : url ,
55+ map : map ,
56+ source : 'California'
57+ } ;
58+ var style ;
59+ mapboxStyles = new MapboxStyles ( stylesOptions ) ;
60+ setTimeout ( ( ) => {
61+ style = mapboxStyles . getStyleFunction ( ) ;
62+ } , 8000 ) ;
63+ setTimeout ( ( ) => {
64+ expect ( style ) . not . toBeNull ( ) ;
65+ mapboxStyles = null ;
66+ done ( ) ;
67+ } , 1000 ) ;
68+ } ) ;
69+
70+ it ( 'getStyleFunction,setSelectedId' , ( done ) => {
71+ var stylesOptions = {
72+ url : url ,
73+ map : map ,
74+ source : 'California'
75+ } ;
76+ var style ;
77+ mapboxStyles = new MapboxStyles ( stylesOptions ) ;
78+ setTimeout ( ( ) => {
79+ mapboxStyles . setSelectedId ( 1 , 1 ) ;
80+ style = mapboxStyles . getStyleFunction ( ) ;
81+ } , 8000 ) ;
82+ setTimeout ( ( ) => {
83+ expect ( style ) . not . toBeNull ( ) ;
84+ mapboxStyles = null ;
85+ done ( ) ;
86+ } , 1000 ) ;
87+ } ) ;
88+
89+ it ( 'getStylesBySourceLayer' , ( done ) => {
90+ var stylesOptions = {
91+ url : url ,
92+ map : map ,
93+ source : 'California'
94+ } ;
95+ var layer ;
96+ mapboxStyles = new MapboxStyles ( stylesOptions ) ;
97+ setTimeout ( ( ) => {
98+ layer = mapboxStyles . getStylesBySourceLayer ( "Military_R@California" ) ;
99+ } , 8000 ) ;
100+ setTimeout ( ( ) => {
101+ expect ( layer ) . not . toBeNull ( ) ;
102+ mapboxStyles = null ;
103+ done ( ) ;
104+ } , 1000 ) ;
105+
106+ } ) ;
107+ } )
0 commit comments