1+ require ( '../../../../src/leaflet/overlay/theme/GraphThemeLayer' ) ;
2+ require ( '../../../tool/chinaConsumptionLevel' ) ;
3+
4+ var options = {
5+ isOverLay : true
6+ } ;
7+
8+ describe ( 'leaflet_testGraphThemeLayer' , function ( ) {
9+ var originalTimeout ;
10+ var url = GlobeParameter . China4326URL ;
11+ var mydiv = window . document . createElement ( "div" ) ;
12+ mydiv . setAttribute ( "id" , "map" ) ;
13+ mydiv . style . styleFloat = "left" ;
14+ mydiv . style . marginLeft = "8px" ;
15+ mydiv . style . marginTop = "50px" ;
16+ mydiv . style . width = "400px" ;
17+ mydiv . style . height = "400px" ;
18+ window . document . body . appendChild ( mydiv ) ;
19+ var map = L . map ( "map" , {
20+ crs : L . CRS . EPSG4326 ,
21+ center : [ 40 , 117 ] ,
22+ maxZoom : 18 ,
23+ zoom : 0
24+ } ) ;
25+ L . supermap . tiledMapLayer ( url ) . addTo ( map ) ;
26+
27+ beforeEach ( function ( ) {
28+ originalTimeout = jasmine . DEFAULT_TIMEOUT_INTERVAL ;
29+ jasmine . DEFAULT_TIMEOUT_INTERVAL = 50000 ;
30+ } ) ;
31+ afterEach ( function ( ) {
32+ jasmine . DEFAULT_TIMEOUT_INTERVAL = originalTimeout ;
33+ } ) ;
34+ afterAll ( function ( ) {
35+ window . document . body . removeChild ( mydiv ) ;
36+ } ) ;
37+
38+ it ( 'construtor and destroy' , function ( ) {
39+ var barThemeLayer = L . supermap . graphThemeLayer ( "BarThemeLayer" , "Bar" , { isOverLay : false } ) . addTo ( map ) ;
40+ barThemeLayer . themeFields = [ "CON2009" , "CON2010" , "CON2011" , "CON2012" , "CON2013" ] ;
41+ barThemeLayer . chartsSetting = {
42+ width : 240 ,
43+ height : 100 ,
44+ codomain : [ 0 , 40000 ] ,
45+ barStyle : { fillOpacity : 0.7 } ,
46+ barHoverStyle : { fillOpacity : 1 } ,
47+ xShapeBlank : [ 10 , 10 , 10 ] ,
48+ axisYTick : 4 ,
49+ axisYLabels : [ "4万" , "3万" , "2万" , "1万" , "0" ] ,
50+ axisXLabels : [ "09年" , "10年" , "11年" , "12年" , "13年" ] ,
51+ backgroundStyle : { fillColor : "#CCE8CF" } ,
52+ backgroundRadius : [ 5 , 5 , 5 , 5 ] ,
53+ showShadow : true ,
54+ barShadowStyle : { shadowBlur : 8 , shadowOffsetX : 2 , shadowOffsetY : 2 , shadowColor : "rgba(100,100,100,0.8)" } ,
55+ barLinearGradient : [ [ "#00FF00" , "#00CD00" ] , [ "#00CCFF" , "#5E87A2" ] , [ "#00FF66" , "#669985" ] , [ "#CCFF00" , "#94A25E" ] , [ "#FF9900" , "#A2945E" ] ]
56+ } ;
57+ expect ( barThemeLayer ) . not . toBeNull ( ) ;
58+ expect ( barThemeLayer . chartsType ) . toBe ( "Bar" ) ;
59+ expect ( barThemeLayer . charts . length ) . toEqual ( 0 ) ;
60+ var chartsSetting = barThemeLayer . chartsSetting ;
61+ expect ( chartsSetting . axisXLabels . length ) . toEqual ( 5 ) ;
62+ expect ( chartsSetting . axisYLabels . length ) . toEqual ( 5 ) ;
63+ expect ( chartsSetting . axisYTick ) . toEqual ( 4 ) ;
64+ expect ( chartsSetting . backgroundRadius . length ) . toEqual ( 4 ) ;
65+ expect ( chartsSetting . backgroundStyle . fillColor ) . toBe ( "#CCE8CF" ) ;
66+ expect ( chartsSetting . barHoverStyle . fillOpacity ) . toEqual ( 1 ) ;
67+ expect ( chartsSetting . barStyle . fillOpacity ) . toEqual ( 0.7 ) ;
68+ expect ( chartsSetting . barLinearGradient . length ) . toEqual ( 5 ) ;
69+ expect ( chartsSetting . barShadowStyle ) . not . toBeNull ( ) ;
70+ expect ( chartsSetting . codomain . length ) . toEqual ( 2 ) ;
71+ expect ( chartsSetting . barShadowStyle ) . not . toBeNull ( ) ;
72+ expect ( chartsSetting . height ) . toEqual ( 100 ) ;
73+ expect ( chartsSetting . width ) . toEqual ( 240 ) ;
74+ expect ( chartsSetting . showShadow ) . toBeTruthy ( ) ;
75+ expect ( barThemeLayer . options . isOverLay ) . toBeFalsy ( ) ;
76+ expect ( barThemeLayer . options . name ) . toBe ( "BarThemeLayer" ) ;
77+ expect ( barThemeLayer . themeFields . length ) . toEqual ( 5 ) ;
78+ barThemeLayer . clear ( ) ;
79+ } ) ;
80+
81+ it ( 'setChartsType' , function ( ) {
82+ var graphThemeLayer = L . supermap . graphThemeLayer ( "BarThemeLayer" , "Bar" , options ) . addTo ( map ) ;
83+ graphThemeLayer . chartsSetting = {
84+ width : 240 ,
85+ height : 100 ,
86+ codomain : [ 0 , 40000 ]
87+ } ;
88+ expect ( graphThemeLayer . chartsType ) . toBe ( "Bar" ) ;
89+ graphThemeLayer . setChartsType ( "Line" ) ;
90+ expect ( graphThemeLayer . chartsType ) . toBe ( "Line" ) ;
91+ graphThemeLayer . clear ( ) ;
92+ } ) ;
93+
94+ it ( 'addFeatures_point' , function ( ) {
95+ var graphThemeLayer = L . supermap . graphThemeLayer ( "BarThemeLayer" , "Bar" ) . addTo ( map ) ;
96+ graphThemeLayer . themeFields = [ "CON2009" , "CON2010" , "CON2011" , "CON2012" , "CON2013" ] ;
97+ graphThemeLayer . chartsSetting = {
98+ width : 240 ,
99+ height : 100 ,
100+ codomain : [ 0 , 40000 ] ,
101+ barStyle : { fillOpacity : 0.7 } ,
102+ barHoverStyle : { fillOpacity : 1 } ,
103+ xShapeBlank : [ 10 , 10 , 10 ] ,
104+ axisYTick : 4 ,
105+ axisYLabels : [ "4万" , "3万" , "2万" , "1万" , "0" ] ,
106+ axisXLabels : [ "09年" , "10年" , "11年" , "12年" , "13年" ] ,
107+ backgroundStyle : { fillColor : "#CCE8CF" } ,
108+ backgroundRadius : [ 5 , 5 , 5 , 5 ] ,
109+ showShadow : true ,
110+ barShadowStyle : { shadowBlur : 8 , shadowOffsetX : 2 , shadowOffsetY : 2 , shadowColor : "rgba(100,100,100,0.8)" } ,
111+ barLinearGradient : [ [ "#00FF00" , "#00CD00" ] , [ "#00CCFF" , "#5E87A2" ] , [ "#00FF66" , "#669985" ] , [ "#CCFF00" , "#94A25E" ] , [ "#FF9900" , "#A2945E" ] ]
112+ } ;
113+ expect ( graphThemeLayer . features . length ) . toEqual ( 0 ) ;
114+ var features = [ ] ;
115+ for ( var i = 0 , len = chinaConsumptionLevel . length ; i < len ; i ++ ) {
116+ var provinceInfo = chinaConsumptionLevel [ i ] ;
117+ var geometry = L . point ( provinceInfo [ 1 ] , provinceInfo [ 2 ] ) ;
118+ var atrributes = { } ;
119+ atrributes . NAME = provinceInfo [ 0 ] ;
120+ atrributes . CON2009 = provinceInfo [ 3 ] ;
121+ atrributes . CON2010 = provinceInfo [ 4 ] ;
122+ atrributes . CON2011 = provinceInfo [ 5 ] ;
123+ atrributes . CON2012 = provinceInfo [ 6 ] ;
124+ atrributes . CON2013 = provinceInfo [ 7 ] ;
125+ var fea = L . supermap . themeFeature ( geometry , atrributes ) ;
126+ features . push ( fea ) ;
127+ }
128+ graphThemeLayer . addFeatures ( features ) ;
129+ var LayerFeatures = graphThemeLayer . features ;
130+ expect ( LayerFeatures . length ) . toBeGreaterThan ( 0 ) ;
131+ expect ( LayerFeatures [ 0 ] . geometry . y ) . toEqual ( 39.904557 ) ;
132+ expect ( LayerFeatures [ 0 ] . geometry . x ) . toEqual ( 116.407283 ) ;
133+ expect ( LayerFeatures [ 0 ] . data ) . toEqual ( LayerFeatures [ 0 ] . attributes ) ;
134+ expect ( LayerFeatures [ 0 ] . data ) . toEqual ( Object ( {
135+ CON2009 : 22023 ,
136+ CON2010 : 24982 ,
137+ CON2011 : 27760 ,
138+ CON2012 : 30350 ,
139+ CON2013 : 33337 ,
140+ NAME : "北京市"
141+ } ) ) ;
142+ var shape1 = graphThemeLayer . getShapesByFeatureID ( ) ;
143+ var shape2 = graphThemeLayer . getShapesByFeatureID ( LayerFeatures [ 0 ] . id ) ;
144+ expect ( shape1 . length ) . toEqual ( 17 ) ;
145+ expect ( shape2 . length ) . toEqual ( 5 ) ;
146+ var weightFieldValue = graphThemeLayer . getWeightFieldValue ( LayerFeatures [ 0 ] , "CON2009" , 0 ) ;
147+ expect ( weightFieldValue ) . toEqual ( 22023 ) ;
148+ var weightFieldValue2 = graphThemeLayer . getWeightFieldValue ( LayerFeatures [ 0 ] , "CON2007" , 10 ) ;
149+ expect ( weightFieldValue2 ) . toEqual ( 10 ) ;
150+ var weightFieldValue3 = graphThemeLayer . getWeightFieldValue ( LayerFeatures [ 0 ] , "CON2007" ) ;
151+ expect ( weightFieldValue3 ) . toEqual ( 0 ) ;
152+ graphThemeLayer . features [ 0 ] . geometry . x = 39 ;
153+ var redraw = graphThemeLayer . redraw ( ) ;
154+ expect ( graphThemeLayer . features [ 0 ] . geometry . x ) . toEqual ( 39 ) ;
155+ expect ( redraw ) . toBeTruthy ( ) ;
156+ graphThemeLayer . clear ( ) ;
157+ } ) ;
158+
159+ it ( 'isQuadrilateralOverLap' , function ( ) {
160+ var graphThemeLayer = L . supermap . graphThemeLayer ( "BarThemeLayer" , "Bar" ) . addTo ( map ) ;
161+ graphThemeLayer . themeFields = [ "CON2009" , "CON2010" , "CON2011" , "CON2012" , "CON2013" ] ;
162+ graphThemeLayer . chartsSetting = {
163+ width : 240 ,
164+ height : 100 ,
165+ codomain : [ 0 , 40000 ]
166+ } ;
167+ var quadrilateral , quadrilateral2 ;
168+ quadrilateral = [ { "x" : 1 , "y" : 1 } , { "x" : 3 , "y" : 1 } , { "x" : 6 , "y" : 4 } , { "x" : 2 , "y" : 10 } , { "x" : 1 , "y" : 1 } ] ;
169+ quadrilateral2 = [ { "x" : 1 , "y" : 1 } , { "x" : 3 , "y" : 1 } , { "x" : 6 , "y" : 4 } , { "x" : 2 , "y" : 10 } , { "x" : 1 , "y" : 1 } ] ;
170+ var isPointInPoly = graphThemeLayer . isQuadrilateralOverLap ( quadrilateral , quadrilateral2 ) ;
171+ expect ( isPointInPoly ) . toBeTruthy ( ) ;
172+ graphThemeLayer . clear ( ) ;
173+ } ) ;
174+
175+
176+ // 此方法为iclient8的私有方法,不支持leaflet对象,此处测试传入iclient对象的情况
177+ it ( 'isPointInPoly' , function ( ) {
178+ var graphThemeLayer = L . supermap . graphThemeLayer ( "BarThemeLayer" , "Bar" , options ) . addTo ( map ) ;
179+ graphThemeLayer . themeFields = [ "CON2009" , "CON2010" , "CON2011" , "CON2012" , "CON2013" ] ;
180+ graphThemeLayer . chartsSetting = {
181+ width : 240 ,
182+ height : 100 ,
183+ codomain : [ 0 , 40000 ]
184+ } ;
185+ var point = { "x" : 2 , "y" : 5 } ;
186+ var polygon = [ { "x" : 1 , "y" : 1 } , { "x" : 3 , "y" : 1 } , { "x" : 6 , "y" : 4 } , { "x" : 2 , "y" : 10 } , { "x" : 1 , "y" : 1 } ] ;
187+ var isPointInPoly = graphThemeLayer . isPointInPoly ( point , polygon ) ;
188+ expect ( isPointInPoly ) . toBeTruthy ( ) ;
189+ graphThemeLayer . clear ( ) ;
190+ } ) ;
191+
192+ it ( 'drawCharts' , function ( ) {
193+ var graphThemeLayer = L . supermap . graphThemeLayer ( "BarThemeLayer" , "Bar" , {
194+ isOverLay : false
195+ } ) . addTo ( map ) ;
196+ graphThemeLayer . themeFields = [ "CON2009" , "CON2010" , "CON2011" , "CON2012" , "CON2013" ] ;
197+ graphThemeLayer . chartsSetting = {
198+ width : 240 ,
199+ height : 100 ,
200+ codomain : [ 0 , 40000 ] ,
201+ barStyle : { fillOpacity : 0.7 } ,
202+ barHoverStyle : { fillOpacity : 1 } ,
203+ xShapeBlank : [ 10 , 10 , 10 ] ,
204+ axisYTick : 4 ,
205+ axisYLabels : [ "4万" , "3万" , "2万" , "1万" , "0" ] ,
206+ axisXLabels : [ "09年" , "10年" , "11年" , "12年" , "13年" ] ,
207+ backgroundStyle : { fillColor : "#CCE8CF" } ,
208+ backgroundRadius : [ 5 , 5 , 5 , 5 ] ,
209+ showShadow : true ,
210+ barShadowStyle : { shadowBlur : 8 , shadowOffsetX : 2 , shadowOffsetY : 2 , shadowColor : "rgba(100,100,100,0.8)" } ,
211+ barLinearGradient : [ [ "#00FF00" , "#00CD00" ] , [ "#00CCFF" , "#5E87A2" ] , [ "#00FF66" , "#669985" ] , [ "#CCFF00" , "#94A25E" ] , [ "#FF9900" , "#A2945E" ] ]
212+ } ;
213+ graphThemeLayer . drawCharts ( ) ;
214+ expect ( graphThemeLayer ) . not . toBeNull ( ) ;
215+ graphThemeLayer . clear ( ) ;
216+ } ) ;
217+
218+ it ( 'removeFeatures' , function ( ) {
219+ var graphThemeLayer = L . supermap . graphThemeLayer ( "BarThemeLayer" , "Bar" , options ) . addTo ( map ) ;
220+ graphThemeLayer . themeFields = [ "CON2009" , "CON2010" , "CON2011" , "CON2012" , "CON2013" ] ;
221+ graphThemeLayer . chartsSetting = {
222+ width : 240 ,
223+ height : 100 ,
224+ codomain : [ 0 , 40000 ] ,
225+ } ;
226+ var features = [ ] ;
227+ for ( var i = 0 , len = chinaConsumptionLevel . length ; i < len ; i ++ ) {
228+ var provinceInfo = chinaConsumptionLevel [ i ] ;
229+ var geometry = L . point ( provinceInfo [ 2 ] , provinceInfo [ 1 ] ) ;
230+ var fea = new L . supermap . themeFeature ( geometry ) ;
231+ features . push ( fea ) ;
232+ }
233+ graphThemeLayer . addFeatures ( features ) ;
234+ expect ( graphThemeLayer . features . length ) . toBeGreaterThan ( 0 ) ;
235+ graphThemeLayer . removeFeatures ( ) ;
236+ graphThemeLayer . removeAllFeatures ( ) ;
237+ expect ( graphThemeLayer . features . length ) . toEqual ( 0 ) ;
238+ graphThemeLayer . clear ( ) ;
239+ } ) ;
240+
241+ it ( 'clearCache' , function ( ) {
242+ var graphThemeLayer = L . supermap . graphThemeLayer ( "BarThemeLayer" , "Bar" , options ) . addTo ( map ) ;
243+ graphThemeLayer . themeFields = [ "CON2009" , "CON2010" , "CON2011" , "CON2012" , "CON2013" ] ;
244+ graphThemeLayer . chartsSetting = {
245+ width : 240 ,
246+ height : 100 ,
247+ codomain : [ 0 , 40000 ]
248+ } ;
249+ graphThemeLayer . charts = [ 1 , 2 , 3 ] ;
250+ graphThemeLayer . cache = { 'name' : 'ONETWO' } ;
251+ expect ( graphThemeLayer . charts . length ) . toEqual ( 3 ) ;
252+ expect ( graphThemeLayer . cache ) . toEqual ( Object ( {
253+ name : "ONETWO"
254+ } ) ) ;
255+ graphThemeLayer . clearCache ( ) ;
256+ expect ( graphThemeLayer . charts . length ) . toEqual ( 0 ) ;
257+ expect ( graphThemeLayer . cache ) . toEqual ( Object ( { } ) ) ;
258+ } ) ;
259+
260+ it ( 'createThematicFeature' , function ( ) {
261+ var graphThemeLayer = L . supermap . graphThemeLayer ( "BarThemeLayer" , "Bar" , options ) . addTo ( map ) ;
262+ graphThemeLayer . addTo ( map ) ;
263+ graphThemeLayer . themeFields = [ "CON2009" , "CON2010" , "CON2011" , "CON2012" , "CON2013" ] ;
264+ graphThemeLayer . chartsSetting = {
265+ width : 240 ,
266+ height : 100 ,
267+ codomain : [ 0 , 40000 ] ,
268+ barStyle : { fillOpacity : 0.7 } ,
269+ barHoverStyle : { fillOpacity : 1 } ,
270+ xShapeBlank : [ 10 , 10 , 10 ] ,
271+ axisYTick : 4 ,
272+ axisYLabels : [ "4万" , "3万" , "2万" , "1万" , "0" ] ,
273+ axisXLabels : [ "09年" , "10年" , "11年" , "12年" , "13年" ] ,
274+ backgroundStyle : { fillColor : "#CCE8CF" } ,
275+ backgroundRadius : [ 5 , 5 , 5 , 5 ] ,
276+ showShadow : true ,
277+ barShadowStyle : { shadowBlur : 8 , shadowOffsetX : 2 , shadowOffsetY : 2 , shadowColor : "rgba(100,100,100,0.8)" } ,
278+ barLinearGradient : [ [ "#00FF00" , "#00CD00" ] , [ "#00CCFF" , "#5E87A2" ] , [ "#00FF66" , "#669985" ] , [ "#CCFF00" , "#94A25E" ] , [ "#FF9900" , "#A2945E" ] ]
279+ } ;
280+ var provinceInfo = chinaConsumptionLevel [ 0 ] ;
281+ var geo = new SuperMap . Geometry . Point ( provinceInfo [ 1 ] , provinceInfo [ 2 ] ) ;
282+ var attrs = { } ;
283+ attrs . NAME = provinceInfo [ 0 ] ;
284+ attrs . CON2009 = provinceInfo [ 3 ] ;
285+ attrs . CON2010 = provinceInfo [ 4 ] ;
286+ attrs . CON2011 = provinceInfo [ 5 ] ;
287+ attrs . CON2012 = provinceInfo [ 6 ] ;
288+ attrs . CON2013 = provinceInfo [ 7 ] ;
289+ var feature = new SuperMap . Feature . Vector ( geo , attrs ) ;
290+ graphThemeLayer . createThematicFeature ( feature ) ;
291+ expect ( graphThemeLayer ) . not . toBeNull ( ) ;
292+ graphThemeLayer . clear ( ) ;
293+ } ) ;
294+
295+
296+ } ) ;
0 commit comments