Skip to content

Commit 3c4a4a1

Browse files
增加leaflet客户端graphThemeLayer单元测试。review by zhurch
1 parent 46a9427 commit 3c4a4a1

File tree

4 files changed

+349
-14
lines changed

4 files changed

+349
-14
lines changed

karma.conf.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ module.exports = function (config) {
3030
'src/common/style/CartoCSS.js',
3131
'src/common/**/*.js',
3232
/***Leaflet文件夹下的源码添加至此,暂未添加***/
33+
{pattern: './node_modules/leaflet/dist/leaflet.css', include: false},
3334
'src/leaflet/**/*.js',
3435
'src/leaflet/overlay/**/*.js',
3536
/***OL3文件夹下的源码添加至此,暂未添加***/
3637
//'src/openlayers/**/*.js',
3738
//'src/openlayers/overlay/**/*.js',
3839

3940
/***以下全是测试文件***/
40-
'test/tool/GlobeParameter.js',
41+
'test/tool/**.js',
4142
/**common --iServer**/
4243
//'test/common/iServer/AreaSolarRadiationServiceSpec.js', //iclient8注释掉
4344
'test/common/iServer/BufferAnalystServiceSpec.js',
@@ -116,6 +117,7 @@ module.exports = function (config) {
116117
'test/leaflet/services/AddressServiceSpec.js',
117118
'test/leaflet/services/FieldServiceSpec.js',
118119
'test/leaflet/services/ThemeServiceSpec.js',
120+
'test/leaflet/overlay/theme/GraphThemeLayerSpec.js',
119121

120122
/**openlayers --services**/
121123
//'test/openlayers/services/QueryServiceSpec.js'
Lines changed: 296 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,296 @@
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+
});

test/tool/GlobeParameter.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@
44
worldMapURL: "http://localhost:8090/iserver/services/map-world/rest/maps/世界地图",
55
networkAnalystURL: "http://localhost:8090/iserver/services/transportationanalyst-sample/rest/networkanalyst/RoadNet@Changchun",
66
spatialAnalystURL: "http://localhost:8090/iserver/services/spatialanalyst-sample/restjsr/spatialanalyst",
7-
spatialAnalystURL_Changchun:"http://localhost:8090/iserver/services/spatialanalyst-changchun/restjsr/spatialanalyst",
7+
spatialAnalystURL_Changchun: "http://localhost:8090/iserver/services/spatialanalyst-changchun/restjsr/spatialanalyst",
88
dataServiceURL: "http://localhost:8090/iserver/services/data-world/rest/data",
99
editServiceURL: "http://localhost:8090/iserver/services/data-jingjin/rest/data/datasources/Jingjin/datasets/Landuse_R",
10-
editServiceURL_LINE:"http://localhost:8090/iserver/services/data-jingjin/rest/data/datasources/Jingjin/datasets/Geomor_L",
11-
editServiceURL_POINT:"http://localhost:8090/iserver/services/data-jingjin/rest/data/datasources/Jingjin/datasets/Neighbor_P",
10+
editServiceURL_LINE: "http://localhost:8090/iserver/services/data-jingjin/rest/data/datasources/Jingjin/datasets/Geomor_L",
11+
editServiceURL_POINT: "http://localhost:8090/iserver/services/data-jingjin/rest/data/datasources/Jingjin/datasets/Neighbor_P",
1212
trafficTransferURL: "http://localhost:8090/iserver/services/traffictransferanalyst-sample/restjsr/traffictransferanalyst/Traffic-Changchun",
13-
vectorURL: "http://localhost:8090/iserver/services/map-world/rest/maps/World/",
14-
gridURL:"http://localhost:8090/iserver/services/map-jingjin/rest/maps/京津地区土地利用现状图",
15-
imageURL: "http://localhost:8090/iserver/services/map-world/rest/maps/世界地图_Day",
16-
WorldURL: "http://localhost:8090/iserver/services/map-world/rest/maps/World",
17-
ChinaURL:"http://localhost:8090/iserver/services/map-china400/rest/maps/China",
18-
WMTSURL:"http://localhost:8090/iserver/services/map-world/wmts100",
19-
WCSURL: "http://localhost:8090/iserver/services/data-world/wcs111",
20-
plotUrl: "http://localhost:8090/iserver/services/plot-jingyong/rest/plot",
13+
vectorURL: "http://localhost:8090/iserver/services/map-world/rest/maps/World/",
14+
gridURL: "http://localhost:8090/iserver/services/map-jingjin/rest/maps/京津地区土地利用现状图",
15+
imageURL: "http://localhost:8090/iserver/services/map-world/rest/maps/世界地图_Day",
16+
WorldURL: "http://localhost:8090/iserver/services/map-world/rest/maps/World",
17+
ChinaURL: "http://localhost:8090/iserver/services/map-china400/rest/maps/China",
18+
WMTSURL: "http://localhost:8090/iserver/services/map-world/wmts100",
19+
WCSURL: "http://localhost:8090/iserver/services/data-world/wcs111",
20+
plotUrl: "http://localhost:8090/iserver/services/plot-jingyong/rest/plot",
2121
tileSetsURL: "http://localhost:8090/iserver/services/map-ChinaProvinces/rest/maps/ChinaProvinces",
2222
addressMatchURL: "http://localhost:8090/iserver/services/addressmatch-BeijingAddress/restjsr/v1/address",
23-
jingjinMapURL : "http://localhost:8090/iserver/services/map-jingjin/rest",
23+
jingjinMapURL: "http://localhost:8090/iserver/services/map-jingjin/rest",
2424
editServiceURL_leaflet: "http://localhost:8090/iserver/services/data-jingjin/rest/data",
25-
};
25+
China4326URL: "http://localhost:8090/iserver/services/map-china400/rest/maps/China_4326"
26+
}

0 commit comments

Comments
 (0)