1+ var TileVectorLayer = require ( '../../../src/leaflet/overlay/TileVectorLayer' ) ;
2+ require ( '../../tool/china_layers.js' ) ;
3+
4+ describe ( 'leaflet_testTileVectorLayer' , function ( ) {
5+ var originalTimeout ;
6+ var testDiv , map ;
7+ var ChinaURL = GlobeParameter . ChinaURL ;
8+ beforeAll ( function ( ) {
9+ testDiv = window . document . createElement ( "div" ) ;
10+ testDiv . setAttribute ( "id" , "map" ) ;
11+ testDiv . style . styleFloat = "left" ;
12+ testDiv . style . marginLeft = "8px" ;
13+ testDiv . style . marginTop = "50px" ;
14+ testDiv . style . width = "500px" ;
15+ testDiv . style . height = "500px" ;
16+ window . document . body . appendChild ( testDiv ) ;
17+ map = L . map ( 'map' , {
18+ center : [ 39.89 , 116.43 ] ,
19+ maxZoom : 12 ,
20+ zoom : 9
21+ } ) ;
22+ } ) ;
23+ beforeEach ( function ( ) {
24+ originalTimeout = jasmine . DEFAULT_TIMEOUT_INTERVAL ;
25+ jasmine . DEFAULT_TIMEOUT_INTERVAL = 50000 ;
26+ } ) ;
27+ afterEach ( function ( ) {
28+ jasmine . DEFAULT_TIMEOUT_INTERVAL = originalTimeout ;
29+ } ) ;
30+ afterAll ( function ( ) {
31+ map . remove ( ) ;
32+ window . document . body . removeChild ( testDiv ) ;
33+ } ) ;
34+
35+ it ( 'initialize_serverCartoCSSStyle:false' , function ( done ) {
36+ var tileVectorLayer = L . supermap . tiledVectorLayer ( ChinaURL , {
37+ cacheEnabled : false ,
38+ serverCartoCSSStyle : false
39+ } ) . addTo ( map ) ;
40+ setTimeout ( function ( ) {
41+ expect ( tileVectorLayer ) . not . toBeNull ( ) ;
42+ var layersInfo = tileVectorLayer . layersInfo ;
43+ expect ( layersInfo !== undefined ) . toBeTruthy ( ) ;
44+ expect ( layersInfo ) . not . toBeNull ( ) ;
45+ var isLayersInfoInitialized = tileVectorLayer . layersInfoInitialized ;
46+ expect ( isLayersInfoInitialized !== undefined ) . toBeTruthy ( ) ;
47+ expect ( isLayersInfoInitialized ) . toBeTruthy ( ) ;
48+ var layersStyles = tileVectorLayer . layersStyles ;
49+ expect ( layersStyles !== undefined ) . toBeTruthy ( ) ;
50+ expect ( layersStyles ) . not . toBeNull ( ) ;
51+ expect ( tileVectorLayer . scales ) . not . toBeNull ( ) ;
52+ var scaleNine = tileVectorLayer . getScale ( 9 ) ;
53+ expect ( scaleNine ) . toEqual ( 8.653637486605625e-7 ) ;
54+ var vectorTileLayerStyles = tileVectorLayer . vectorTileLayerStyles ;
55+ expect ( vectorTileLayerStyles !== undefined ) . toBeTruthy ( ) ;
56+ expect ( vectorTileLayerStyles ) . not . toBeNull ( ) ;
57+ var layerStyle = tileVectorLayer . getStyle ( 'China_Province_pl@China' ) ;
58+ expect ( layerStyle . color ) . toBe ( "rgba(120,113,102,0)" ) ;
59+ expect ( layerStyle . fillColor ) . toBe ( "rgba(255,255,255,1)" ) ;
60+ expect ( layerStyle . markerSize ) . toEqual ( 22.677119999999995 ) ;
61+ expect ( layerStyle . weight ) . toEqual ( 0.94488 ) ;
62+ map . removeLayer ( tileVectorLayer ) ;
63+ done ( ) ;
64+ } , 3000 ) ;
65+ } ) ;
66+
67+ it ( 'initialize_serverCartoCSSStyle:true' , function ( done ) {
68+ var tileVectorLayer = new L . supermap . tiledVectorLayer ( ChinaURL , {
69+ cacheEnabled : false ,
70+ serverCartoCSSStyle : true
71+ } ) . addTo ( map ) ;
72+ setTimeout ( function ( ) {
73+ expect ( tileVectorLayer ) . not . toBeNull ( ) ;
74+ var layerStyle = tileVectorLayer . getStyle ( 'China_Province_pl@China' ) ;
75+ expect ( layerStyle . length ) . toEqual ( 1 ) ;
76+ expect ( layerStyle [ 0 ] . color ) . toBe ( "rgba(0, 0, 0, 0)" ) ;
77+ expect ( layerStyle [ 0 ] . fillColor ) . toBe ( "rgba(255, 255, 255, 1)" ) ;
78+ expect ( layerStyle [ 0 ] . markerSize ) . toBeUndefined ( ) ;
79+ expect ( layerStyle [ 0 ] . weight ) . toEqual ( 1 ) ;
80+ map . removeLayer ( tileVectorLayer ) ;
81+ done ( ) ;
82+ } , 3000 ) ;
83+ } ) ;
84+
85+
86+ it ( 'initialize_cartoCSS' , function ( done ) {
87+ var cssStr = initClientCssStr ( ) ;
88+ var tileVectorLayer = L . supermap . tiledVectorLayer ( ChinaURL , {
89+ cacheEnabled : true ,
90+ cartoCSS : cssStr ,
91+ serverCartoCSSStyle : false
92+ } ) . addTo ( map ) ;
93+ setTimeout ( function ( ) {
94+ expect ( tileVectorLayer ) . not . toBeNull ( ) ;
95+ var layerStyle = tileVectorLayer . getStyle ( 'China_Province_pl@China' ) ;
96+ expect ( layerStyle . length ) . toEqual ( 1 ) ;
97+ expect ( layerStyle [ 0 ] . color ) . toBe ( "rgba(0, 0, 0, 0)" ) ;
98+ expect ( layerStyle [ 0 ] . fillColor ) . toBe ( "rgba(183, 202, 147, 1)" ) ;
99+ expect ( layerStyle [ 0 ] . markerSize ) . toBeUndefined ( ) ;
100+ expect ( layerStyle [ 0 ] . fillOpacity ) . toEqual ( 1 ) ;
101+ expect ( layerStyle [ 0 ] . opacity ) . toEqual ( 1 ) ;
102+ expect ( layerStyle [ 0 ] . weight ) . toEqual ( 1 ) ;
103+ map . removeLayer ( tileVectorLayer ) ;
104+ done ( ) ;
105+ } , 3000 ) ;
106+ } ) ;
107+
108+ it ( 'setClientCartoCSS' , function ( done ) {
109+ var cssStr = initClientCssStr ( ) ;
110+ var tileVectorLayer = L . supermap . tiledVectorLayer ( ChinaURL , {
111+ cacheEnabled : false ,
112+ serverCartoCSSStyle : false
113+ } ) . addTo ( map ) ;
114+ tileVectorLayer . setClientCartoCSS ( cssStr ) ;
115+ setTimeout ( function ( ) {
116+ expect ( tileVectorLayer ) . not . toBeNull ( ) ;
117+ var layerStyle = tileVectorLayer . getStyle ( 'China_Province_pl@China' ) ;
118+ expect ( layerStyle . length ) . toEqual ( 1 ) ;
119+ expect ( layerStyle [ 0 ] . color ) . toBe ( "rgba(0, 0, 0, 0)" ) ;
120+ expect ( layerStyle [ 0 ] . fillColor ) . toBe ( "rgba(183, 202, 147, 1)" ) ;
121+ expect ( layerStyle [ 0 ] . markerSize ) . toBeUndefined ( ) ;
122+ expect ( layerStyle [ 0 ] . weight ) . toEqual ( 1 ) ;
123+ map . removeLayer ( tileVectorLayer ) ;
124+ done ( ) ;
125+ } , 3000 ) ;
126+ } ) ;
127+
128+ it ( 'setServerCartoCss' , function ( done ) {
129+ var cssStr2 = initServerCssStr ( ) ;
130+ var tileVectorLayer = L . supermap . tiledVectorLayer ( ChinaURL , {
131+ cacheEnabled : false ,
132+ serverCartoCSSStyle : false
133+ } ) . addTo ( map ) ;
134+ tileVectorLayer . setServerCartoCSS ( cssStr2 ) ;
135+ setTimeout ( function ( ) {
136+ var layerStyle = tileVectorLayer . getStyle ( 'China_Province_pl@China' ) ;
137+ expect ( layerStyle . length ) . toEqual ( 1 ) ;
138+ expect ( layerStyle [ 0 ] . color ) . toBe ( "rgba(0, 0, 0, 0)" ) ;
139+ expect ( layerStyle [ 0 ] . fillColor ) . toBe ( "rgba(255, 255, 255, 1)" ) ;
140+ expect ( layerStyle [ 0 ] . markerSize ) . toBeUndefined ( ) ;
141+ expect ( layerStyle [ 0 ] . weight ) . toEqual ( 1 ) ;
142+ map . removeLayer ( tileVectorLayer ) ;
143+ done ( ) ;
144+ } , 3000 ) ;
145+ } ) ;
146+
147+ function initClientCssStr ( ) {
148+ var cartoCss = "@waterColor:rgb(109,183,255);" +
149+ "@roadColora:rgb(100,100,100);" +
150+ "@roadColorb:rgb(250,250,250);" +
151+ "@railwayColora:rgb(186,186,186);" +
152+ "@railwayColorb:rgb(250,250,250);" +
153+ "@vegetationColor:rgb(193,220,185);" +
154+ "@continentColor:rgb(183,202,147);" +
155+ "@provinceLineColor:rgb(100,100,100);" ;
156+ cartoCss = cartoCss . replace ( / [ @ ] / gi, "\n@" ) ;
157+ var cartoCss2 = "#World_Continent_pl___China{\npolygon-fill:@continentColor;\nline-width:1;\nline-color:@continentColor;\n}" +
158+ "#China_Province_pl___China{\npolygon-fill:@continentColor;\nline-color:rgba(0,0,0,0);\n}" +
159+ "#Arterial_Road_ln___China::one{\nline-color:@roadColora;\nline-width:2;\n}" +
160+ "#Arterial_Road_ln___China::two{\nline-color:@roadColorb;\nline-width:1;\n}" +
161+ "#Arterial_Road_ln___China___1::one{\nline-color:@roadColora;\nline-width:2;\n}" +
162+ "#Arterial_Road_ln___China___1::two{\nline-color:@roadColorb;\nline-width:1;\n}" +
163+ "#Arterial_Road_ln___China___1___1::one{\nline-color:@roadColora;\nline-width:2;\n}" +
164+ "#Arterial_Road_ln___China___1___1::two{\nline-color:@roadColorb;\nline-width:1;\n}" +
165+ "#Main_Road_L___China::one{\nline-color:@roadColora;\nline-width:2;\n}" +
166+ "#Main_Road_L___China::two{\nline-color:@roadColorb;\nline-width:1;\n}" +
167+ "#Main_Road_L___China___1::one{\nline-color:@roadColora;\nline-width:2;\n}" +
168+ "#Main_Road_L___China___1::two{\nline-color:@roadColorb;\nline-width:1;\n}" +
169+ "#Main_Road_L___China___1___1::a{\nline-color:@roadColora;\nline-width:2;\n}" +
170+ "#Main_Road_L___China___1___1::b{\nline-color:@roadColorb;\nline-width:1;\n}" +
171+ "#Hydside_Area_pl___Hydside{\npolygon-fill:@waterColor;\nline-color:@waterColor;\n}" +
172+ "#China_Provinces_L___China400{\nline-dasharray:10,10;\nline-color:@provinceLineColor;\nline-width:1;\n}" ;
173+ cartoCss2 = cartoCss2 . replace ( / [ # ] / gi, "\n#" ) ;
174+ return cartoCss + cartoCss2 ;
175+ }
176+
177+ function initServerCssStr ( ) {
178+ return "#World_Continent_pl@China{text-placement-type:simple;text-placements:\"E,NE,SE,W,NW,SW\";line-color:rgba(0,0,0,0);polygon-fill:rgba(245,243,240,1);marker-width:9.070866141732283;marker-height:9.070866141732283;marker-fill:rgba(13,80,143,1);marker-type:ellipse;polygon-opacity:1.0;polygon-pattern-opacity:1.0;}" +
179+ "#China_Province_pl@China{text-placement-type:simple;text-placements:\"E,NE,SE,W,NW,SW\";line-color:rgba(0,0,0,0);polygon-fill:rgba(255,255,255,1);marker-width:9.070866141732283;marker-height:9.070866141732283;marker-fill:rgba(13,80,143,1);marker-type:ellipse;polygon-opacity:1.0;polygon-pattern-opacity:1.0;}" +
180+ "#Arterial_Road_ln@China\\#1\\#1[zoom<=6.9229099892844565E-6][zoom>=4.3268187433028044E-7]{text-placement-type:simple;text-placements:\"E,NE,SE,W,NW,SW\";::subLine_0{line-join:round;line-cap:butt;line-color:rgba(226,160,70,1);line-width:1.8897637795275593;}::subLine_1{line-join:round;line-cap:round;line-color:rgba(242,223,106,1);line-width:1.1338582677165354;}polygon-fill:rgba(208,255,240,1);marker-width:9.070866141732283;marker-height:9.070866141732283;marker-fill:rgba(13,80,143,1);marker-type:ellipse;polygon-opacity:1.0;polygon-pattern-opacity:1.0;}" +
181+ "#Arterial_Road_ln@China[zoom<=4.3268187433028044E-7][zoom>=2.1634093716513974E-7]{text-placement-type:simple;text-placements:\"E,NE,SE,W,NW,SW\";line-color:rgba(232,212,85,1);line-width:0.37795275590551186;polygon-fill:rgba(189,235,255,1);marker-width:9.070866141732283;marker-height:9.070866141732283;marker-fill:rgba(13,80,143,1);marker-type:ellipse;polygon-opacity:1.0;polygon-pattern-opacity:1.0;}" +
182+ "#Arterial_Road_ln@China\\#1[zoom>=6.9229099892844565E-6]{text-placement-type:simple;text-placements:\"E,NE,SE,W,NW,SW\";::subLine_0{line-join:round;line-cap:butt;line-color:rgba(226,160,70,1);line-width:3.7795275590551185;}::subLine_1{line-join:round;line-cap:round;line-color:rgba(242,223,106,1);line-width:3.023622047244095;}polygon-fill:rgba(208,255,240,1);marker-width:9.070866141732283;marker-height:9.070866141732283;marker-fill:rgba(13,80,143,1);marker-type:ellipse;polygon-opacity:1.0;polygon-pattern-opacity:1.0;}" +
183+ "#Arterial_Road_ln@China\\#2[zoom>=3.4614549946422405E-6]{text-placement-type:simple;text-placements:\"E,NE,SE,W,NW,SW\";text-name:\"[NAME]\";text-placement:line;text-placement-type:simple;text-placements:\"E,NE,SE,W,NW,SW\";text-face-name:\"微软雅黑\";text-size:14;text-fill:rgba(150,105,0,1);text-opacity:1;text-size-fixed:true;text-halo-fill:rgba(255,255,255,1);text-halo:true;text-halo-radius:1;text-vertical-alignment:middle;text-horizontal-alignment:middle;}" +
184+ "#Main_Road_L@China\\#2[zoom>=8.653637486605571E-7]{text-placement-type:simple;text-placements:\"E,NE,SE,W,NW,SW\";text-name:\"[RN]\";text-placement:line;text-placement-type:simple;text-placements:\"E,NE,SE,W,NW,SW\";text-face-name:\"微软雅黑\";text-size:13;text-fill:rgba(255,255,255,1);text-opacity:1;text-size-fixed:true;text-vertical-alignment:middle;text-horizontal-alignment:middle;}" +
185+ "#Main_Road_L@China\\#1[zoom>=6.9229099892844565E-6]{text-placement-type:simple;text-placements:\"E,NE,SE,W,NW,SW\";::subLine_0{line-join:round;line-cap:butt;line-color:rgba(178,137,80,1);line-width:5.291338582677165;}::subLine_1{line-join:round;line-cap:round;line-color:rgba(255,206,16,1);line-width:2.6456692913385824;}polygon-fill:rgba(208,255,240,1);marker-width:9.070866141732283;marker-height:9.070866141732283;marker-fill:rgba(13,80,143,1);marker-type:ellipse;polygon-opacity:1.0;polygon-pattern-opacity:1.0;}" +
186+ "#Main_Road_L@China\\#3[zoom>=8.653637486605571E-7]{text-placement-type:simple;text-placements:\"E,NE,SE,W,NW,SW\";text-name:\"[NAME]\";text-placement:line;text-placement-type:simple;text-placements:\"E,NE,SE,W,NW,SW\";text-face-name:\"微软雅黑\";text-size:15;text-fill:rgba(150,105,0,1);text-opacity:1;text-size-fixed:true;text-halo-fill:rgba(255,224,104,1);text-halo:true;text-halo-radius:1;text-vertical-alignment:middle;text-horizontal-alignment:middle;}" +
187+ "#Main_Road_L@China[zoom<=4.3268187433028044E-7][zoom>=5.40852342912851E-8]{text-placement-type:simple;text-placements:\"E,NE,SE,W,NW,SW\";line-color:rgba(221,155,44,1);line-width:0.37795275590551186;polygon-fill:rgba(208,255,240,1);marker-width:9.070866141732283;marker-height:9.070866141732283;marker-fill:rgba(13,80,143,1);marker-type:ellipse;polygon-opacity:1.0;polygon-pattern-opacity:1.0;}" +
188+ "#Main_Road_L@China\\#1\\#1[zoom<=6.9229099892844565E-6][zoom>=4.3268187433028044E-7]{text-placement-type:simple;text-placements:\"E,NE,SE,W,NW,SW\";::subLine_0{line-join:round;line-cap:butt;line-color:rgba(178,137,80,1);line-width:2.6456692913385824;}::subLine_1{line-join:round;line-cap:round;line-color:rgba(255,206,16,1);line-width:1.5118110236220474;}polygon-fill:rgba(208,255,240,1);marker-width:9.070866141732283;marker-height:9.070866141732283;marker-fill:rgba(13,80,143,1);marker-type:ellipse;polygon-opacity:1.0;polygon-pattern-opacity:1.0;}" ;
189+ }
190+ } ) ;
0 commit comments