Skip to content

Commit 8ffb6ac

Browse files
committed
补充UT。review by chenmy
1 parent 216f460 commit 8ffb6ac

File tree

9 files changed

+7797
-3
lines changed

9 files changed

+7797
-3
lines changed

test/common/commontypes/geometry/GeoTextSpec.js

Lines changed: 253 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require('../../../../src/common/commontypes/geometry/GeoText');
22

33
describe('GeoText', function () {
4-
it('initialize, destroy', function () {
4+
it('constructor, destroy', function () {
55
var x = 100, y = 35, text = "中华人民共和国";
66
var geoText = new SuperMap.Geometry.GeoText(x, y, text);
77
geoText.bsInfo = {
@@ -56,4 +56,256 @@ describe('GeoText', function () {
5656
expect(geoText.bounds.left).toEqual(x);
5757
geoText.destroy();
5858
});
59+
60+
//获取标签对象的质心
61+
it('getCentroid', function () {
62+
var x = 100, y = 35, text = "中华人民共和国";
63+
var geoText = new SuperMap.Geometry.GeoText(x, y, text);
64+
var centroid = geoText.getCentroid();
65+
expect(centroid).not.toBeNull();
66+
expect(centroid.CLASS_NAME).toEqual("SuperMap.Geometry.Point");
67+
expect(centroid.id).not.toBeNull();
68+
expect(centroid.type).toEqual("Point");
69+
expect(centroid.x).toEqual(100);
70+
expect(centroid.y).toEqual(35);
71+
geoText.destroy();
72+
});
73+
74+
//根据绘制好的标签获取文字标签的像素范围,参数的单位是像素
75+
it('getLabelPxBoundsByLabel', function () {
76+
var x = 0, y = 0, text = "test";
77+
var geoText = new SuperMap.Geometry.GeoText(x, y, text);
78+
var locationPixel = {X: 0, y: 0};
79+
var labelWidth = "100px";
80+
var labelHeight = "60px";
81+
var style = {
82+
fill: true,
83+
fillColor: "#FFFFFF",
84+
fillOpacity: 1,
85+
fontColor: "#000000",
86+
fontFamily: "arial,sans-serif",
87+
fontOpacity: 1,
88+
fontSize: "12px",
89+
fontStyle: "normal",
90+
fontVariant: "normal",
91+
fontWeight: "bolder",
92+
label: "13",
93+
labelAlign: "center",
94+
labelBaseline: "middle",
95+
labelPosition: "top",
96+
labelRect: true,
97+
labelRotation: 0,
98+
labelSelect: true,
99+
labelXOffset: 0,
100+
labelYOffset: 0,
101+
pointRadius: 6,
102+
shadowBlur: 0,
103+
shadowColor: "#000000",
104+
shadowOffsetX: 0,
105+
shadowOffsetY: 0,
106+
stroke: false,
107+
strokeColor: "#8B7B8B",
108+
strokeDashstyle: "solid",
109+
strokeLineJoin: "miter",
110+
strokeLinecap: "butt",
111+
strokeOpacity: 1,
112+
strokeWidth: 1
113+
};
114+
var labelBounds = geoText.getLabelPxBoundsByLabel(locationPixel, labelWidth, labelHeight, style);
115+
expect(labelBounds).not.toBeNull();
116+
expect(labelBounds.CLASS_NAME).toEqual("SuperMap.Bounds");
117+
expect(labelBounds.bottom).toEqual(30);
118+
expect(labelBounds.top).toEqual(-30);
119+
//测试style.labelAlign在不同取值下的标签的像素范围
120+
style.labelAlign = "lt";
121+
var labelBounds_lt = geoText.getLabelPxBoundsByLabel(locationPixel, labelWidth, labelHeight, style);
122+
expect(labelBounds_lt).not.toBeNull();
123+
expect(labelBounds.CLASS_NAME).toEqual("SuperMap.Bounds");
124+
expect(labelBounds.bottom).toEqual(30);
125+
expect(labelBounds.top).toEqual(-30);
126+
style.labelAlign = "lm";
127+
var labelBounds_lm = geoText.getLabelPxBoundsByLabel(locationPixel, labelWidth, labelHeight, style);
128+
expect(labelBounds_lm).not.toBeNull();
129+
expect(labelBounds.CLASS_NAME).toEqual("SuperMap.Bounds");
130+
expect(labelBounds.bottom).toEqual(30);
131+
expect(labelBounds.top).toEqual(-30);
132+
style.labelAlign = "lb";
133+
var labelBounds_lb = geoText.getLabelPxBoundsByLabel(locationPixel, labelWidth, labelHeight, style);
134+
expect(labelBounds_lb).not.toBeNull();
135+
expect(labelBounds.CLASS_NAME).toEqual("SuperMap.Bounds");
136+
expect(labelBounds.bottom).toEqual(30);
137+
expect(labelBounds.top).toEqual(-30);
138+
style.labelAlign = "ct";
139+
var labelBounds_ct = geoText.getLabelPxBoundsByLabel(locationPixel, labelWidth, labelHeight, style);
140+
expect(labelBounds_ct).not.toBeNull();
141+
expect(labelBounds.CLASS_NAME).toEqual("SuperMap.Bounds");
142+
expect(labelBounds.bottom).toEqual(30);
143+
expect(labelBounds.top).toEqual(-30);
144+
style.labelAlign = "cb";
145+
var labelBounds_cb = geoText.getLabelPxBoundsByLabel(locationPixel, labelWidth, labelHeight, style);
146+
expect(labelBounds_cb).not.toBeNull();
147+
expect(labelBounds.CLASS_NAME).toEqual("SuperMap.Bounds");
148+
expect(labelBounds.bottom).toEqual(30);
149+
expect(labelBounds.top).toEqual(-30);
150+
style.labelAlign = "rt";
151+
var labelBounds_rt = geoText.getLabelPxBoundsByLabel(locationPixel, labelWidth, labelHeight, style);
152+
expect(labelBounds_rt).not.toBeNull();
153+
expect(labelBounds.CLASS_NAME).toEqual("SuperMap.Bounds");
154+
expect(labelBounds.bottom).toEqual(30);
155+
expect(labelBounds.top).toEqual(-30);
156+
style.labelAlign = "rm";
157+
var labelBounds_rm = geoText.getLabelPxBoundsByLabel(locationPixel, labelWidth, labelHeight, style);
158+
expect(labelBounds_rm).not.toBeNull();
159+
expect(labelBounds.CLASS_NAME).toEqual("SuperMap.Bounds");
160+
expect(labelBounds.bottom).toEqual(30);
161+
expect(labelBounds.top).toEqual(-30);
162+
style.labelAlign = "rb";
163+
var labelBounds_rb = geoText.getLabelPxBoundsByLabel(locationPixel, labelWidth, labelHeight, style);
164+
expect(labelBounds_rb).not.toBeNull();
165+
expect(labelBounds.CLASS_NAME).toEqual("SuperMap.Bounds");
166+
expect(labelBounds.bottom).toEqual(30);
167+
expect(labelBounds.top).toEqual(-30);
168+
geoText.destroy();
169+
});
170+
171+
// 根据文本内容获取文字标签的像素范围 处理斜体字
172+
it('getLabelPxBoundsByText_italic', function () {
173+
var x = 0, y = 0, text = "test";
174+
var geoText = new SuperMap.Geometry.GeoText(x, y, text);
175+
var locationPixel = {X: 10, y: 10};
176+
var style = {
177+
fill: true,
178+
fillColor: "#FFFFFF",
179+
fillOpacity: 1,
180+
fontColor: "#000000",
181+
fontFamily: "arial,sans-serif",
182+
fontOpacity: 1,
183+
fontSize: "12px",
184+
fontStyle: "italic",
185+
fontVariant: "normal",
186+
fontWeight: "bolder",
187+
label: "13",
188+
labelAlign: "center",
189+
labelBaseline: "middle",
190+
labelPosition: "top",
191+
labelRect: true,
192+
labelRotation: 0,
193+
labelSelect: true,
194+
labelXOffset: 0,
195+
labelYOffset: 0,
196+
pointRadius: 6,
197+
shadowBlur: 0,
198+
shadowColor: "#000000",
199+
shadowOffsetX: 0,
200+
shadowOffsetY: 0,
201+
stroke: false,
202+
strokeColor: "#8B7B8B",
203+
strokeDashstyle: "solid",
204+
strokeLineJoin: "miter",
205+
strokeLinecap: "butt",
206+
strokeOpacity: 1,
207+
strokeWidth: 1
208+
};
209+
var labelBounds = geoText.getLabelPxBoundsByText(locationPixel, style);
210+
expect(labelBounds).not.toBeNull();
211+
expect(labelBounds.CLASS_NAME).toEqual("SuperMap.Bounds");
212+
expect(labelBounds.bottom).toEqual(18.2);
213+
expect(labelBounds.top).toEqual(1.8);
214+
//测试style.labelAlign在不同取值下的标签的像素范围
215+
style.labelAlign = "lt";
216+
var labelBounds_lt = geoText.getLabelPxBoundsByText(locationPixel, style);
217+
expect(labelBounds_lt).not.toBeNull();
218+
expect(labelBounds.CLASS_NAME).toEqual("SuperMap.Bounds");
219+
expect(labelBounds.bottom).toEqual(18.2);
220+
expect(labelBounds.top).toEqual(1.8);
221+
style.labelAlign = "lm";
222+
var labelBounds_lm = geoText.getLabelPxBoundsByText(locationPixel, style);
223+
expect(labelBounds_lm).not.toBeNull();
224+
expect(labelBounds.CLASS_NAME).toEqual("SuperMap.Bounds");
225+
expect(labelBounds.bottom).toEqual(18.2);
226+
expect(labelBounds.top).toEqual(1.8);
227+
style.labelAlign = "lb";
228+
var labelBounds_lb = geoText.getLabelPxBoundsByText(locationPixel, style);
229+
expect(labelBounds_lb).not.toBeNull();
230+
expect(labelBounds.CLASS_NAME).toEqual("SuperMap.Bounds");
231+
expect(labelBounds.bottom).toEqual(18.2);
232+
expect(labelBounds.top).toEqual(1.8);
233+
style.labelAlign = "ct";
234+
var labelBounds_ct = geoText.getLabelPxBoundsByText(locationPixel, style);
235+
expect(labelBounds_ct).not.toBeNull();
236+
expect(labelBounds.CLASS_NAME).toEqual("SuperMap.Bounds");
237+
expect(labelBounds.bottom).toEqual(18.2);
238+
expect(labelBounds.top).toEqual(1.8);
239+
style.labelAlign = "cb";
240+
var labelBounds_cb = geoText.getLabelPxBoundsByText(locationPixel, style);
241+
expect(labelBounds_cb).not.toBeNull();
242+
expect(labelBounds.CLASS_NAME).toEqual("SuperMap.Bounds");
243+
expect(labelBounds.bottom).toEqual(18.2);
244+
expect(labelBounds.top).toEqual(1.8);
245+
style.labelAlign = "rt";
246+
var labelBounds_rt = geoText.getLabelPxBoundsByText(locationPixel, style);
247+
expect(labelBounds_rt).not.toBeNull();
248+
expect(labelBounds.CLASS_NAME).toEqual("SuperMap.Bounds");
249+
expect(labelBounds.bottom).toEqual(18.2);
250+
expect(labelBounds.top).toEqual(1.8);
251+
style.labelAlign = "rm";
252+
var labelBounds_rm = geoText.getLabelPxBoundsByText(locationPixel, style);
253+
expect(labelBounds_rm).not.toBeNull();
254+
expect(labelBounds.CLASS_NAME).toEqual("SuperMap.Bounds");
255+
expect(labelBounds.bottom).toEqual(18.2);
256+
expect(labelBounds.top).toEqual(1.8);
257+
style.labelAlign = "rb";
258+
var labelBounds_rb = geoText.getLabelPxBoundsByText(locationPixel, style);
259+
expect(labelBounds_rb).not.toBeNull();
260+
expect(labelBounds.CLASS_NAME).toEqual("SuperMap.Bounds");
261+
expect(labelBounds.bottom).toEqual(18.2);
262+
expect(labelBounds.top).toEqual(1.8);
263+
geoText.destroy();
264+
});
265+
266+
// 根据文本内容获取文字标签的像素范围 正常字体
267+
it('getLabelPxBoundsByText_normalontStyle', function () {
268+
var x = 0, y = 0, text = "test";
269+
var geoText = new SuperMap.Geometry.GeoText(x, y, text);
270+
var locationPixel = {X: 10, y: 10};
271+
var style = {
272+
fill: true,
273+
fillColor: "#FFFFFF",
274+
fillOpacity: 1,
275+
fontColor: "#000000",
276+
fontFamily: "arial,sans-serif",
277+
fontOpacity: 1,
278+
fontSize: "12px",
279+
fontStyle: "normal",
280+
fontVariant: "normal",
281+
fontWeight: "bolder",
282+
label: "13",
283+
labelAlign: "center",
284+
labelBaseline: "middle",
285+
labelPosition: "top",
286+
labelRect: true,
287+
labelRotation: 0,
288+
labelSelect: true,
289+
labelXOffset: 0,
290+
labelYOffset: 0,
291+
pointRadius: 6,
292+
shadowBlur: 0,
293+
shadowColor: "#000000",
294+
shadowOffsetX: 0,
295+
shadowOffsetY: 0,
296+
stroke: false,
297+
strokeColor: "#8B7B8B",
298+
strokeDashstyle: "solid",
299+
strokeLineJoin: "miter",
300+
strokeLinecap: "butt",
301+
strokeOpacity: 1,
302+
strokeWidth: 1
303+
};
304+
var labelBounds = geoText.getLabelPxBoundsByText(locationPixel, style);
305+
expect(labelBounds).not.toBeNull();
306+
expect(labelBounds.CLASS_NAME).toEqual("SuperMap.Bounds");
307+
expect(labelBounds.bottom).toEqual(18.2);
308+
expect(labelBounds.top).toEqual(1.8);
309+
geoText.destroy();
310+
});
59311
});

0 commit comments

Comments
 (0)