@@ -6,15 +6,14 @@ describe('openlayers_graph', function () {
66 var originalTimeout ;
77 var testDiv , map ;
88 beforeAll ( function ( ) {
9- testDiv = document . createElement ( "div" ) ;
9+ testDiv = window . document . createElement ( "div" ) ;
1010 testDiv . setAttribute ( "id" , "map" ) ;
1111 testDiv . style . styleFloat = "left" ;
1212 testDiv . style . marginLeft = "8px" ;
1313 testDiv . style . marginTop = "50px" ;
1414 testDiv . style . width = "500px" ;
1515 testDiv . style . height = "500px" ;
16- document . body . appendChild ( testDiv ) ;
17-
16+ window . document . body . appendChild ( testDiv ) ;
1817 map = new ol . Map ( {
1918 target : 'map' ,
2019 view : new ol . View ( {
@@ -38,7 +37,8 @@ describe('openlayers_graph', function () {
3837 jasmine . DEFAULT_TIMEOUT_INTERVAL = originalTimeout ;
3938 } ) ;
4039 afterAll ( function ( ) {
41- document . body . removeChild ( testDiv ) ;
40+ window . document . body . removeChild ( testDiv ) ;
41+ map . remove ( ) ;
4242 } ) ;
4343
4444 it ( 'construtor and destroy' , function ( ) {
@@ -67,7 +67,6 @@ describe('openlayers_graph', function () {
6767 barLinearGradient : [ [ "#00FF00" , "#00CD00" ] , [ "#00CCFF" , "#5E87A2" ] , [ "#00FF66" , "#669985" ] , [ "#CCFF00" , "#94A25E" ] , [ "#FF9900" , "#A2945E" ] ]
6868 }
6969 } ) ;
70-
7170 expect ( barThemeLayer ) . not . toBeNull ( ) ;
7271 expect ( barThemeLayer . chartsType ) . toBe ( "Bar" ) ;
7372 expect ( barThemeLayer . charts . length ) . toEqual ( 0 ) ;
@@ -91,7 +90,7 @@ describe('openlayers_graph', function () {
9190 barThemeLayer . destroy ( ) ;
9291 } ) ;
9392
94- xit ( 'setChartsType' , function ( ) {
93+ it ( 'setChartsType' , function ( ) {
9594 var graphThemeSource = new ol . source . Graph ( "BarThemeLayer" , "Bar" , {
9695 map : map ,
9796 chartsSetting : {
@@ -100,15 +99,92 @@ describe('openlayers_graph', function () {
10099 codomain : [ 0 , 40000 ]
101100 }
102101 } ) ;
103-
104102 var layer = new ol . layer . Image ( {
105103 source : graphThemeSource
106104 } ) ;
107105 map . addLayer ( layer ) ;
108-
109106 expect ( graphThemeSource . chartsType ) . toBe ( "Bar" ) ;
110107 graphThemeSource . setChartsType ( "Line" ) ;
111108 expect ( graphThemeSource . chartsType ) . toBe ( "Line" ) ;
109+ graphThemeSource . clear ( ) ;
110+ } ) ;
111+
112+ it ( 'addFeatures and removeFeatures' , function ( ) {
113+ var graphThemeSource = new ol . source . Graph ( "BarThemeLayer" , "Bar" , {
114+ map : map
115+ } ) ;
116+ graphThemeSource . themeFields = [ "CON2009" , "CON2010" , "CON2011" , "CON2012" , "CON2013" ] ;
117+ graphThemeSource . chartsSetting = {
118+ width : 240 ,
119+ height : 100 ,
120+ codomain : [ 0 , 40000 ] ,
121+ barStyle : { fillOpacity : 0.7 } ,
122+ barHoverStyle : { fillOpacity : 1 } ,
123+ xShapeBlank : [ 10 , 10 , 10 ] ,
124+ axisYTick : 4 ,
125+ axisYLabels : [ "4万" , "3万" , "2万" , "1万" , "0" ] ,
126+ axisXLabels : [ "09年" , "10年" , "11年" , "12年" , "13年" ] ,
127+ backgroundStyle : { fillColor : "#CCE8CF" } ,
128+ backgroundRadius : [ 5 , 5 , 5 , 5 ] ,
129+ showShadow : true ,
130+ barShadowStyle : { shadowBlur : 8 , shadowOffsetX : 2 , shadowOffsetY : 2 , shadowColor : "rgba(100,100,100,0.8)" } ,
131+ barLinearGradient : [ [ "#00FF00" , "#00CD00" ] , [ "#00CCFF" , "#5E87A2" ] , [ "#00FF66" , "#669985" ] , [ "#CCFF00" , "#94A25E" ] , [ "#FF9900" , "#A2945E" ] ]
132+ } ;
133+ var layer = new ol . layer . Image ( {
134+ source : graphThemeSource
135+ } ) ;
136+ map . addLayer ( layer ) ;
137+ expect ( graphThemeSource . features . length ) . toEqual ( 0 ) ;
138+ var features = [ ] ;
139+ for ( var i = 0 , len = chinaConsumptionLevel . length ; i < len ; i ++ ) {
140+ var provinceInfo = chinaConsumptionLevel [ i ] ;
141+ var geometry = new ol . geom . Point ( [ provinceInfo [ 1 ] , provinceInfo [ 2 ] ] ) ;
142+ var atrributes = { } ;
143+ atrributes . NAME = provinceInfo [ 0 ] ;
144+ atrributes . CON2009 = provinceInfo [ 3 ] ;
145+ atrributes . CON2010 = provinceInfo [ 4 ] ;
146+ atrributes . CON2011 = provinceInfo [ 5 ] ;
147+ atrributes . CON2012 = provinceInfo [ 6 ] ;
148+ atrributes . CON2013 = provinceInfo [ 7 ] ;
149+ var fea = new ol . supermap . ThemeFeature ( geometry , atrributes ) ;
150+ features . push ( fea ) ;
151+ }
152+ graphThemeSource . addFeatures ( features ) ;
153+ var LayerFeatures = graphThemeSource . features ;
154+ expect ( LayerFeatures . length ) . toBeGreaterThan ( 0 ) ;
155+ for ( var j = 0 ; j < LayerFeatures . length ; j ++ ) {
156+ expect ( LayerFeatures [ j ] . CLASS_NAME ) . toBe ( "SuperMap.Feature.Vector" ) ;
157+ expect ( LayerFeatures [ j ] . id ) . toContain ( "SuperMap.Feature" ) ;
158+ expect ( LayerFeatures [ j ] . attributes ) . not . toBeNull ( ) ;
159+ expect ( LayerFeatures [ j ] . geometry ) . not . toBeNull ( ) ;
160+ expect ( LayerFeatures [ j ] . geometry . CLASS_NAME ) . toBe ( "SuperMap.Geometry.Point" ) ;
161+ expect ( LayerFeatures [ j ] . geometry . id ) . toContain ( "SuperMap.Geometry" ) ;
162+ expect ( LayerFeatures [ j ] . geometry . x ) . not . toBeNull ( ) ;
163+ expect ( LayerFeatures [ j ] . geometry . y ) . not . toBeNull ( ) ;
164+ }
165+ expect ( LayerFeatures [ 0 ] . geometry . x ) . toEqual ( 116.407283 ) ;
166+ expect ( LayerFeatures [ 0 ] . geometry . y ) . toEqual ( 39.904557 ) ;
167+ expect ( LayerFeatures [ 0 ] . data ) . toEqual ( LayerFeatures [ 0 ] . attributes ) ;
168+ expect ( LayerFeatures [ 0 ] . attributes ) . toEqual ( Object ( {
169+ CON2009 : 22023 ,
170+ CON2010 : 24982 ,
171+ CON2011 : 27760 ,
172+ CON2012 : 30350 ,
173+ CON2013 : 33337 ,
174+ NAME : "北京市"
175+ } ) ) ;
176+ var shape1 = graphThemeSource . getShapesByFeatureID ( ) ;
177+ var shape2 = graphThemeSource . getShapesByFeatureID ( LayerFeatures [ 0 ] . id ) ;
178+ expect ( shape1 . length ) . toEqual ( 17 ) ;
179+ expect ( shape2 . length ) . toEqual ( 5 ) ;
180+ graphThemeSource . features [ 0 ] . geometry . x = 39 ;
181+ var redraw = graphThemeSource . redraw ( ) ;
182+ expect ( redraw ) . toBeTruthy ( ) ;
183+ expect ( graphThemeSource . features [ 0 ] . geometry . x ) . toEqual ( 39 ) ;
184+ graphThemeSource . removeFeatures ( ) ;
185+ graphThemeSource . removeAllFeatures ( ) ;
186+ expect ( graphThemeSource . features . length ) . toEqual ( 0 ) ;
187+ graphThemeSource . clear ( ) ;
112188 } ) ;
113189
114190 it ( 'isQuadrilateralOverLap' , function ( ) {
@@ -126,9 +202,10 @@ describe('openlayers_graph', function () {
126202 quadrilateral2 = [ { "x" : 1 , "y" : 1 } , { "x" : 3 , "y" : 1 } , { "x" : 6 , "y" : 4 } , { "x" : 2 , "y" : 10 } , { "x" : 1 , "y" : 1 } ] ;
127203 var isPointInPoly = graphThemeSource . isQuadrilateralOverLap ( quadrilateral , quadrilateral2 ) ;
128204 expect ( isPointInPoly ) . toBeTruthy ( ) ;
205+ graphThemeSource . clear ( ) ;
129206 } ) ;
130207
131- // 此方法为iclient8的私有方法,不支持leaflet对象 ,此处测试传入iclient对象的情况
208+ // 此方法为iclient8的私有方法,不支持openlayers对象 ,此处测试传入iclient对象的情况
132209 it ( 'isPointInPoly' , function ( ) {
133210 var graphThemeSource = new ol . source . Graph ( "BarThemeLayer" , "Bar" , {
134211 map : map ,
@@ -143,9 +220,10 @@ describe('openlayers_graph', function () {
143220 var polygon = [ { "x" : 1 , "y" : 1 } , { "x" : 3 , "y" : 1 } , { "x" : 6 , "y" : 4 } , { "x" : 2 , "y" : 10 } , { "x" : 1 , "y" : 1 } ] ;
144221 var isPointInPoly = graphThemeSource . isPointInPoly ( point , polygon ) ;
145222 expect ( isPointInPoly ) . toBeTruthy ( ) ;
223+ graphThemeSource . clear ( ) ;
146224 } ) ;
147225
148- it ( 'drawCharts' , function ( ) {
226+ it ( 'drawCharts' , function ( done ) {
149227 var graphThemeSource = new ol . source . Graph ( "BarThemeLayer" , "Bar" , {
150228 map : map ,
151229 themeFields : [ "CON2009" , "CON2010" , "CON2011" , "CON2012" , "CON2013" ] ,
@@ -175,38 +253,14 @@ describe('openlayers_graph', function () {
175253 source : graphThemeSource
176254 } ) ;
177255 map . addLayer ( layer ) ;
256+ expect ( graphThemeSource ) . not . toBeNull ( ) ;
257+ expect ( graphThemeSource . context ) . toBeUndefined ( ) ;
258+ graphThemeSource . drawCharts ( ) ;
178259 setTimeout ( function ( ) {
179- graphThemeSource . drawCharts ( ) ;
180- expect ( graphThemeSource ) . not . toBeNull ( ) ;
181- } , 5000 ) ;
182- } ) ;
183-
184- xit ( 'removeFeatures' , function ( ) {
185- var graphThemeSource = new ol . source . Graph ( "BarThemeLayer" , "Bar" , {
186- map : map ,
187- themeFields : [ "CON2009" , "CON2010" , "CON2011" , "CON2012" , "CON2013" ] ,
188- chartsSetting : {
189- width : 240 ,
190- height : 100 ,
191- codomain : [ 0 , 40000 ] ,
192- }
193- } ) ;
194- var layer = new ol . layer . Image ( {
195- source : graphThemeSource
196- } ) ;
197- map . addLayer ( layer ) ;
198- var features = [ ] ;
199- for ( var i = 0 , len = chinaConsumptionLevel . length ; i < len ; i ++ ) {
200- var provinceInfo = chinaConsumptionLevel [ i ] ;
201- var geometry = new ol . geom . Point ( provinceInfo [ 2 ] , provinceInfo [ 1 ] ) ;
202- var fea = new ol . supermap . ThemeFeature ( geometry ) ;
203- features . push ( fea ) ;
204- }
205- graphThemeSource . addFeatures ( features ) ;
206- expect ( graphThemeSource . features . length ) . toBeGreaterThan ( 0 ) ;
207- graphThemeSource . removeFeatures ( ) ;
208- graphThemeSource . removeAllFeatures ( ) ;
209- expect ( graphThemeSource . features . length ) . toEqual ( 0 ) ;
260+ expect ( graphThemeSource . context ) . not . toBeUndefined ( ) ;
261+ graphThemeSource . clear ( ) ;
262+ done ( ) ;
263+ } , 3000 ) ;
210264 } ) ;
211265
212266 it ( 'clearCache' , function ( ) {
@@ -228,45 +282,6 @@ describe('openlayers_graph', function () {
228282 graphThemeSource . clearCache ( ) ;
229283 expect ( graphThemeSource . charts . length ) . toEqual ( 0 ) ;
230284 expect ( graphThemeSource . cache ) . toEqual ( Object ( { } ) ) ;
231- } ) ;
232-
233- xit ( 'createThematicFeature' , function ( ) {
234- var graphThemeSource = new ol . source . Graph ( "BarThemeLayer" , "Bar" , {
235- map : map ,
236- themeFields : [ "CON2009" , "CON2010" , "CON2011" , "CON2012" , "CON2013" ] ,
237- chartsSetting : {
238- width : 240 ,
239- height : 100 ,
240- codomain : [ 0 , 40000 ] ,
241- barStyle : { fillOpacity : 0.7 } ,
242- barHoverStyle : { fillOpacity : 1 } ,
243- xShapeBlank : [ 10 , 10 , 10 ] ,
244- axisYTick : 4 ,
245- axisYLabels : [ "4万" , "3万" , "2万" , "1万" , "0" ] ,
246- axisXLabels : [ "09年" , "10年" , "11年" , "12年" , "13年" ] ,
247- backgroundStyle : { fillColor : "#CCE8CF" } ,
248- backgroundRadius : [ 5 , 5 , 5 , 5 ] ,
249- showShadow : true ,
250- barShadowStyle : {
251- shadowBlur : 8 ,
252- shadowOffsetX : 2 ,
253- shadowOffsetY : 2 ,
254- shadowColor : "rgba(100,100,100,0.8)"
255- } ,
256- barLinearGradient : [ [ "#00FF00" , "#00CD00" ] , [ "#00CCFF" , "#5E87A2" ] , [ "#00FF66" , "#669985" ] , [ "#CCFF00" , "#94A25E" ] , [ "#FF9900" , "#A2945E" ] ]
257- }
258- } ) ;
259- var provinceInfo = chinaConsumptionLevel [ 0 ] ;
260- var geo = new SuperMap . Geometry . Point ( provinceInfo [ 1 ] , provinceInfo [ 2 ] ) ;
261- var attrs = { } ;
262- attrs . NAME = provinceInfo [ 0 ] ;
263- attrs . CON2009 = provinceInfo [ 3 ] ;
264- attrs . CON2010 = provinceInfo [ 4 ] ;
265- attrs . CON2011 = provinceInfo [ 5 ] ;
266- attrs . CON2012 = provinceInfo [ 6 ] ;
267- attrs . CON2013 = provinceInfo [ 7 ] ;
268- var feature = new SuperMap . Feature . Vector ( geo , attrs ) ;
269- graphThemeSource . createThematicFeature ( feature ) ;
270- expect ( graphThemeSource ) . not . toBeNull ( ) ;
285+ graphThemeSource . clear ( ) ;
271286 } ) ;
272287} ) ;
0 commit comments