提交 | 用户 | 时间
|
58d006
|
1 |
describe("Drawing geometry overlays", function() { |
A |
2 |
var map_with_polygons, line, rectangle, circle, polygon; |
|
3 |
|
|
4 |
beforeEach(function() { |
|
5 |
map_with_polygons = map_with_polygons || new GMaps({ |
|
6 |
el : '#map-with-polygons', |
|
7 |
lat : -12.0433, |
|
8 |
lng : -77.0283, |
|
9 |
zoom : 12 |
|
10 |
}); |
|
11 |
}); |
|
12 |
|
|
13 |
describe("A line", function() { |
|
14 |
beforeEach(function() { |
|
15 |
line = line || map_with_polygons.drawPolyline({ |
|
16 |
path : [[-12.0440, -77.0247], [-12.0544, -77.0302], [-12.0551, -77.0303], [-12.0759, -77.0276], [-12.0763, -77.0279], [-12.0768, -77.0289], [-12.0885, -77.0241], [-12.0908, -77.0227]], |
|
17 |
strokeColor : '#131540', |
|
18 |
strokeOpacity : 0.6, |
|
19 |
strokeWeight : 6 |
|
20 |
}); |
|
21 |
}); |
|
22 |
|
|
23 |
it("should add the line to the polylines collection", function() { |
|
24 |
expect(map_with_polygons.polylines.length).toEqual(1); |
|
25 |
expect(map_with_polygons.polylines[0]).toEqual(line); |
|
26 |
}); |
|
27 |
|
|
28 |
it("should be added in the current map", function() { |
|
29 |
expect(line.getMap()).toEqual(map_with_polygons.map); |
|
30 |
}); |
|
31 |
|
|
32 |
it("should return the defined path", function() { |
|
33 |
var first_point = line.getPath().getAt(0); |
|
34 |
|
|
35 |
expect(parseFloat(first_point.lat().toFixed(4))).toEqual(-12.0440); |
|
36 |
expect(parseFloat(first_point.lng().toFixed(4))).toEqual(-77.0247); |
|
37 |
}); |
|
38 |
}); |
|
39 |
|
|
40 |
describe("A rectangle", function() { |
|
41 |
beforeEach(function() { |
|
42 |
rectangle = rectangle || map_with_polygons.drawRectangle({ |
|
43 |
bounds : [[-12.0303,-77.0237],[-12.0348,-77.0115]], |
|
44 |
strokeColor : '#BBD8E9', |
|
45 |
strokeOpacity : 1, |
|
46 |
strokeWeight : 3, |
|
47 |
fillColor : '#BBD8E9', |
|
48 |
fillOpacity : 0.6 |
|
49 |
}); |
|
50 |
}); |
|
51 |
|
|
52 |
it("should add the rectangle to the polygons collection", function() { |
|
53 |
expect(map_with_polygons.polygons.length).toEqual(1); |
|
54 |
expect(map_with_polygons.polygons[0]).toEqual(rectangle); |
|
55 |
}); |
|
56 |
|
|
57 |
it("should be added in the current map", function() { |
|
58 |
expect(rectangle.getMap()).toEqual(map_with_polygons.map); |
|
59 |
}); |
|
60 |
|
|
61 |
it("should have the defined bounds", function() { |
|
62 |
// Fix for floating-point bug |
|
63 |
var SWLat = parseFloat(rectangle.getBounds().getSouthWest().lat().toFixed(4)); |
|
64 |
var SWLng = parseFloat(rectangle.getBounds().getSouthWest().lng().toFixed(4)); |
|
65 |
|
|
66 |
var NELat = parseFloat(rectangle.getBounds().getNorthEast().lat().toFixed(4)); |
|
67 |
var NELng = parseFloat(rectangle.getBounds().getNorthEast().lng().toFixed(4)); |
|
68 |
|
|
69 |
expect(SWLat).toEqual(-12.0303); |
|
70 |
expect(SWLng).toEqual(-77.0237); |
|
71 |
expect(NELat).toEqual(-12.0348); |
|
72 |
expect(NELng).toEqual(-77.0115); |
|
73 |
}); |
|
74 |
}); |
|
75 |
|
|
76 |
describe("A polygon", function() { |
|
77 |
beforeEach(function() { |
|
78 |
polygon = polygon || map_with_polygons.drawPolygon({ |
|
79 |
paths : [[-12.0403,-77.0337],[-12.0402,-77.0399],[-12.0500,-77.0244],[-12.0448,-77.0215]], |
|
80 |
strokeColor : '#25D359', |
|
81 |
strokeOpacity : 1, |
|
82 |
strokeWeight : 3, |
|
83 |
fillColor : '#25D359', |
|
84 |
fillOpacity : 0.6 |
|
85 |
}); |
|
86 |
}); |
|
87 |
|
|
88 |
it("should add the polygon to the polygons collection", function() { |
|
89 |
expect(map_with_polygons.polygons.length).toEqual(2); |
|
90 |
expect(map_with_polygons.polygons[1]).toEqual(polygon); |
|
91 |
}); |
|
92 |
|
|
93 |
it("should be added in the current map", function() { |
|
94 |
expect(polygon.getMap()).toEqual(map_with_polygons.map); |
|
95 |
}); |
|
96 |
|
|
97 |
it("should return the defined path", function() { |
|
98 |
var first_point = polygon.getPath().getAt(0); |
|
99 |
|
|
100 |
expect(parseFloat(first_point.lat().toFixed(4))).toEqual(-12.0403); |
|
101 |
expect(parseFloat(first_point.lng().toFixed(4))).toEqual(-77.0337); |
|
102 |
}); |
|
103 |
}); |
|
104 |
|
|
105 |
describe("A circle", function() { |
|
106 |
beforeEach(function() { |
|
107 |
circle = circle || map_with_polygons.drawCircle({ |
|
108 |
lat : -12.040504866577001, |
|
109 |
lng : -77.02024422636042, |
|
110 |
radius : 350, |
|
111 |
strokeColor : '#432070', |
|
112 |
strokeOpacity : 1, |
|
113 |
strokeWeight : 3, |
|
114 |
fillColor : '#432070', |
|
115 |
fillOpacity : 0.6 |
|
116 |
}); |
|
117 |
}); |
|
118 |
|
|
119 |
it("should add the circle to the polygons collection", function() { |
|
120 |
expect(map_with_polygons.polygons.length).toEqual(3); |
|
121 |
expect(map_with_polygons.polygons[2]).toEqual(circle); |
|
122 |
}); |
|
123 |
|
|
124 |
it("should be added in the current map", function() { |
|
125 |
expect(circle.getMap()).toEqual(map_with_polygons.map); |
|
126 |
}); |
|
127 |
|
|
128 |
it("should have the defined radius", function() { |
|
129 |
expect(circle.getRadius()).toEqual(350); |
|
130 |
}); |
|
131 |
}); |
|
132 |
}); |
|
133 |
|
|
134 |
describe("Removing geometry overlays", function() { |
|
135 |
var map_with_polygons, line, rectangle, circle, polygon; |
|
136 |
|
|
137 |
beforeEach(function() { |
|
138 |
map_with_polygons = map_with_polygons || new GMaps({ |
|
139 |
el : '#map-with-polygons', |
|
140 |
lat : -12.0433, |
|
141 |
lng : -77.0283, |
|
142 |
zoom : 12 |
|
143 |
}); |
|
144 |
}); |
|
145 |
|
|
146 |
describe("A line", function() { |
|
147 |
beforeEach(function() { |
|
148 |
line = map_with_polygons.drawPolyline({ |
|
149 |
path : [[-12.0440, -77.0247], [-12.0544, -77.0302], [-12.0551, -77.0303], [-12.0759, -77.0276], [-12.0763, -77.0279], [-12.0768, -77.0289], [-12.0885, -77.0241], [-12.0908, -77.0227]], |
|
150 |
strokeColor : '#131540', |
|
151 |
strokeOpacity : 0.6, |
|
152 |
strokeWeight : 6 |
|
153 |
}); |
|
154 |
|
|
155 |
map_with_polygons.removePolyline(line); |
|
156 |
}); |
|
157 |
|
|
158 |
it("should remove the line from the polylines collection", function() { |
|
159 |
expect(map_with_polygons.polylines.length).toEqual(0); |
|
160 |
expect(line.getMap()).toBeNull(); |
|
161 |
}); |
|
162 |
}); |
|
163 |
|
|
164 |
describe("A rectangle", function() { |
|
165 |
beforeEach(function() { |
|
166 |
rectangle = map_with_polygons.drawRectangle({ |
|
167 |
bounds : [[-12.0303,-77.0237],[-12.0348,-77.0115]], |
|
168 |
strokeColor : '#BBD8E9', |
|
169 |
strokeOpacity : 1, |
|
170 |
strokeWeight : 3, |
|
171 |
fillColor : '#BBD8E9', |
|
172 |
fillOpacity : 0.6 |
|
173 |
}); |
|
174 |
|
|
175 |
map_with_polygons.removePolygon(rectangle); |
|
176 |
}); |
|
177 |
|
|
178 |
it("should remove the rectangle from the polygons collection", function() { |
|
179 |
expect(map_with_polygons.polygons.length).toEqual(0); |
|
180 |
expect(rectangle.getMap()).toBeNull(); |
|
181 |
}); |
|
182 |
}); |
|
183 |
|
|
184 |
describe("A polygon", function() { |
|
185 |
beforeEach(function() { |
|
186 |
polygon = map_with_polygons.drawPolygon({ |
|
187 |
paths : [[-12.0403,-77.0337],[-12.0402,-77.0399],[-12.0500,-77.0244],[-12.0448,-77.0215]], |
|
188 |
strokeColor : '#25D359', |
|
189 |
strokeOpacity : 1, |
|
190 |
strokeWeight : 3, |
|
191 |
fillColor : '#25D359', |
|
192 |
fillOpacity : 0.6 |
|
193 |
}); |
|
194 |
|
|
195 |
map_with_polygons.removePolygon(polygon); |
|
196 |
}); |
|
197 |
|
|
198 |
it("should remove the polygon from the polygons collection", function() { |
|
199 |
expect(map_with_polygons.polygons.length).toEqual(0); |
|
200 |
expect(polygon.getMap()).toBeNull(); |
|
201 |
}); |
|
202 |
}); |
|
203 |
|
|
204 |
describe("A circle", function() { |
|
205 |
beforeEach(function() { |
|
206 |
circle = map_with_polygons.drawCircle({ |
|
207 |
lat : -12.040504866577001, |
|
208 |
lng : -77.02024422636042, |
|
209 |
radius : 350, |
|
210 |
strokeColor : '#432070', |
|
211 |
strokeOpacity : 1, |
|
212 |
strokeWeight : 3, |
|
213 |
fillColor : '#432070', |
|
214 |
fillOpacity : 0.6 |
|
215 |
}); |
|
216 |
|
|
217 |
map_with_polygons.removePolygon(circle); |
|
218 |
}); |
|
219 |
|
|
220 |
it("should remove the circle from the polygons collection", function() { |
|
221 |
expect(map_with_polygons.polygons.length).toEqual(0); |
|
222 |
expect(circle.getMap()).toBeNull(); |
|
223 |
}); |
|
224 |
}); |
|
225 |
}); |