@@ -17,699 +17,699 @@ |
||
17 | 17 | class MapAPI extends ViewableData |
18 | 18 | { |
19 | 19 | |
20 | - /** GoogleMap key **/ |
|
21 | - protected $googleMapKey = ''; |
|
20 | + /** GoogleMap key **/ |
|
21 | + protected $googleMapKey = ''; |
|
22 | 22 | |
23 | - /** GoogleMap ID for the HTML DIV **/ |
|
24 | - protected $googleMapId = 'googlemapapi'; |
|
23 | + /** GoogleMap ID for the HTML DIV **/ |
|
24 | + protected $googleMapId = 'googlemapapi'; |
|
25 | 25 | |
26 | - /* Additional CSS classes to use when rendering the map */ |
|
27 | - protected $set_additional_css_classes = ''; |
|
26 | + /* Additional CSS classes to use when rendering the map */ |
|
27 | + protected $set_additional_css_classes = ''; |
|
28 | 28 | |
29 | - /** Width of the gmap **/ |
|
30 | - protected $width = 800; |
|
29 | + /** Width of the gmap **/ |
|
30 | + protected $width = 800; |
|
31 | 31 | |
32 | - /** Height of the gmap **/ |
|
33 | - protected $height = 600; |
|
32 | + /** Height of the gmap **/ |
|
33 | + protected $height = 600; |
|
34 | 34 | |
35 | - /* array of lines to be drawn on the map */ |
|
36 | - protected $lines = array(); |
|
35 | + /* array of lines to be drawn on the map */ |
|
36 | + protected $lines = array(); |
|
37 | 37 | |
38 | - /* kml file to be rendered */ |
|
39 | - protected $kmlFiles = array(); |
|
38 | + /* kml file to be rendered */ |
|
39 | + protected $kmlFiles = array(); |
|
40 | 40 | |
41 | - /** Default zoom of the gmap **/ |
|
42 | - protected $zoom = 9; |
|
41 | + /** Default zoom of the gmap **/ |
|
42 | + protected $zoom = 9; |
|
43 | 43 | |
44 | - /** Enable the zoom of the Infowindow **/ |
|
45 | - protected $enableWindowZoom = false; |
|
44 | + /** Enable the zoom of the Infowindow **/ |
|
45 | + protected $enableWindowZoom = false; |
|
46 | 46 | |
47 | - /** Default zoom of the Infowindow **/ |
|
48 | - protected $infoWindowZoom = 13; |
|
47 | + /** Default zoom of the Infowindow **/ |
|
48 | + protected $infoWindowZoom = 13; |
|
49 | 49 | |
50 | - /** Lang of the gmap **/ |
|
51 | - protected $lang = 'en'; |
|
50 | + /** Lang of the gmap **/ |
|
51 | + protected $lang = 'en'; |
|
52 | 52 | |
53 | - /**Center of the gmap **/ |
|
54 | - protected $center = 'Paris, France'; |
|
53 | + /**Center of the gmap **/ |
|
54 | + protected $center = 'Paris, France'; |
|
55 | 55 | |
56 | - /* |
|
56 | + /* |
|
57 | 57 | Additional CSS classes to render as a class attribute for the div of the |
58 | 58 | map. Use this if you want more fine grained control over your map using |
59 | 59 | CSS. If blank it will be ignored |
60 | 60 | */ |
61 | - protected $additional_css_classes = ''; |
|
61 | + protected $additional_css_classes = ''; |
|
62 | 62 | |
63 | 63 | |
64 | - /* Decided whether or not to show the inline map css style on div creation */ |
|
65 | - protected $show_inline_map_div_style = true; |
|
64 | + /* Decided whether or not to show the inline map css style on div creation */ |
|
65 | + protected $show_inline_map_div_style = true; |
|
66 | 66 | |
67 | - protected $latLongCenter = null; |
|
67 | + protected $latLongCenter = null; |
|
68 | 68 | |
69 | - protected $jsonMapStyles = '[]'; |
|
69 | + protected $jsonMapStyles = '[]'; |
|
70 | 70 | |
71 | - /** |
|
72 | - * Type of the gmap, can be: |
|
73 | - * 'road' (roadmap), |
|
74 | - * 'satellite' (sattelite/aerial photographs) |
|
75 | - * 'hybrid' (hybrid of road and satellite) |
|
76 | - * 'terrain' (terrain) |
|
77 | - * The JavaScript for the mapping service will convert this into a suitable mapping type |
|
78 | - */ |
|
71 | + /** |
|
72 | + * Type of the gmap, can be: |
|
73 | + * 'road' (roadmap), |
|
74 | + * 'satellite' (sattelite/aerial photographs) |
|
75 | + * 'hybrid' (hybrid of road and satellite) |
|
76 | + * 'terrain' (terrain) |
|
77 | + * The JavaScript for the mapping service will convert this into a suitable mapping type |
|
78 | + */ |
|
79 | 79 | |
80 | - protected $mapType = 'road'; |
|
80 | + protected $mapType = 'road'; |
|
81 | 81 | |
82 | 82 | |
83 | - /** Content of the HTML generated **/ |
|
84 | - protected $content = ''; |
|
83 | + /** Content of the HTML generated **/ |
|
84 | + protected $content = ''; |
|
85 | 85 | |
86 | - protected $mapService = 'google'; |
|
86 | + protected $mapService = 'google'; |
|
87 | 87 | |
88 | - /** Hide the marker by default **/ |
|
89 | - protected $defaultHideMarker = false; |
|
88 | + /** Hide the marker by default **/ |
|
89 | + protected $defaultHideMarker = false; |
|
90 | 90 | |
91 | - /** Extra content (marker, etc...) **/ |
|
92 | - protected $contentMarker = ''; |
|
91 | + /** Extra content (marker, etc...) **/ |
|
92 | + protected $contentMarker = ''; |
|
93 | 93 | |
94 | - // a list of markers, markers being associative arrays |
|
95 | - protected $markers = array(); |
|
94 | + // a list of markers, markers being associative arrays |
|
95 | + protected $markers = array(); |
|
96 | 96 | |
97 | - /** Use clusterer to display a lot of markers on the gmap **/ |
|
98 | - protected $useClusterer = false; |
|
99 | - protected $gridSize = 50; |
|
100 | - protected $maxZoom = 17; |
|
101 | - protected $clustererLibraryPath = "/mappable/javascript/google/markerclusterer.js"; |
|
97 | + /** Use clusterer to display a lot of markers on the gmap **/ |
|
98 | + protected $useClusterer = false; |
|
99 | + protected $gridSize = 50; |
|
100 | + protected $maxZoom = 17; |
|
101 | + protected $clustererLibraryPath = "/mappable/javascript/google/markerclusterer.js"; |
|
102 | 102 | |
103 | - /** Enable automatic center/zoom **/ |
|
104 | - protected $enableAutomaticCenterZoom = false; |
|
103 | + /** Enable automatic center/zoom **/ |
|
104 | + protected $enableAutomaticCenterZoom = false; |
|
105 | 105 | |
106 | - /** maximum longitude of all markers **/ |
|
107 | - protected $maxLng = -1000000; |
|
106 | + /** maximum longitude of all markers **/ |
|
107 | + protected $maxLng = -1000000; |
|
108 | 108 | |
109 | - /** minimum longitude of all markers **/ |
|
110 | - protected $minLng = 1000000; |
|
109 | + /** minimum longitude of all markers **/ |
|
110 | + protected $minLng = 1000000; |
|
111 | 111 | |
112 | - /** max latitude of all markers **/ |
|
113 | - protected $maxLat = -1000000; |
|
112 | + /** max latitude of all markers **/ |
|
113 | + protected $maxLat = -1000000; |
|
114 | 114 | |
115 | - /** min latitude of all markers **/ |
|
116 | - protected $minLat = 1000000; |
|
115 | + /** min latitude of all markers **/ |
|
116 | + protected $minLat = 1000000; |
|
117 | 117 | |
118 | - /** map center latitude (horizontal), calculated automatically as markers |
|
118 | + /** map center latitude (horizontal), calculated automatically as markers |
|
119 | 119 | are added to the map **/ |
120 | - protected $centerLat = null; |
|
120 | + protected $centerLat = null; |
|
121 | 121 | |
122 | - /** map center longitude (vertical), calculated automatically as markers |
|
122 | + /** map center longitude (vertical), calculated automatically as markers |
|
123 | 123 | are added to the map **/ |
124 | - protected $centerLng = null; |
|
124 | + protected $centerLng = null; |
|
125 | 125 | |
126 | - /** factor by which to fudge the boundaries so that when we zoom encompass, |
|
126 | + /** factor by which to fudge the boundaries so that when we zoom encompass, |
|
127 | 127 | the markers aren't too close to the edge **/ |
128 | - protected $coordCoef = 0.01; |
|
129 | - |
|
130 | - /* set this to true to render button to maximize / minimize a map */ |
|
131 | - protected $allowFullScreen = null; |
|
132 | - |
|
133 | - /** |
|
134 | - * Class constructor |
|
135 | - * |
|
136 | - * @param string $googleMapKey the googleMapKey |
|
137 | - */ |
|
138 | - |
|
139 | - public function __construct($googleMapKey = '') { |
|
140 | - $this->googleMapKey = $googleMapKey; |
|
141 | - } |
|
142 | - |
|
143 | - public function setShowInlineMapDivStyle($new_show_inline_map_div_style) { |
|
144 | - $this->show_inline_map_div_style = $new_show_inline_map_div_style; |
|
145 | - return $this; |
|
146 | - } |
|
147 | - |
|
148 | - public function setAdditionalCSSClasses($new_additional_css_classes) { |
|
149 | - $this->additional_css_classes = $new_additional_css_classes; |
|
150 | - return $this; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - public function setMapStyle($newStyles) { |
|
155 | - $this->jsonMapStyles = $newStyles; |
|
156 | - return $this; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Set the useClusterer parameter (optimization to display a lot of marker) |
|
161 | - * |
|
162 | - * @param boolean $useClusterer use cluster or not |
|
163 | - * @param int $gridSize grid size |
|
164 | - * @param int $maxZoom max zoom to cluster at |
|
165 | - * |
|
166 | - * * @return MapAPI This same object, in order to enable chaining of methods |
|
167 | - */ |
|
168 | - |
|
169 | - public function setClusterer($useClusterer, $gridSize = 50, $maxZoom = 17, |
|
170 | - $clustererLibraryPath = '/mappable/javascript/google/markerclusterer.js') { |
|
171 | - $this->useClusterer = $useClusterer; |
|
172 | - $this->gridSize = $gridSize; |
|
173 | - $this->maxZoom = $maxZoom; |
|
174 | - $this->clustererLibraryPath = $clustererLibraryPath; |
|
175 | - return $this; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Set the ID of the default gmap DIV |
|
180 | - * |
|
181 | - * @param string $googleMapId the google div ID |
|
182 | - * |
|
183 | - * @return MapAPI This same object, in order to enable chaining of methods |
|
184 | - */ |
|
185 | - |
|
186 | - public function setDivId($googleMapId) { |
|
187 | - $this->googleMapId = $googleMapId; |
|
188 | - return $this; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Set the size of the gmap. If these values are not provided |
|
193 | - * then CSS is used instead |
|
194 | - * |
|
195 | - * @param int $width GoogleMap width |
|
196 | - * @param int $height GoogleMap height |
|
197 | - * |
|
198 | - * @return MapAPI This same object, in order to enable chaining of methods |
|
199 | - */ |
|
200 | - |
|
201 | - public function setSize($width, $height) { |
|
202 | - $this->width = $width; |
|
203 | - $this->height = $height; |
|
204 | - return $this; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Set the lang of the gmap |
|
209 | - * |
|
210 | - * @param string $lang GoogleMap lang : fr,en,.. |
|
211 | - * |
|
212 | - * @return MapAPI This same object, in order to enable chaining of methods |
|
213 | - */ |
|
214 | - |
|
215 | - public function setLang($lang) { |
|
216 | - $this->lang = $lang; |
|
217 | - return $this; |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * Set the zoom of the gmap |
|
222 | - * |
|
223 | - * @param int $zoom GoogleMap zoom. |
|
224 | - * |
|
225 | - * @return MapAPI This same object, in order to enable chaining of methods |
|
226 | - */ |
|
227 | - |
|
228 | - public function setZoom($zoom) { |
|
229 | - $this->zoom = $zoom; |
|
230 | - return $this; |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * Set the zoom of the infowindow |
|
235 | - * |
|
236 | - * @param int $infoWindowZoom GoogleMap information window zoom. |
|
237 | - * |
|
238 | - * @return MapAPI This same object, in order to enable chaining of methods |
|
239 | - */ |
|
240 | - |
|
241 | - public function setInfoWindowZoom($infoWindowZoom) { |
|
242 | - $this->infoWindowZoom = $infoWindowZoom; |
|
243 | - return $this; |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * Enable the zoom on the marker when you click on it |
|
248 | - * |
|
249 | - * @param boolean $enableWindowZoom info window enabled zoom. |
|
250 | - * |
|
251 | - * @return MapAPI This same object, in order to enable chaining of methods |
|
252 | - */ |
|
253 | - |
|
254 | - public function setEnableWindowZoom($enableWindowZoom) { |
|
255 | - $this->enableWindowZoom = $enableWindowZoom; |
|
256 | - return $this; |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Enable theautomatic center/zoom at the gmap load |
|
261 | - * |
|
262 | - * @param boolean $enableAutomaticCenterZoom enable automatic centre zoom |
|
263 | - * |
|
264 | - * @return MapAPI This same object, in order to enable chaining of methods |
|
265 | - */ |
|
266 | - |
|
267 | - public function setEnableAutomaticCenterZoom($enableAutomaticCenterZoom) { |
|
268 | - $this->enableAutomaticCenterZoom = $enableAutomaticCenterZoom; |
|
269 | - return $this; |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * Set the center of the gmap (an address) |
|
274 | - * |
|
275 | - * @param string $center GoogleMap center (an address) |
|
276 | - * |
|
277 | - * @return MapAPI This same object, in order to enable chaining of methods |
|
278 | - */ |
|
279 | - |
|
280 | - public function setCenter($center) { |
|
281 | - $this->center = $center; |
|
282 | - return $this; |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * Set the type of the gmap. Also takes into account legacy settings |
|
287 | - * |
|
288 | - * FIXME - allow other valid settings in config for map type |
|
289 | - * |
|
290 | - * @param string $mapType Can be one of road,satellite,hybrid or terrain. Defaults to road |
|
291 | - * |
|
292 | - * @return MapAPI This same object, in order to enable chaining of methods |
|
293 | - */ |
|
294 | - |
|
295 | - public function setMapType($mapType) { |
|
296 | - $this->mapType = $mapType; |
|
297 | - |
|
298 | - // deal with legacy values for backwards compatbility |
|
299 | - switch ($mapType) { |
|
300 | - case 'google.maps.MapTypeId.SATELLITE': |
|
301 | - $this->mapType = "satellite"; |
|
302 | - break; |
|
303 | - case 'google.maps.MapTypeId.G_HYBRID_MAP': |
|
304 | - $this->mapType = "hybrid"; |
|
305 | - break; |
|
306 | - case 'google.maps.MapTypeId.G_PHYSICAL_MAP': |
|
307 | - $this->mapType = "terrain"; |
|
308 | - break; |
|
309 | - case 'google.maps.MapTypeId.ROADMAP': |
|
310 | - $this->mapType = "road"; |
|
311 | - break; |
|
312 | - } |
|
313 | - return $this; |
|
314 | - } |
|
315 | - |
|
316 | - /* |
|
128 | + protected $coordCoef = 0.01; |
|
129 | + |
|
130 | + /* set this to true to render button to maximize / minimize a map */ |
|
131 | + protected $allowFullScreen = null; |
|
132 | + |
|
133 | + /** |
|
134 | + * Class constructor |
|
135 | + * |
|
136 | + * @param string $googleMapKey the googleMapKey |
|
137 | + */ |
|
138 | + |
|
139 | + public function __construct($googleMapKey = '') { |
|
140 | + $this->googleMapKey = $googleMapKey; |
|
141 | + } |
|
142 | + |
|
143 | + public function setShowInlineMapDivStyle($new_show_inline_map_div_style) { |
|
144 | + $this->show_inline_map_div_style = $new_show_inline_map_div_style; |
|
145 | + return $this; |
|
146 | + } |
|
147 | + |
|
148 | + public function setAdditionalCSSClasses($new_additional_css_classes) { |
|
149 | + $this->additional_css_classes = $new_additional_css_classes; |
|
150 | + return $this; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + public function setMapStyle($newStyles) { |
|
155 | + $this->jsonMapStyles = $newStyles; |
|
156 | + return $this; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Set the useClusterer parameter (optimization to display a lot of marker) |
|
161 | + * |
|
162 | + * @param boolean $useClusterer use cluster or not |
|
163 | + * @param int $gridSize grid size |
|
164 | + * @param int $maxZoom max zoom to cluster at |
|
165 | + * |
|
166 | + * * @return MapAPI This same object, in order to enable chaining of methods |
|
167 | + */ |
|
168 | + |
|
169 | + public function setClusterer($useClusterer, $gridSize = 50, $maxZoom = 17, |
|
170 | + $clustererLibraryPath = '/mappable/javascript/google/markerclusterer.js') { |
|
171 | + $this->useClusterer = $useClusterer; |
|
172 | + $this->gridSize = $gridSize; |
|
173 | + $this->maxZoom = $maxZoom; |
|
174 | + $this->clustererLibraryPath = $clustererLibraryPath; |
|
175 | + return $this; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Set the ID of the default gmap DIV |
|
180 | + * |
|
181 | + * @param string $googleMapId the google div ID |
|
182 | + * |
|
183 | + * @return MapAPI This same object, in order to enable chaining of methods |
|
184 | + */ |
|
185 | + |
|
186 | + public function setDivId($googleMapId) { |
|
187 | + $this->googleMapId = $googleMapId; |
|
188 | + return $this; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Set the size of the gmap. If these values are not provided |
|
193 | + * then CSS is used instead |
|
194 | + * |
|
195 | + * @param int $width GoogleMap width |
|
196 | + * @param int $height GoogleMap height |
|
197 | + * |
|
198 | + * @return MapAPI This same object, in order to enable chaining of methods |
|
199 | + */ |
|
200 | + |
|
201 | + public function setSize($width, $height) { |
|
202 | + $this->width = $width; |
|
203 | + $this->height = $height; |
|
204 | + return $this; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Set the lang of the gmap |
|
209 | + * |
|
210 | + * @param string $lang GoogleMap lang : fr,en,.. |
|
211 | + * |
|
212 | + * @return MapAPI This same object, in order to enable chaining of methods |
|
213 | + */ |
|
214 | + |
|
215 | + public function setLang($lang) { |
|
216 | + $this->lang = $lang; |
|
217 | + return $this; |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * Set the zoom of the gmap |
|
222 | + * |
|
223 | + * @param int $zoom GoogleMap zoom. |
|
224 | + * |
|
225 | + * @return MapAPI This same object, in order to enable chaining of methods |
|
226 | + */ |
|
227 | + |
|
228 | + public function setZoom($zoom) { |
|
229 | + $this->zoom = $zoom; |
|
230 | + return $this; |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * Set the zoom of the infowindow |
|
235 | + * |
|
236 | + * @param int $infoWindowZoom GoogleMap information window zoom. |
|
237 | + * |
|
238 | + * @return MapAPI This same object, in order to enable chaining of methods |
|
239 | + */ |
|
240 | + |
|
241 | + public function setInfoWindowZoom($infoWindowZoom) { |
|
242 | + $this->infoWindowZoom = $infoWindowZoom; |
|
243 | + return $this; |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * Enable the zoom on the marker when you click on it |
|
248 | + * |
|
249 | + * @param boolean $enableWindowZoom info window enabled zoom. |
|
250 | + * |
|
251 | + * @return MapAPI This same object, in order to enable chaining of methods |
|
252 | + */ |
|
253 | + |
|
254 | + public function setEnableWindowZoom($enableWindowZoom) { |
|
255 | + $this->enableWindowZoom = $enableWindowZoom; |
|
256 | + return $this; |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Enable theautomatic center/zoom at the gmap load |
|
261 | + * |
|
262 | + * @param boolean $enableAutomaticCenterZoom enable automatic centre zoom |
|
263 | + * |
|
264 | + * @return MapAPI This same object, in order to enable chaining of methods |
|
265 | + */ |
|
266 | + |
|
267 | + public function setEnableAutomaticCenterZoom($enableAutomaticCenterZoom) { |
|
268 | + $this->enableAutomaticCenterZoom = $enableAutomaticCenterZoom; |
|
269 | + return $this; |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * Set the center of the gmap (an address) |
|
274 | + * |
|
275 | + * @param string $center GoogleMap center (an address) |
|
276 | + * |
|
277 | + * @return MapAPI This same object, in order to enable chaining of methods |
|
278 | + */ |
|
279 | + |
|
280 | + public function setCenter($center) { |
|
281 | + $this->center = $center; |
|
282 | + return $this; |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * Set the type of the gmap. Also takes into account legacy settings |
|
287 | + * |
|
288 | + * FIXME - allow other valid settings in config for map type |
|
289 | + * |
|
290 | + * @param string $mapType Can be one of road,satellite,hybrid or terrain. Defaults to road |
|
291 | + * |
|
292 | + * @return MapAPI This same object, in order to enable chaining of methods |
|
293 | + */ |
|
294 | + |
|
295 | + public function setMapType($mapType) { |
|
296 | + $this->mapType = $mapType; |
|
297 | + |
|
298 | + // deal with legacy values for backwards compatbility |
|
299 | + switch ($mapType) { |
|
300 | + case 'google.maps.MapTypeId.SATELLITE': |
|
301 | + $this->mapType = "satellite"; |
|
302 | + break; |
|
303 | + case 'google.maps.MapTypeId.G_HYBRID_MAP': |
|
304 | + $this->mapType = "hybrid"; |
|
305 | + break; |
|
306 | + case 'google.maps.MapTypeId.G_PHYSICAL_MAP': |
|
307 | + $this->mapType = "terrain"; |
|
308 | + break; |
|
309 | + case 'google.maps.MapTypeId.ROADMAP': |
|
310 | + $this->mapType = "road"; |
|
311 | + break; |
|
312 | + } |
|
313 | + return $this; |
|
314 | + } |
|
315 | + |
|
316 | + /* |
|
317 | 317 | Set whether or not to allow the full screen tools |
318 | 318 | @return MapAPI This same object, in order to enable chaining of methods |
319 | 319 | */ |
320 | - public function setAllowFullScreen($allowed) { |
|
321 | - $this->allowFullScreen = $allowed; |
|
322 | - return $this; |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * Set the center of the gmap |
|
327 | - * |
|
328 | - * @return MapAPI This same object, in order to enable chaining of methods |
|
329 | - **/ |
|
330 | - public function setLatLongCenter($center) { |
|
331 | - // error check, we want an associative array with lat,lng keys numeric |
|
332 | - |
|
333 | - if (!is_array($center)) { |
|
334 | - throw new InvalidArgumentException('Center must be an associative array containing lat,lng'); |
|
335 | - } |
|
336 | - |
|
337 | - $keys = array_keys($center); |
|
338 | - sort($keys); |
|
339 | - if (implode(',', $keys) != 'lat,lng') { |
|
340 | - throw new InvalidArgumentException('Keys provided must be lat, lng'); |
|
341 | - } |
|
342 | - |
|
343 | - $this->latLongCenter = $center; |
|
344 | - return $this; |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * Set the defaultHideMarker |
|
349 | - * |
|
350 | - * @param boolean $defaultHideMarker hide all the markers on the map by default |
|
351 | - * |
|
352 | - * @return MapAPI |
|
353 | - */ |
|
354 | - |
|
355 | - public function setDefaultHideMarker($defaultHideMarker) { |
|
356 | - $this->defaultHideMarker = $defaultHideMarker; |
|
357 | - return $this; |
|
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * Get the google map content |
|
362 | - * |
|
363 | - * @return string the google map html code |
|
364 | - */ |
|
365 | - |
|
366 | - public function getGoogleMap() { |
|
367 | - return $this->content; |
|
368 | - } |
|
369 | - |
|
370 | - |
|
371 | - /** |
|
372 | - * Get URL content using cURL. |
|
373 | - * |
|
374 | - * @param string $url the url |
|
375 | - * |
|
376 | - * @return string the html code |
|
377 | - * |
|
378 | - * @todo add proxy settings |
|
379 | - */ |
|
380 | - |
|
381 | - public function getContent($url) { |
|
382 | - $curl = curl_init(); |
|
383 | - curl_setopt($curl, CURLOPT_TIMEOUT, 10); |
|
384 | - curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5); |
|
385 | - curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); |
|
386 | - curl_setopt($curl, CURLOPT_URL, $url); |
|
387 | - $data = curl_exec($curl); |
|
388 | - curl_close($curl); |
|
389 | - return $data; |
|
390 | - } |
|
391 | - |
|
392 | - /** |
|
393 | - * Geocoding an address (address -> lat,lng) |
|
394 | - * |
|
395 | - * @param string $address an address |
|
396 | - * |
|
397 | - * @return string array with precision, lat & lng |
|
398 | - */ |
|
399 | - |
|
400 | - public function geocoding($address) { |
|
401 | - $geocoder = new MappableGoogleGeocoder(); |
|
402 | - $locations = $geocoder->getLocations($address); |
|
403 | - $result = null; |
|
404 | - if (!empty($locations)) { |
|
405 | - $place = $locations[0]; |
|
406 | - $location = $place['geometry']['location']; |
|
407 | - $result = array( |
|
408 | - 'lat' => $location['lat'], |
|
409 | - 'lon' => $location['lng'], |
|
410 | - 'geocoded' => true |
|
411 | - ); |
|
412 | - |
|
413 | - } else { |
|
414 | - $result = array(); // no results |
|
415 | - } |
|
416 | - return $result; |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * Add marker by his coord |
|
421 | - * |
|
422 | - * @param string $lat lat |
|
423 | - * @param string $lng lngs |
|
424 | - * @param string $html html code display in the info window |
|
425 | - * @param string $category marker category |
|
426 | - * @param string $icon an icon url |
|
427 | - * |
|
428 | - * @return MapAPI |
|
429 | - */ |
|
430 | - |
|
431 | - public function addMarkerByCoords($lat, $lng, $html = '', $category = '', $icon = '') { |
|
432 | - $m = array( |
|
433 | - 'latitude' => $lat, |
|
434 | - 'longitude' => $lng, |
|
435 | - 'html' => $html, |
|
436 | - 'category' => $category, |
|
437 | - 'icon' => $icon |
|
438 | - ); |
|
439 | - array_push($this->markers, $m); |
|
440 | - return $this; |
|
441 | - } |
|
442 | - |
|
443 | - |
|
444 | - /** |
|
445 | - * Add marker by his address |
|
446 | - * |
|
447 | - * @param string $address an ddress |
|
448 | - * @param string $content html code display in the info window |
|
449 | - * @param string $category marker category |
|
450 | - * @param string $icon an icon url |
|
451 | - * |
|
452 | - * @return MapAPI |
|
453 | - */ |
|
454 | - |
|
455 | - public function addMarkerByAddress($address, $content = '', $category = '', $icon = '') { |
|
456 | - $point = $this->geocoding($address); |
|
457 | - if ($point !== null) { |
|
458 | - $this->addMarkerByCoords($point['lat'], $point['lon'], $content, $category, $icon); |
|
459 | - } |
|
460 | - return $this; |
|
461 | - } |
|
462 | - |
|
463 | - /** |
|
464 | - * Add marker by an array of coord |
|
465 | - * |
|
466 | - * @param array $coordtab an array of lat,lng,content |
|
467 | - * @param string $category marker category |
|
468 | - * @param string $icon an icon url |
|
469 | - * |
|
470 | - * @return MapAPI |
|
471 | - */ |
|
472 | - |
|
473 | - public function addArrayMarkerByCoords($coordtab, $category = '', $icon = '') { |
|
474 | - foreach ($coordtab as $coord) { |
|
475 | - $this->addMarkerByCoords($coord[0], $coord[1], $coord[2], $category, $icon); |
|
476 | - } |
|
477 | - return $this; |
|
478 | - } |
|
479 | - |
|
480 | - |
|
481 | - /** |
|
482 | - * Adds a {@link ViewableData} object that implements {@link Mappable} |
|
483 | - * to the map. |
|
484 | - * @param $infowindowtemplateparams Optional array of extra parameters to pass to the map info window |
|
485 | - * |
|
486 | - * @param ViewableData $obj |
|
487 | - */ |
|
488 | - public function addMarkerAsObject(ViewableData $obj, $infowindowtemplateparams = null) { |
|
489 | - $extensionsImplementMappable = false; |
|
490 | - $extensions = Object::get_extensions(get_class($obj)); |
|
491 | - if (is_array($extensions)) { |
|
492 | - |
|
493 | - foreach ($extensions as $extension) { |
|
494 | - $class = new ReflectionClass($extension); |
|
495 | - if ($class->implementsInterface('Mappable')) { |
|
496 | - $extensionsImplementMappable = true; |
|
497 | - } |
|
498 | - |
|
499 | - } |
|
500 | - } |
|
501 | - |
|
502 | - if ($extensionsImplementMappable || |
|
503 | - ($obj instanceof Mappable) || |
|
504 | - (Object::has_extension($obj->ClassName, 'MapExtension')) |
|
505 | - ) { |
|
506 | - $cat = $obj->hasMethod('getMappableMapCategory') ? $obj->getMappableMapCategory() : "default"; |
|
507 | - if ($infowindowtemplateparams !== null) { |
|
508 | - foreach ($infowindowtemplateparams as $key => $value) { |
|
509 | - $obj->{$key} = $value; |
|
510 | - } |
|
511 | - } |
|
512 | - $this->addMarkerByCoords( |
|
513 | - $obj->getMappableLatitude(), |
|
514 | - $obj->getMappableLongitude(), |
|
515 | - $obj->getMappableMapContent(), |
|
516 | - $cat, |
|
517 | - $obj->getMappableMapPin() |
|
518 | - ); |
|
519 | - } |
|
520 | - |
|
521 | - return $this; |
|
522 | - } |
|
523 | - |
|
524 | - |
|
525 | - /** |
|
526 | - * Draws a line between two {@link ViewableData} objects |
|
527 | - * |
|
528 | - * @param ViewableData $one The first point |
|
529 | - * @param ViewableData $two The second point |
|
530 | - * @param string $color The hexidecimal color of the line |
|
531 | - */ |
|
532 | - public function connectPoints(ViewableData $one, ViewableData $two, $color = "#FF3300") { |
|
533 | - $this->addLine( |
|
534 | - array($one->getMappableLatitude(), $one->getMappableLongitude()), |
|
535 | - array($two->getMappableLatitude(), $two->getMappableLongitude()), |
|
536 | - $color |
|
537 | - ); |
|
538 | - } |
|
539 | - |
|
540 | - public function forTemplate() { |
|
541 | - $this->generate(); |
|
542 | - MapUtil::set_map_already_rendered(true); |
|
543 | - return $this->getGoogleMap(); |
|
544 | - } |
|
545 | - |
|
546 | - /** |
|
547 | - * Add a KML file which will be rendered on this map. Normally used for likes |
|
548 | - * of GPS traces from activities |
|
549 | - * |
|
550 | - * @param string $url url of the kml file compatible with gmap and gearth |
|
551 | - * |
|
552 | - * @return MapAPI |
|
553 | - */ |
|
554 | - |
|
555 | - public function addKML($url) { |
|
556 | - array_push($this->kmlFiles, $url); |
|
557 | - return $this; |
|
558 | - } |
|
559 | - |
|
560 | - |
|
561 | - /* |
|
320 | + public function setAllowFullScreen($allowed) { |
|
321 | + $this->allowFullScreen = $allowed; |
|
322 | + return $this; |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * Set the center of the gmap |
|
327 | + * |
|
328 | + * @return MapAPI This same object, in order to enable chaining of methods |
|
329 | + **/ |
|
330 | + public function setLatLongCenter($center) { |
|
331 | + // error check, we want an associative array with lat,lng keys numeric |
|
332 | + |
|
333 | + if (!is_array($center)) { |
|
334 | + throw new InvalidArgumentException('Center must be an associative array containing lat,lng'); |
|
335 | + } |
|
336 | + |
|
337 | + $keys = array_keys($center); |
|
338 | + sort($keys); |
|
339 | + if (implode(',', $keys) != 'lat,lng') { |
|
340 | + throw new InvalidArgumentException('Keys provided must be lat, lng'); |
|
341 | + } |
|
342 | + |
|
343 | + $this->latLongCenter = $center; |
|
344 | + return $this; |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * Set the defaultHideMarker |
|
349 | + * |
|
350 | + * @param boolean $defaultHideMarker hide all the markers on the map by default |
|
351 | + * |
|
352 | + * @return MapAPI |
|
353 | + */ |
|
354 | + |
|
355 | + public function setDefaultHideMarker($defaultHideMarker) { |
|
356 | + $this->defaultHideMarker = $defaultHideMarker; |
|
357 | + return $this; |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * Get the google map content |
|
362 | + * |
|
363 | + * @return string the google map html code |
|
364 | + */ |
|
365 | + |
|
366 | + public function getGoogleMap() { |
|
367 | + return $this->content; |
|
368 | + } |
|
369 | + |
|
370 | + |
|
371 | + /** |
|
372 | + * Get URL content using cURL. |
|
373 | + * |
|
374 | + * @param string $url the url |
|
375 | + * |
|
376 | + * @return string the html code |
|
377 | + * |
|
378 | + * @todo add proxy settings |
|
379 | + */ |
|
380 | + |
|
381 | + public function getContent($url) { |
|
382 | + $curl = curl_init(); |
|
383 | + curl_setopt($curl, CURLOPT_TIMEOUT, 10); |
|
384 | + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5); |
|
385 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); |
|
386 | + curl_setopt($curl, CURLOPT_URL, $url); |
|
387 | + $data = curl_exec($curl); |
|
388 | + curl_close($curl); |
|
389 | + return $data; |
|
390 | + } |
|
391 | + |
|
392 | + /** |
|
393 | + * Geocoding an address (address -> lat,lng) |
|
394 | + * |
|
395 | + * @param string $address an address |
|
396 | + * |
|
397 | + * @return string array with precision, lat & lng |
|
398 | + */ |
|
399 | + |
|
400 | + public function geocoding($address) { |
|
401 | + $geocoder = new MappableGoogleGeocoder(); |
|
402 | + $locations = $geocoder->getLocations($address); |
|
403 | + $result = null; |
|
404 | + if (!empty($locations)) { |
|
405 | + $place = $locations[0]; |
|
406 | + $location = $place['geometry']['location']; |
|
407 | + $result = array( |
|
408 | + 'lat' => $location['lat'], |
|
409 | + 'lon' => $location['lng'], |
|
410 | + 'geocoded' => true |
|
411 | + ); |
|
412 | + |
|
413 | + } else { |
|
414 | + $result = array(); // no results |
|
415 | + } |
|
416 | + return $result; |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * Add marker by his coord |
|
421 | + * |
|
422 | + * @param string $lat lat |
|
423 | + * @param string $lng lngs |
|
424 | + * @param string $html html code display in the info window |
|
425 | + * @param string $category marker category |
|
426 | + * @param string $icon an icon url |
|
427 | + * |
|
428 | + * @return MapAPI |
|
429 | + */ |
|
430 | + |
|
431 | + public function addMarkerByCoords($lat, $lng, $html = '', $category = '', $icon = '') { |
|
432 | + $m = array( |
|
433 | + 'latitude' => $lat, |
|
434 | + 'longitude' => $lng, |
|
435 | + 'html' => $html, |
|
436 | + 'category' => $category, |
|
437 | + 'icon' => $icon |
|
438 | + ); |
|
439 | + array_push($this->markers, $m); |
|
440 | + return $this; |
|
441 | + } |
|
442 | + |
|
443 | + |
|
444 | + /** |
|
445 | + * Add marker by his address |
|
446 | + * |
|
447 | + * @param string $address an ddress |
|
448 | + * @param string $content html code display in the info window |
|
449 | + * @param string $category marker category |
|
450 | + * @param string $icon an icon url |
|
451 | + * |
|
452 | + * @return MapAPI |
|
453 | + */ |
|
454 | + |
|
455 | + public function addMarkerByAddress($address, $content = '', $category = '', $icon = '') { |
|
456 | + $point = $this->geocoding($address); |
|
457 | + if ($point !== null) { |
|
458 | + $this->addMarkerByCoords($point['lat'], $point['lon'], $content, $category, $icon); |
|
459 | + } |
|
460 | + return $this; |
|
461 | + } |
|
462 | + |
|
463 | + /** |
|
464 | + * Add marker by an array of coord |
|
465 | + * |
|
466 | + * @param array $coordtab an array of lat,lng,content |
|
467 | + * @param string $category marker category |
|
468 | + * @param string $icon an icon url |
|
469 | + * |
|
470 | + * @return MapAPI |
|
471 | + */ |
|
472 | + |
|
473 | + public function addArrayMarkerByCoords($coordtab, $category = '', $icon = '') { |
|
474 | + foreach ($coordtab as $coord) { |
|
475 | + $this->addMarkerByCoords($coord[0], $coord[1], $coord[2], $category, $icon); |
|
476 | + } |
|
477 | + return $this; |
|
478 | + } |
|
479 | + |
|
480 | + |
|
481 | + /** |
|
482 | + * Adds a {@link ViewableData} object that implements {@link Mappable} |
|
483 | + * to the map. |
|
484 | + * @param $infowindowtemplateparams Optional array of extra parameters to pass to the map info window |
|
485 | + * |
|
486 | + * @param ViewableData $obj |
|
487 | + */ |
|
488 | + public function addMarkerAsObject(ViewableData $obj, $infowindowtemplateparams = null) { |
|
489 | + $extensionsImplementMappable = false; |
|
490 | + $extensions = Object::get_extensions(get_class($obj)); |
|
491 | + if (is_array($extensions)) { |
|
492 | + |
|
493 | + foreach ($extensions as $extension) { |
|
494 | + $class = new ReflectionClass($extension); |
|
495 | + if ($class->implementsInterface('Mappable')) { |
|
496 | + $extensionsImplementMappable = true; |
|
497 | + } |
|
498 | + |
|
499 | + } |
|
500 | + } |
|
501 | + |
|
502 | + if ($extensionsImplementMappable || |
|
503 | + ($obj instanceof Mappable) || |
|
504 | + (Object::has_extension($obj->ClassName, 'MapExtension')) |
|
505 | + ) { |
|
506 | + $cat = $obj->hasMethod('getMappableMapCategory') ? $obj->getMappableMapCategory() : "default"; |
|
507 | + if ($infowindowtemplateparams !== null) { |
|
508 | + foreach ($infowindowtemplateparams as $key => $value) { |
|
509 | + $obj->{$key} = $value; |
|
510 | + } |
|
511 | + } |
|
512 | + $this->addMarkerByCoords( |
|
513 | + $obj->getMappableLatitude(), |
|
514 | + $obj->getMappableLongitude(), |
|
515 | + $obj->getMappableMapContent(), |
|
516 | + $cat, |
|
517 | + $obj->getMappableMapPin() |
|
518 | + ); |
|
519 | + } |
|
520 | + |
|
521 | + return $this; |
|
522 | + } |
|
523 | + |
|
524 | + |
|
525 | + /** |
|
526 | + * Draws a line between two {@link ViewableData} objects |
|
527 | + * |
|
528 | + * @param ViewableData $one The first point |
|
529 | + * @param ViewableData $two The second point |
|
530 | + * @param string $color The hexidecimal color of the line |
|
531 | + */ |
|
532 | + public function connectPoints(ViewableData $one, ViewableData $two, $color = "#FF3300") { |
|
533 | + $this->addLine( |
|
534 | + array($one->getMappableLatitude(), $one->getMappableLongitude()), |
|
535 | + array($two->getMappableLatitude(), $two->getMappableLongitude()), |
|
536 | + $color |
|
537 | + ); |
|
538 | + } |
|
539 | + |
|
540 | + public function forTemplate() { |
|
541 | + $this->generate(); |
|
542 | + MapUtil::set_map_already_rendered(true); |
|
543 | + return $this->getGoogleMap(); |
|
544 | + } |
|
545 | + |
|
546 | + /** |
|
547 | + * Add a KML file which will be rendered on this map. Normally used for likes |
|
548 | + * of GPS traces from activities |
|
549 | + * |
|
550 | + * @param string $url url of the kml file compatible with gmap and gearth |
|
551 | + * |
|
552 | + * @return MapAPI |
|
553 | + */ |
|
554 | + |
|
555 | + public function addKML($url) { |
|
556 | + array_push($this->kmlFiles, $url); |
|
557 | + return $this; |
|
558 | + } |
|
559 | + |
|
560 | + |
|
561 | + /* |
|
562 | 562 | Add a line to the map |
563 | 563 | |
564 | 564 | */ |
565 | - public function addLine($from = array(), $to = array(), $color = "#FF3300") { |
|
566 | - $line = array( |
|
567 | - 'lat1' => $from[0], |
|
568 | - 'lon1' => $from[1], |
|
569 | - 'lat2' => $to[0], |
|
570 | - 'lon2' => $to[1], |
|
571 | - 'color' => $color |
|
572 | - ); |
|
565 | + public function addLine($from = array(), $to = array(), $color = "#FF3300") { |
|
566 | + $line = array( |
|
567 | + 'lat1' => $from[0], |
|
568 | + 'lon1' => $from[1], |
|
569 | + 'lat2' => $to[0], |
|
570 | + 'lon2' => $to[1], |
|
571 | + 'color' => $color |
|
572 | + ); |
|
573 | 573 | |
574 | - array_push($this->lines, $line); |
|
575 | - return $this; |
|
576 | - } |
|
574 | + array_push($this->lines, $line); |
|
575 | + return $this; |
|
576 | + } |
|
577 | 577 | |
578 | 578 | |
579 | - /* |
|
579 | + /* |
|
580 | 580 | For php 5.3 |
581 | 581 | */ |
582 | - public static function jsonRemoveUnicodeSequences($struct) { |
|
583 | - return preg_replace("/\\\\u([a-f0-9]{4})/e", |
|
584 | - "iconv('UCS-4LE','UTF-8',pack('V', hexdec('U$1')))", |
|
585 | - json_encode($struct)); |
|
586 | - } |
|
587 | - |
|
588 | - |
|
589 | - /** |
|
590 | - * Generate the gmap |
|
591 | - * |
|
592 | - * @return void |
|
593 | - */ |
|
594 | - |
|
595 | - public function generate() { |
|
596 | - // from http://stackoverflow.com/questions/3586401/cant-decode-json-string-in-php |
|
597 | - $jsonMarkers = null; |
|
598 | - $linesJson = null; |
|
599 | - $kmlJson = null; |
|
600 | - |
|
601 | - // prior to PHP version 5.4, one needs to use regex |
|
602 | - if (PHP_VERSION_ID < 50400) { |
|
603 | - $jsonMarkers = stripslashes(MapAPI::jsonRemoveUnicodeSequences($this->markers)); |
|
604 | - $linesJson = stripslashes(MapAPI::jsonRemoveUnicodeSequences($this->lines)); |
|
605 | - $kmlJson = stripslashes(MapAPI::jsonRemoveUnicodeSequences($this->kmlFiles)); |
|
606 | - } else { |
|
607 | - $jsonMarkers = stripslashes(json_encode($this->markers, JSON_UNESCAPED_UNICODE)); |
|
608 | - $linesJson = stripslashes(json_encode($this->lines, JSON_UNESCAPED_UNICODE)); |
|
609 | - $kmlJson = stripslashes(json_encode($this->kmlFiles, JSON_UNESCAPED_UNICODE)); |
|
610 | - } |
|
611 | - |
|
612 | - // Center of the GMap - text centre takes precedence |
|
613 | - $geocodeCentre = ($this->latLongCenter) ? |
|
614 | - $this->latLongCenter : $this->geocoding($this->center); |
|
615 | - |
|
616 | - $latlngCentre = null; |
|
617 | - // coordinates for centre depending on which method used |
|
618 | - if (isset($geocodeCentre['geocoded'])) { |
|
619 | - $latlngCentre = array( |
|
620 | - 'lat' => $geocodeCentre['lat'], |
|
621 | - 'lng' => $geocodeCentre['lon'] |
|
622 | - ); |
|
623 | - } else if (is_array($this->latLongCenter)) { |
|
624 | - $latlngCentre = $this->latLongCenter; |
|
625 | - } |
|
626 | - |
|
627 | - $this->LatLngCentreJSON = stripslashes(json_encode($latlngCentre)); |
|
628 | - |
|
629 | - $lenLng = $this->maxLng - $this->minLng; |
|
630 | - $lenLat = $this->maxLat - $this->minLat; |
|
631 | - $this->minLng -= $lenLng * $this->coordCoef; |
|
632 | - $this->maxLng += $lenLng * $this->coordCoef; |
|
633 | - $this->minLat -= $lenLat * $this->coordCoef; |
|
634 | - $this->maxLat += $lenLat * $this->coordCoef; |
|
635 | - |
|
636 | - // add the css class mappable as a handle onto the map styling |
|
637 | - $this->additional_css_classes .= ' mappable'; |
|
638 | - |
|
639 | - if (!$this->enableAutomaticCenterZoom) { |
|
640 | - $this->enableAutomaticCenterZoom = 'false'; |
|
641 | - } |
|
642 | - |
|
643 | - if (!$this->useClusterer) { |
|
644 | - $this->useClusterer = 'false'; |
|
645 | - } |
|
646 | - |
|
647 | - if (!$this->defaultHideMarker) { |
|
648 | - $this->defaultHideMarker = 'false'; |
|
649 | - } |
|
650 | - |
|
651 | - // initialise full screen as the config value if not already set |
|
652 | - if ($this->allowFullScreen === null) { |
|
653 | - $this->allowFullScreen = Config::inst()->get('Mappable', 'allow_full_screen'); |
|
654 | - } |
|
655 | - |
|
656 | - if (!$this->allowFullScreen) { |
|
657 | - $this->allowFullScreen = 'false'; |
|
658 | - } |
|
659 | - |
|
660 | - if (!$this->enableWindowZoom) { |
|
661 | - $this->enableWindowZoom = 'false'; |
|
662 | - } |
|
663 | - |
|
664 | - $vars = new ArrayData(array( |
|
665 | - |
|
666 | - 'JsonMapStyles' => $this->jsonMapStyles, |
|
667 | - 'AdditionalCssClasses' => $this->additional_css_classes, |
|
668 | - 'Width' => $this->width, |
|
669 | - 'Height' => $this->height, |
|
670 | - 'ShowInlineMapDivStyle' => $this->show_inline_map_div_style, |
|
671 | - 'InfoWindowZoom' => $this->infoWindowZoom, |
|
672 | - 'EnableWindowZoom' => $this->enableWindowZoom, |
|
673 | - 'MapMarkers' => $jsonMarkers, |
|
674 | - 'DefaultHideMarker' => $this->defaultHideMarker, |
|
675 | - 'LatLngCentre' => $this->LatLngCentreJSON, |
|
676 | - 'EnableAutomaticCenterZoom' => $this->enableAutomaticCenterZoom, |
|
677 | - 'Zoom' => $this->zoom, |
|
678 | - 'MaxZoom' => $this->maxZoom, |
|
679 | - 'GridSize' => $this->gridSize, |
|
680 | - 'MapType' => $this->mapType, |
|
681 | - 'GoogleMapID' => $this->googleMapId, |
|
682 | - 'Lang'=>$this->lang, |
|
683 | - 'UseClusterer'=>$this->useClusterer, |
|
684 | - 'ClustererLibraryPath' => $this->clustererLibraryPath, |
|
685 | - 'ClustererMaxZoom' => $this->maxZoom, |
|
686 | - 'ClustererGridSize' => $this->gridSize, |
|
687 | - 'Lines' => $linesJson, |
|
688 | - 'KmlFiles' => $kmlJson, |
|
689 | - 'AllowFullScreen' => $this->allowFullScreen, |
|
690 | - 'UseCompressedAssets' => Config::inst()->get('Mappable', 'use_compressed_assets') |
|
691 | - ) |
|
692 | - ); |
|
693 | - |
|
694 | - if (!MapUtil::get_map_already_rendered()) { |
|
695 | - $vars->setField('GoogleMapKey', $this->googleMapKey); |
|
696 | - $vars->setField('GoogleMapLang', $this->lang); |
|
697 | - } |
|
698 | - |
|
699 | - // HTML component of the map |
|
700 | - $this->content = $this->processTemplateHTML('Map', $vars); |
|
701 | - } |
|
702 | - |
|
703 | - /** |
|
704 | - * @param string $templateName |
|
705 | - * @param ArrayData $templateVariables |
|
706 | - */ |
|
707 | - public function processTemplateHTML($templateName, $templateVariables = null) { |
|
708 | - if (!$templateVariables) { |
|
709 | - $templateVariables = new ArrayList(); |
|
710 | - } |
|
711 | - $mappingService = Config::inst()->get('Mappable', 'mapping_service'); |
|
712 | - $result = $templateVariables->renderWith($templateName.$mappingService.'HTML'); |
|
713 | - return $result; |
|
714 | - } |
|
582 | + public static function jsonRemoveUnicodeSequences($struct) { |
|
583 | + return preg_replace("/\\\\u([a-f0-9]{4})/e", |
|
584 | + "iconv('UCS-4LE','UTF-8',pack('V', hexdec('U$1')))", |
|
585 | + json_encode($struct)); |
|
586 | + } |
|
587 | + |
|
588 | + |
|
589 | + /** |
|
590 | + * Generate the gmap |
|
591 | + * |
|
592 | + * @return void |
|
593 | + */ |
|
594 | + |
|
595 | + public function generate() { |
|
596 | + // from http://stackoverflow.com/questions/3586401/cant-decode-json-string-in-php |
|
597 | + $jsonMarkers = null; |
|
598 | + $linesJson = null; |
|
599 | + $kmlJson = null; |
|
600 | + |
|
601 | + // prior to PHP version 5.4, one needs to use regex |
|
602 | + if (PHP_VERSION_ID < 50400) { |
|
603 | + $jsonMarkers = stripslashes(MapAPI::jsonRemoveUnicodeSequences($this->markers)); |
|
604 | + $linesJson = stripslashes(MapAPI::jsonRemoveUnicodeSequences($this->lines)); |
|
605 | + $kmlJson = stripslashes(MapAPI::jsonRemoveUnicodeSequences($this->kmlFiles)); |
|
606 | + } else { |
|
607 | + $jsonMarkers = stripslashes(json_encode($this->markers, JSON_UNESCAPED_UNICODE)); |
|
608 | + $linesJson = stripslashes(json_encode($this->lines, JSON_UNESCAPED_UNICODE)); |
|
609 | + $kmlJson = stripslashes(json_encode($this->kmlFiles, JSON_UNESCAPED_UNICODE)); |
|
610 | + } |
|
611 | + |
|
612 | + // Center of the GMap - text centre takes precedence |
|
613 | + $geocodeCentre = ($this->latLongCenter) ? |
|
614 | + $this->latLongCenter : $this->geocoding($this->center); |
|
615 | + |
|
616 | + $latlngCentre = null; |
|
617 | + // coordinates for centre depending on which method used |
|
618 | + if (isset($geocodeCentre['geocoded'])) { |
|
619 | + $latlngCentre = array( |
|
620 | + 'lat' => $geocodeCentre['lat'], |
|
621 | + 'lng' => $geocodeCentre['lon'] |
|
622 | + ); |
|
623 | + } else if (is_array($this->latLongCenter)) { |
|
624 | + $latlngCentre = $this->latLongCenter; |
|
625 | + } |
|
626 | + |
|
627 | + $this->LatLngCentreJSON = stripslashes(json_encode($latlngCentre)); |
|
628 | + |
|
629 | + $lenLng = $this->maxLng - $this->minLng; |
|
630 | + $lenLat = $this->maxLat - $this->minLat; |
|
631 | + $this->minLng -= $lenLng * $this->coordCoef; |
|
632 | + $this->maxLng += $lenLng * $this->coordCoef; |
|
633 | + $this->minLat -= $lenLat * $this->coordCoef; |
|
634 | + $this->maxLat += $lenLat * $this->coordCoef; |
|
635 | + |
|
636 | + // add the css class mappable as a handle onto the map styling |
|
637 | + $this->additional_css_classes .= ' mappable'; |
|
638 | + |
|
639 | + if (!$this->enableAutomaticCenterZoom) { |
|
640 | + $this->enableAutomaticCenterZoom = 'false'; |
|
641 | + } |
|
642 | + |
|
643 | + if (!$this->useClusterer) { |
|
644 | + $this->useClusterer = 'false'; |
|
645 | + } |
|
646 | + |
|
647 | + if (!$this->defaultHideMarker) { |
|
648 | + $this->defaultHideMarker = 'false'; |
|
649 | + } |
|
650 | + |
|
651 | + // initialise full screen as the config value if not already set |
|
652 | + if ($this->allowFullScreen === null) { |
|
653 | + $this->allowFullScreen = Config::inst()->get('Mappable', 'allow_full_screen'); |
|
654 | + } |
|
655 | + |
|
656 | + if (!$this->allowFullScreen) { |
|
657 | + $this->allowFullScreen = 'false'; |
|
658 | + } |
|
659 | + |
|
660 | + if (!$this->enableWindowZoom) { |
|
661 | + $this->enableWindowZoom = 'false'; |
|
662 | + } |
|
663 | + |
|
664 | + $vars = new ArrayData(array( |
|
665 | + |
|
666 | + 'JsonMapStyles' => $this->jsonMapStyles, |
|
667 | + 'AdditionalCssClasses' => $this->additional_css_classes, |
|
668 | + 'Width' => $this->width, |
|
669 | + 'Height' => $this->height, |
|
670 | + 'ShowInlineMapDivStyle' => $this->show_inline_map_div_style, |
|
671 | + 'InfoWindowZoom' => $this->infoWindowZoom, |
|
672 | + 'EnableWindowZoom' => $this->enableWindowZoom, |
|
673 | + 'MapMarkers' => $jsonMarkers, |
|
674 | + 'DefaultHideMarker' => $this->defaultHideMarker, |
|
675 | + 'LatLngCentre' => $this->LatLngCentreJSON, |
|
676 | + 'EnableAutomaticCenterZoom' => $this->enableAutomaticCenterZoom, |
|
677 | + 'Zoom' => $this->zoom, |
|
678 | + 'MaxZoom' => $this->maxZoom, |
|
679 | + 'GridSize' => $this->gridSize, |
|
680 | + 'MapType' => $this->mapType, |
|
681 | + 'GoogleMapID' => $this->googleMapId, |
|
682 | + 'Lang'=>$this->lang, |
|
683 | + 'UseClusterer'=>$this->useClusterer, |
|
684 | + 'ClustererLibraryPath' => $this->clustererLibraryPath, |
|
685 | + 'ClustererMaxZoom' => $this->maxZoom, |
|
686 | + 'ClustererGridSize' => $this->gridSize, |
|
687 | + 'Lines' => $linesJson, |
|
688 | + 'KmlFiles' => $kmlJson, |
|
689 | + 'AllowFullScreen' => $this->allowFullScreen, |
|
690 | + 'UseCompressedAssets' => Config::inst()->get('Mappable', 'use_compressed_assets') |
|
691 | + ) |
|
692 | + ); |
|
693 | + |
|
694 | + if (!MapUtil::get_map_already_rendered()) { |
|
695 | + $vars->setField('GoogleMapKey', $this->googleMapKey); |
|
696 | + $vars->setField('GoogleMapLang', $this->lang); |
|
697 | + } |
|
698 | + |
|
699 | + // HTML component of the map |
|
700 | + $this->content = $this->processTemplateHTML('Map', $vars); |
|
701 | + } |
|
702 | + |
|
703 | + /** |
|
704 | + * @param string $templateName |
|
705 | + * @param ArrayData $templateVariables |
|
706 | + */ |
|
707 | + public function processTemplateHTML($templateName, $templateVariables = null) { |
|
708 | + if (!$templateVariables) { |
|
709 | + $templateVariables = new ArrayList(); |
|
710 | + } |
|
711 | + $mappingService = Config::inst()->get('Mappable', 'mapping_service'); |
|
712 | + $result = $templateVariables->renderWith($templateName.$mappingService.'HTML'); |
|
713 | + return $result; |
|
714 | + } |
|
715 | 715 | } |
@@ -2,31 +2,31 @@ |
||
2 | 2 | |
3 | 3 | class MapMarkerSetsExtension extends DataExtension { |
4 | 4 | |
5 | - static $many_many = array( |
|
6 | - 'MapMarkerSets' => 'MapMarkerSet' |
|
7 | - ); |
|
8 | - |
|
9 | - |
|
10 | - static $belongs_many_many_extraFields = array( |
|
11 | - 'MapMarkerSets' => array( |
|
12 | - 'SortOrder' => "Int" |
|
13 | - ) |
|
14 | - ); |
|
15 | - |
|
16 | - |
|
17 | - public function updateCMSFields(FieldList $fields) { |
|
18 | - $gridConfig2 = GridFieldConfig_RelationEditor::create(); |
|
19 | - $gridConfig2->getComponentByType( |
|
20 | - 'GridFieldAddExistingAutocompleter')->setSearchFields(array('Title') |
|
21 | - ); |
|
22 | - $gridConfig2->getComponentByType('GridFieldPaginator')->setItemsPerPage(100); |
|
23 | - |
|
24 | - $gridField2 = new GridField("MapMarkerSets", |
|
25 | - "MapMarker Sets", |
|
26 | - $this->owner->MapMarkerSets(), |
|
27 | - $gridConfig2 |
|
28 | - ); |
|
29 | - $fields->addFieldToTab("Root.MapMarkerSets", $gridField2); |
|
30 | - } |
|
5 | + static $many_many = array( |
|
6 | + 'MapMarkerSets' => 'MapMarkerSet' |
|
7 | + ); |
|
8 | + |
|
9 | + |
|
10 | + static $belongs_many_many_extraFields = array( |
|
11 | + 'MapMarkerSets' => array( |
|
12 | + 'SortOrder' => "Int" |
|
13 | + ) |
|
14 | + ); |
|
15 | + |
|
16 | + |
|
17 | + public function updateCMSFields(FieldList $fields) { |
|
18 | + $gridConfig2 = GridFieldConfig_RelationEditor::create(); |
|
19 | + $gridConfig2->getComponentByType( |
|
20 | + 'GridFieldAddExistingAutocompleter')->setSearchFields(array('Title') |
|
21 | + ); |
|
22 | + $gridConfig2->getComponentByType('GridFieldPaginator')->setItemsPerPage(100); |
|
23 | + |
|
24 | + $gridField2 = new GridField("MapMarkerSets", |
|
25 | + "MapMarker Sets", |
|
26 | + $this->owner->MapMarkerSets(), |
|
27 | + $gridConfig2 |
|
28 | + ); |
|
29 | + $fields->addFieldToTab("Root.MapMarkerSets", $gridField2); |
|
30 | + } |
|
31 | 31 | |
32 | 32 | } |
@@ -2,13 +2,13 @@ |
||
2 | 2 | |
3 | 3 | class MapLayer extends DataObject { |
4 | 4 | |
5 | - static $db = array( |
|
6 | - 'Title' => 'Varchar(255)' |
|
7 | - ); |
|
5 | + static $db = array( |
|
6 | + 'Title' => 'Varchar(255)' |
|
7 | + ); |
|
8 | 8 | |
9 | 9 | |
10 | - static $has_one = array( |
|
11 | - 'KmlFile' => 'File' |
|
12 | - ); |
|
10 | + static $has_one = array( |
|
11 | + 'KmlFile' => 'File' |
|
12 | + ); |
|
13 | 13 | |
14 | 14 | } |
@@ -2,28 +2,28 @@ |
||
2 | 2 | |
3 | 3 | class MapLayerExtension extends DataExtension { |
4 | 4 | |
5 | - static $many_many = array( |
|
6 | - 'MapLayers' => 'MapLayer' |
|
7 | - ); |
|
5 | + static $many_many = array( |
|
6 | + 'MapLayers' => 'MapLayer' |
|
7 | + ); |
|
8 | 8 | |
9 | - static $belongs_many_many_extraFields = array( |
|
10 | - 'MapLayers' => array( |
|
11 | - 'SortOrder' => "Int" |
|
12 | - ) |
|
13 | - ); |
|
9 | + static $belongs_many_many_extraFields = array( |
|
10 | + 'MapLayers' => array( |
|
11 | + 'SortOrder' => "Int" |
|
12 | + ) |
|
13 | + ); |
|
14 | 14 | |
15 | - public function updateCMSFields(FieldList $fields) { |
|
16 | - $gridConfig2 = GridFieldConfig_RelationEditor::create(); |
|
17 | - $gridConfig2->getComponentByType( |
|
18 | - 'GridFieldAddExistingAutocompleter')-> |
|
19 | - setSearchFields(array('Title') |
|
20 | - ); |
|
21 | - $gridConfig2->getComponentByType('GridFieldPaginator')->setItemsPerPage(100); |
|
22 | - $gridField2 = new GridField("Map Layers", |
|
23 | - "Map Layers:", |
|
24 | - $this->owner->MapLayers(), |
|
25 | - $gridConfig2 |
|
26 | - ); |
|
27 | - $fields->addFieldToTab("Root.MapLayers", $gridField2); |
|
28 | - } |
|
15 | + public function updateCMSFields(FieldList $fields) { |
|
16 | + $gridConfig2 = GridFieldConfig_RelationEditor::create(); |
|
17 | + $gridConfig2->getComponentByType( |
|
18 | + 'GridFieldAddExistingAutocompleter')-> |
|
19 | + setSearchFields(array('Title') |
|
20 | + ); |
|
21 | + $gridConfig2->getComponentByType('GridFieldPaginator')->setItemsPerPage(100); |
|
22 | + $gridField2 = new GridField("Map Layers", |
|
23 | + "Map Layers:", |
|
24 | + $this->owner->MapLayers(), |
|
25 | + $gridConfig2 |
|
26 | + ); |
|
27 | + $fields->addFieldToTab("Root.MapLayers", $gridField2); |
|
28 | + } |
|
29 | 29 | } |
@@ -2,22 +2,22 @@ |
||
2 | 2 | |
3 | 3 | class MapFieldTest extends SapphireTest { |
4 | 4 | |
5 | - public function testFieldWithTitle() { |
|
6 | - //$headingLevel = 2, $allowHTML = false, $form = nul |
|
7 | - $field = new MapField('NameOfField', 'TitleOfField'); |
|
8 | - $expected = '<div class="editableMap"><div class="middleColumn" id="Nam' |
|
9 | - . 'eOfField" style="width:100%;height:300px;margin:5px 0px 5p' |
|
10 | - . 'x 5px;position:relative;"></div></div>'; |
|
11 | - $this->assertEquals($expected, $field->Field()); |
|
12 | - } |
|
5 | + public function testFieldWithTitle() { |
|
6 | + //$headingLevel = 2, $allowHTML = false, $form = nul |
|
7 | + $field = new MapField('NameOfField', 'TitleOfField'); |
|
8 | + $expected = '<div class="editableMap"><div class="middleColumn" id="Nam' |
|
9 | + . 'eOfField" style="width:100%;height:300px;margin:5px 0px 5p' |
|
10 | + . 'x 5px;position:relative;"></div></div>'; |
|
11 | + $this->assertEquals($expected, $field->Field()); |
|
12 | + } |
|
13 | 13 | |
14 | - public function testFieldWithoutTitle() { |
|
15 | - //$headingLevel = 2, $allowHTML = false, $form = nul |
|
16 | - $field = new MapField('NameOfField'); |
|
17 | - $expected = '<div class="editableMap"><div class="middleColumn" id="Nam' |
|
18 | - . 'eOfField" style="width:100%;height:300px;margin:5px 0px 5p' |
|
19 | - . 'x 5px;position:relative;"></div></div>'; |
|
20 | - $this->assertEquals($expected, $field->Field()); |
|
21 | - } |
|
14 | + public function testFieldWithoutTitle() { |
|
15 | + //$headingLevel = 2, $allowHTML = false, $form = nul |
|
16 | + $field = new MapField('NameOfField'); |
|
17 | + $expected = '<div class="editableMap"><div class="middleColumn" id="Nam' |
|
18 | + . 'eOfField" style="width:100%;height:300px;margin:5px 0px 5p' |
|
19 | + . 'x 5px;position:relative;"></div></div>'; |
|
20 | + $this->assertEquals($expected, $field->Field()); |
|
21 | + } |
|
22 | 22 | |
23 | 23 | } |
@@ -1,127 +1,127 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | class LatLongFieldTest extends SapphireTest { |
4 | - public function testConstructValid() { |
|
5 | - $mapField = new LatLongField(array( |
|
6 | - new TextField('Lat', 'Latitude'), |
|
7 | - new TextField('Lon', 'Longitude'), |
|
8 | - new TextField('ZoomLevel', 'Zoom') |
|
9 | - ), |
|
10 | - array('Address') |
|
11 | - ); |
|
12 | - |
|
13 | - |
|
14 | - } |
|
15 | - |
|
16 | - public function testConstructOneFieldInvalid() { |
|
17 | - try { |
|
18 | - $mapField = new LatLongField( |
|
19 | - array( |
|
20 | - new TextField('Lat', 'Latitude') |
|
21 | - ) |
|
22 | - ); |
|
23 | - $this->fail('Creation of lat long field should have failed'); |
|
24 | - } catch (Exception $e) { |
|
25 | - $expected = 'LatLongField argument 1 must be an array containing at' |
|
26 | - . ' least two FormField objects for Lat/Long values, resp' |
|
27 | - . 'ectively.'; |
|
28 | - $this->assertEquals($expected, $e->getMessage()); |
|
29 | - } |
|
30 | - } |
|
31 | - |
|
32 | - |
|
33 | - public function testConstructTwoFieldsValid() { |
|
34 | - $mapField = new LatLongField( |
|
35 | - array( |
|
36 | - new TextField('Lat', 'Latitude'), |
|
37 | - new TextField('Lon', 'Longitude') |
|
38 | - ) |
|
39 | - ); |
|
40 | - |
|
41 | - $html = $mapField->FieldHolder(); |
|
42 | - $this->assertContains( |
|
43 | - '<label class="fieldholder-small-label" for="Lat">Latitude</label>', |
|
44 | - $html |
|
45 | - ); |
|
46 | - $this->assertContains( |
|
47 | - '<input type="text" name="Lat" class="text hide" id="Lat" />', |
|
48 | - $html |
|
49 | - ); |
|
50 | - $this->assertContains( |
|
51 | - '<label class="fieldholder-small-label" for="Lon">Longitude</label>', |
|
52 | - $html |
|
53 | - ); |
|
54 | - $this->assertContains( |
|
55 | - '<input type="text" name="Lon" class="text hide" id="Lon" />', |
|
56 | - $html |
|
57 | - ); |
|
58 | - |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - public function testConstructThreeFieldsValid() { |
|
63 | - $mapField = new LatLongField( |
|
64 | - array( |
|
65 | - new TextField('Lat', 'Latitude'), |
|
66 | - new TextField('Lon', 'Longitude'), |
|
67 | - new TextField('ZoomLevel', 'Zoom') |
|
68 | - ) |
|
69 | - ); |
|
70 | - |
|
71 | - $html = $mapField->FieldHolder(); |
|
72 | - $this->assertContains( |
|
73 | - '<label class="fieldholder-small-label" for="Lat">Latitude</label>', |
|
74 | - $html |
|
75 | - ); |
|
76 | - $this->assertContains( |
|
77 | - '<input type="text" name="Lat" class="text hide" id="Lat" />', |
|
78 | - $html |
|
79 | - ); |
|
80 | - $this->assertContains( |
|
81 | - '<label class="fieldholder-small-label" for="Lon">Longitude</label>', |
|
82 | - $html |
|
83 | - ); |
|
84 | - $this->assertContains( |
|
85 | - '<input type="text" name="Lon" class="text hide" id="Lon" />', |
|
86 | - $html |
|
87 | - ); |
|
88 | - $this->assertContains( |
|
89 | - '<label class="fieldholder-small-label" for="ZoomLevel">Zoom</label>', |
|
90 | - $html |
|
91 | - ); |
|
92 | - $this->assertContains( |
|
93 | - '<input type="text" name="ZoomLevel" class="text hide" id="ZoomLevel" />', |
|
94 | - $html |
|
95 | - ); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - public function testGeocode() { |
|
100 | - $this->markTestSkipped('TODO'); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - public function testSetGuidePoints() { |
|
105 | - $mapField = new LatLongField( |
|
106 | - array( |
|
107 | - new TextField('Lat', 'Latitude'), |
|
108 | - new TextField('Lon', 'Longitude'), |
|
109 | - new TextField('ZoomLevel', 'Zoom') |
|
110 | - ) |
|
111 | - ); |
|
112 | - $guidePoints = array( |
|
113 | - array('latitude' => 42, 'longitude' => '113.1'), |
|
114 | - array('latitude' => 14.9, 'longitude' => '113.2'), |
|
115 | - array('latitude' => 42.3, 'longitude' => '113.4'), |
|
116 | - ); |
|
117 | - $mapField->setGuidePoints($guidePoints); |
|
118 | - |
|
119 | - $html = $mapField->FieldHolder(); |
|
120 | - $expected = 'data-GuidePoints="[{"latitude":42,"longitude":"113.1&' |
|
121 | - . 'quot;},{"latitude":14.9,"longitude":"113.2"},{&q' |
|
122 | - . 'uot;latitude":42.3,"longitude":"113.4"}]"'; |
|
123 | - |
|
124 | - $this->assertContains($expected, $html); |
|
125 | - } |
|
4 | + public function testConstructValid() { |
|
5 | + $mapField = new LatLongField(array( |
|
6 | + new TextField('Lat', 'Latitude'), |
|
7 | + new TextField('Lon', 'Longitude'), |
|
8 | + new TextField('ZoomLevel', 'Zoom') |
|
9 | + ), |
|
10 | + array('Address') |
|
11 | + ); |
|
12 | + |
|
13 | + |
|
14 | + } |
|
15 | + |
|
16 | + public function testConstructOneFieldInvalid() { |
|
17 | + try { |
|
18 | + $mapField = new LatLongField( |
|
19 | + array( |
|
20 | + new TextField('Lat', 'Latitude') |
|
21 | + ) |
|
22 | + ); |
|
23 | + $this->fail('Creation of lat long field should have failed'); |
|
24 | + } catch (Exception $e) { |
|
25 | + $expected = 'LatLongField argument 1 must be an array containing at' |
|
26 | + . ' least two FormField objects for Lat/Long values, resp' |
|
27 | + . 'ectively.'; |
|
28 | + $this->assertEquals($expected, $e->getMessage()); |
|
29 | + } |
|
30 | + } |
|
31 | + |
|
32 | + |
|
33 | + public function testConstructTwoFieldsValid() { |
|
34 | + $mapField = new LatLongField( |
|
35 | + array( |
|
36 | + new TextField('Lat', 'Latitude'), |
|
37 | + new TextField('Lon', 'Longitude') |
|
38 | + ) |
|
39 | + ); |
|
40 | + |
|
41 | + $html = $mapField->FieldHolder(); |
|
42 | + $this->assertContains( |
|
43 | + '<label class="fieldholder-small-label" for="Lat">Latitude</label>', |
|
44 | + $html |
|
45 | + ); |
|
46 | + $this->assertContains( |
|
47 | + '<input type="text" name="Lat" class="text hide" id="Lat" />', |
|
48 | + $html |
|
49 | + ); |
|
50 | + $this->assertContains( |
|
51 | + '<label class="fieldholder-small-label" for="Lon">Longitude</label>', |
|
52 | + $html |
|
53 | + ); |
|
54 | + $this->assertContains( |
|
55 | + '<input type="text" name="Lon" class="text hide" id="Lon" />', |
|
56 | + $html |
|
57 | + ); |
|
58 | + |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + public function testConstructThreeFieldsValid() { |
|
63 | + $mapField = new LatLongField( |
|
64 | + array( |
|
65 | + new TextField('Lat', 'Latitude'), |
|
66 | + new TextField('Lon', 'Longitude'), |
|
67 | + new TextField('ZoomLevel', 'Zoom') |
|
68 | + ) |
|
69 | + ); |
|
70 | + |
|
71 | + $html = $mapField->FieldHolder(); |
|
72 | + $this->assertContains( |
|
73 | + '<label class="fieldholder-small-label" for="Lat">Latitude</label>', |
|
74 | + $html |
|
75 | + ); |
|
76 | + $this->assertContains( |
|
77 | + '<input type="text" name="Lat" class="text hide" id="Lat" />', |
|
78 | + $html |
|
79 | + ); |
|
80 | + $this->assertContains( |
|
81 | + '<label class="fieldholder-small-label" for="Lon">Longitude</label>', |
|
82 | + $html |
|
83 | + ); |
|
84 | + $this->assertContains( |
|
85 | + '<input type="text" name="Lon" class="text hide" id="Lon" />', |
|
86 | + $html |
|
87 | + ); |
|
88 | + $this->assertContains( |
|
89 | + '<label class="fieldholder-small-label" for="ZoomLevel">Zoom</label>', |
|
90 | + $html |
|
91 | + ); |
|
92 | + $this->assertContains( |
|
93 | + '<input type="text" name="ZoomLevel" class="text hide" id="ZoomLevel" />', |
|
94 | + $html |
|
95 | + ); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + public function testGeocode() { |
|
100 | + $this->markTestSkipped('TODO'); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + public function testSetGuidePoints() { |
|
105 | + $mapField = new LatLongField( |
|
106 | + array( |
|
107 | + new TextField('Lat', 'Latitude'), |
|
108 | + new TextField('Lon', 'Longitude'), |
|
109 | + new TextField('ZoomLevel', 'Zoom') |
|
110 | + ) |
|
111 | + ); |
|
112 | + $guidePoints = array( |
|
113 | + array('latitude' => 42, 'longitude' => '113.1'), |
|
114 | + array('latitude' => 14.9, 'longitude' => '113.2'), |
|
115 | + array('latitude' => 42.3, 'longitude' => '113.4'), |
|
116 | + ); |
|
117 | + $mapField->setGuidePoints($guidePoints); |
|
118 | + |
|
119 | + $html = $mapField->FieldHolder(); |
|
120 | + $expected = 'data-GuidePoints="[{"latitude":42,"longitude":"113.1&' |
|
121 | + . 'quot;},{"latitude":14.9,"longitude":"113.2"},{&q' |
|
122 | + . 'uot;latitude":42.3,"longitude":"113.4"}]"'; |
|
123 | + |
|
124 | + $this->assertContains($expected, $html); |
|
125 | + } |
|
126 | 126 | |
127 | 127 | } |
@@ -2,25 +2,25 @@ |
||
2 | 2 | |
3 | 3 | class MapLayerExtensionTest extends SapphireTest { |
4 | 4 | |
5 | - public function setUp() { |
|
6 | - // add MapExtension and MapLayerExtension extension to Member |
|
7 | - Member::add_extension('MapExtension'); |
|
8 | - Member::add_extension('MapLayerExtension'); |
|
9 | - parent::setUp(); |
|
10 | - } |
|
5 | + public function setUp() { |
|
6 | + // add MapExtension and MapLayerExtension extension to Member |
|
7 | + Member::add_extension('MapExtension'); |
|
8 | + Member::add_extension('MapLayerExtension'); |
|
9 | + parent::setUp(); |
|
10 | + } |
|
11 | 11 | |
12 | - // check for addition of extra CMS fields |
|
13 | - public function testCMSFields() { |
|
14 | - $instance = new Member(); |
|
15 | - $fields = $instance->getCMSFields(); |
|
16 | - $tab = $fields->findOrMakeTab('Root.MapLayers'); |
|
17 | - $fields = $tab->FieldList(); |
|
18 | - $names = array(); |
|
19 | - foreach ($fields as $field) { |
|
20 | - $names[] = $field->getName(); |
|
21 | - } |
|
22 | - $expected = array('Map Layers'); |
|
23 | - $this->assertEquals($expected, $names); |
|
24 | - } |
|
12 | + // check for addition of extra CMS fields |
|
13 | + public function testCMSFields() { |
|
14 | + $instance = new Member(); |
|
15 | + $fields = $instance->getCMSFields(); |
|
16 | + $tab = $fields->findOrMakeTab('Root.MapLayers'); |
|
17 | + $fields = $tab->FieldList(); |
|
18 | + $names = array(); |
|
19 | + foreach ($fields as $field) { |
|
20 | + $names[] = $field->getName(); |
|
21 | + } |
|
22 | + $expected = array('Map Layers'); |
|
23 | + $this->assertEquals($expected, $names); |
|
24 | + } |
|
25 | 25 | |
26 | 26 | } |
@@ -5,13 +5,13 @@ discard block |
||
5 | 5 | */ |
6 | 6 | class GoogleMapShortCodeTest extends SapphireTest |
7 | 7 | { |
8 | - protected static $fixture_file = 'mappable/tests/shortcodes.yml'; |
|
8 | + protected static $fixture_file = 'mappable/tests/shortcodes.yml'; |
|
9 | 9 | |
10 | - public function testRoadMap() { |
|
11 | - GoogleMapShortCodeHandler::resetCounter(); |
|
12 | - $page = $this->objFromFixture('Page', 'RoadMap'); |
|
13 | - $html = ShortcodeParser::get_active()->parse($page->Content); |
|
14 | - $expected = <<<TEXT |
|
10 | + public function testRoadMap() { |
|
11 | + GoogleMapShortCodeHandler::resetCounter(); |
|
12 | + $page = $this->objFromFixture('Page', 'RoadMap'); |
|
13 | + $html = ShortcodeParser::get_active()->parse($page->Content); |
|
14 | + $expected = <<<TEXT |
|
15 | 15 | Some text |
16 | 16 | |
17 | 17 | <div class="googlemapcontainer"> |
@@ -20,15 +20,15 @@ discard block |
||
20 | 20 | </div> |
21 | 21 | |
22 | 22 | TEXT; |
23 | - $this->assertEquals($expected, $html); |
|
24 | - } |
|
23 | + $this->assertEquals($expected, $html); |
|
24 | + } |
|
25 | 25 | |
26 | 26 | |
27 | - public function testAerialMap() { |
|
28 | - GoogleMapShortCodeHandler::resetCounter(); |
|
29 | - $page = $this->objFromFixture('Page', 'AerialMap'); |
|
30 | - $html = ShortcodeParser::get_active()->parse($page->Content); |
|
31 | - $expected = <<<TEXT |
|
27 | + public function testAerialMap() { |
|
28 | + GoogleMapShortCodeHandler::resetCounter(); |
|
29 | + $page = $this->objFromFixture('Page', 'AerialMap'); |
|
30 | + $html = ShortcodeParser::get_active()->parse($page->Content); |
|
31 | + $expected = <<<TEXT |
|
32 | 32 | Some text |
33 | 33 | |
34 | 34 | <div class="googlemapcontainer"> |
@@ -37,15 +37,15 @@ discard block |
||
37 | 37 | </div> |
38 | 38 | |
39 | 39 | TEXT; |
40 | - $this->assertEquals($expected, $html); |
|
41 | - } |
|
40 | + $this->assertEquals($expected, $html); |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - public function testHybridMap() { |
|
45 | - GoogleMapShortCodeHandler::resetCounter(); |
|
46 | - $page = $this->objFromFixture('Page', 'HybridMap'); |
|
47 | - $html = ShortcodeParser::get_active()->parse($page->Content); |
|
48 | - $expected = <<<TEXT |
|
44 | + public function testHybridMap() { |
|
45 | + GoogleMapShortCodeHandler::resetCounter(); |
|
46 | + $page = $this->objFromFixture('Page', 'HybridMap'); |
|
47 | + $html = ShortcodeParser::get_active()->parse($page->Content); |
|
48 | + $expected = <<<TEXT |
|
49 | 49 | Some text |
50 | 50 | |
51 | 51 | <div class="googlemapcontainer"> |
@@ -54,15 +54,15 @@ discard block |
||
54 | 54 | </div> |
55 | 55 | |
56 | 56 | TEXT; |
57 | - $this->assertEquals($expected, $html); |
|
58 | - } |
|
57 | + $this->assertEquals($expected, $html); |
|
58 | + } |
|
59 | 59 | |
60 | 60 | |
61 | - public function testTerrainmap() { |
|
62 | - GoogleMapShortCodeHandler::resetCounter(); |
|
63 | - $page = $this->objFromFixture('Page', 'TerrainMap'); |
|
64 | - $html = ShortcodeParser::get_active()->parse($page->Content); |
|
65 | - $expected = <<<TEXT |
|
61 | + public function testTerrainmap() { |
|
62 | + GoogleMapShortCodeHandler::resetCounter(); |
|
63 | + $page = $this->objFromFixture('Page', 'TerrainMap'); |
|
64 | + $html = ShortcodeParser::get_active()->parse($page->Content); |
|
65 | + $expected = <<<TEXT |
|
66 | 66 | Some text |
67 | 67 | |
68 | 68 | <div class="googlemapcontainer"> |
@@ -71,22 +71,22 @@ discard block |
||
71 | 71 | </div> |
72 | 72 | |
73 | 73 | TEXT; |
74 | - $this->assertEquals($expected, $html); |
|
75 | - } |
|
74 | + $this->assertEquals($expected, $html); |
|
75 | + } |
|
76 | 76 | |
77 | 77 | |
78 | - public function testNoLongitude() { |
|
79 | - $page = $this->objFromFixture('Page', 'MapWithNoLongitude'); |
|
80 | - $html = ShortcodeParser::get_active()->parse($page->Content); |
|
81 | - $this->assertEquals('Some text', $html); |
|
82 | - } |
|
78 | + public function testNoLongitude() { |
|
79 | + $page = $this->objFromFixture('Page', 'MapWithNoLongitude'); |
|
80 | + $html = ShortcodeParser::get_active()->parse($page->Content); |
|
81 | + $this->assertEquals('Some text', $html); |
|
82 | + } |
|
83 | 83 | |
84 | 84 | |
85 | - public function testNoLatitude() { |
|
86 | - $page = $this->objFromFixture('Page', 'MapWithNoLatitude'); |
|
87 | - $html = ShortcodeParser::get_active()->parse($page->Content); |
|
88 | - $this->assertEquals('Some text', $html); |
|
89 | - } |
|
85 | + public function testNoLatitude() { |
|
86 | + $page = $this->objFromFixture('Page', 'MapWithNoLatitude'); |
|
87 | + $html = ShortcodeParser::get_active()->parse($page->Content); |
|
88 | + $this->assertEquals('Some text', $html); |
|
89 | + } |
|
90 | 90 | |
91 | 91 | |
92 | 92 | } |
@@ -2,68 +2,68 @@ discard block |
||
2 | 2 | |
3 | 3 | class MapAPITest extends SapphireTest { |
4 | 4 | |
5 | - public function setUpOnce() { |
|
6 | - $this->requiredExtensions = array( |
|
7 | - 'Member' => array('MapExtension') |
|
8 | - ); |
|
9 | - parent::setupOnce(); |
|
10 | - } |
|
11 | - |
|
12 | - public function setUp() { |
|
13 | - MapUtil::reset(); |
|
14 | - parent::setUp(); |
|
15 | - } |
|
16 | - |
|
17 | - public function testSetClusterer() { |
|
18 | - $map = $this->getMap(); |
|
19 | - $map->setClusterer(true); |
|
20 | - $html = $map->forTemplate(); |
|
21 | - $this->assertContains('data-clusterergridsize=50', $html); |
|
22 | - $this->assertContains('data-clusterermaxzoom=17', $html); |
|
23 | - $this->assertContains('data-useclusterer=1', $html); |
|
24 | - |
|
25 | - $map = $this->getMap(); |
|
26 | - $map->setClusterer(true, 60, 14); |
|
27 | - $html = $map->forTemplate(); |
|
28 | - $this->assertContains('data-clusterergridsize=60', $html); |
|
29 | - $this->assertContains('data-clusterermaxzoom=14', $html); |
|
30 | - $this->assertContains('data-useclusterer=1', $html); |
|
31 | - |
|
32 | - $map = $this->getMap(); |
|
33 | - $map->setClusterer(false); |
|
34 | - $html = $map->forTemplate(); |
|
35 | - $this->assertContains('data-useclusterer=false', $html); |
|
36 | - $this->assertContains('data-clusterergridsize=50', $html); |
|
37 | - $this->assertContains('data-clusterermaxzoom=17', $html); |
|
38 | - } |
|
39 | - |
|
40 | - /* |
|
5 | + public function setUpOnce() { |
|
6 | + $this->requiredExtensions = array( |
|
7 | + 'Member' => array('MapExtension') |
|
8 | + ); |
|
9 | + parent::setupOnce(); |
|
10 | + } |
|
11 | + |
|
12 | + public function setUp() { |
|
13 | + MapUtil::reset(); |
|
14 | + parent::setUp(); |
|
15 | + } |
|
16 | + |
|
17 | + public function testSetClusterer() { |
|
18 | + $map = $this->getMap(); |
|
19 | + $map->setClusterer(true); |
|
20 | + $html = $map->forTemplate(); |
|
21 | + $this->assertContains('data-clusterergridsize=50', $html); |
|
22 | + $this->assertContains('data-clusterermaxzoom=17', $html); |
|
23 | + $this->assertContains('data-useclusterer=1', $html); |
|
24 | + |
|
25 | + $map = $this->getMap(); |
|
26 | + $map->setClusterer(true, 60, 14); |
|
27 | + $html = $map->forTemplate(); |
|
28 | + $this->assertContains('data-clusterergridsize=60', $html); |
|
29 | + $this->assertContains('data-clusterermaxzoom=14', $html); |
|
30 | + $this->assertContains('data-useclusterer=1', $html); |
|
31 | + |
|
32 | + $map = $this->getMap(); |
|
33 | + $map->setClusterer(false); |
|
34 | + $html = $map->forTemplate(); |
|
35 | + $this->assertContains('data-useclusterer=false', $html); |
|
36 | + $this->assertContains('data-clusterergridsize=50', $html); |
|
37 | + $this->assertContains('data-clusterermaxzoom=17', $html); |
|
38 | + } |
|
39 | + |
|
40 | + /* |
|
41 | 41 | Toggle as to whether or not to include a style= attribute with width/height |
42 | 42 | */ |
43 | - public function testSetShowInlineMapDivStyle() { |
|
44 | - $map = $this->getMap(); |
|
45 | - $map->setShowInlineMapDivStyle(true); |
|
46 | - $html = $map->forTemplate(); |
|
47 | - $expected = 'style="width:100%; height: 400px;"'; |
|
48 | - $this->assertContains($expected, $html); |
|
49 | - |
|
50 | - $map->setShowInlineMapDivStyle(false); |
|
51 | - $html = $map->forTemplate(); |
|
52 | - $this->assertNotContains($expected, $html); |
|
53 | - } |
|
54 | - |
|
55 | - public function testSetAdditionalCSSClasses() { |
|
56 | - $map = $this->getMap(); |
|
57 | - $map->setAdditionalCSSClasses('bigMap shadowMap'); |
|
58 | - $html = $map->forTemplate(); |
|
59 | - $expected = 'class="bigMap shadowMap mappable"'; |
|
60 | - $this->assertContains($expected, $html); |
|
61 | - $map->setAdditionalCSSClasses('bigMap shadowMap'); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - public function testSetMapStyle() { |
|
66 | - $style = <<<STYLE |
|
43 | + public function testSetShowInlineMapDivStyle() { |
|
44 | + $map = $this->getMap(); |
|
45 | + $map->setShowInlineMapDivStyle(true); |
|
46 | + $html = $map->forTemplate(); |
|
47 | + $expected = 'style="width:100%; height: 400px;"'; |
|
48 | + $this->assertContains($expected, $html); |
|
49 | + |
|
50 | + $map->setShowInlineMapDivStyle(false); |
|
51 | + $html = $map->forTemplate(); |
|
52 | + $this->assertNotContains($expected, $html); |
|
53 | + } |
|
54 | + |
|
55 | + public function testSetAdditionalCSSClasses() { |
|
56 | + $map = $this->getMap(); |
|
57 | + $map->setAdditionalCSSClasses('bigMap shadowMap'); |
|
58 | + $html = $map->forTemplate(); |
|
59 | + $expected = 'class="bigMap shadowMap mappable"'; |
|
60 | + $this->assertContains($expected, $html); |
|
61 | + $map->setAdditionalCSSClasses('bigMap shadowMap'); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + public function testSetMapStyle() { |
|
66 | + $style = <<<STYLE |
|
67 | 67 | [{ |
68 | 68 | "featureType": "landscape", |
69 | 69 | "stylers": [{ |
@@ -77,10 +77,10 @@ discard block |
||
77 | 77 | }] |
78 | 78 | }] |
79 | 79 | STYLE; |
80 | - $map = $this->getMap(); |
|
81 | - $map->setMapStyle($style); |
|
82 | - $html = $map->forTemplate()->getValue(); |
|
83 | - $expected = <<<HTML |
|
80 | + $map = $this->getMap(); |
|
81 | + $map->setMapStyle($style); |
|
82 | + $html = $map->forTemplate()->getValue(); |
|
83 | + $expected = <<<HTML |
|
84 | 84 | |
85 | 85 | |
86 | 86 | <div id="google_map_1" data-google-map-lang="en" style="width:100%; height: 400px;" |
@@ -116,372 +116,372 @@ discard block |
||
116 | 116 | </div> |
117 | 117 | |
118 | 118 | HTML; |
119 | - $this->assertEquals($expected, $html); |
|
120 | - $map->setMapStyle(null); |
|
121 | - } |
|
122 | - |
|
123 | - public function testSetDivId() { |
|
124 | - $map = $this->getMap(); |
|
125 | - $map->setDivId('mymapid'); |
|
126 | - $html = $map->forTemplate(); |
|
127 | - $expected = '<div id="mymapid" data-google-map-lang="en" style='; |
|
128 | - $this->assertContains($expected, $html); |
|
129 | - } |
|
130 | - |
|
131 | - public function testSetSize() { |
|
132 | - $map = $this->getMap(); |
|
133 | - $map->setSize('432px', '1234px'); |
|
134 | - $html = $map->forTemplate(); |
|
135 | - $this->assertContains('style="width:432px; height: 1234px;"', $html); |
|
136 | - } |
|
137 | - |
|
138 | - public function testSetLang() { |
|
139 | - Config::inst()->update('Mappable', 'language', 'fr'); |
|
140 | - $map = $this->getMap(); |
|
141 | - $html = $map->forTemplate(); |
|
142 | - $this->assertContains( |
|
143 | - '<div id="google_map_1" data-google-map-lang="fr" ', |
|
144 | - $html |
|
145 | - ); |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - public function testSetZoom() { |
|
150 | - $map = $this->getMap(); |
|
151 | - $map->setZoom(4); |
|
152 | - $html = $map->forTemplate(); |
|
153 | - $this->assertContains('data-zoom=4', $html); |
|
154 | - $map->setZoom(12); |
|
155 | - $html = $map->forTemplate(); |
|
156 | - $this->assertContains('data-zoom=12', $html); |
|
157 | - } |
|
158 | - |
|
159 | - public function testSetInfoWindowZoom() { |
|
160 | - $map = $this->getMap(); |
|
161 | - $map->setInfoWindowZoom(4); |
|
162 | - $html = $map->forTemplate(); |
|
163 | - $this->assertContains('data-infowindowzoom=4', $html); |
|
164 | - $map->setInfoWindowZoom(12); |
|
165 | - $html = $map->forTemplate(); |
|
166 | - $this->assertContains('data-infowindowzoom=12', $html); |
|
167 | - |
|
168 | - } |
|
169 | - |
|
170 | - public function testSetEnableWindowZoom() { |
|
171 | - $map = $this->getMap(); |
|
172 | - $map->setEnableWindowZoom(false); |
|
173 | - $html = $map->forTemplate(); |
|
174 | - $this->assertContains('data-enablewindowzoom=false', $html); |
|
175 | - $map->setEnableWindowZoom(true); |
|
176 | - $html = $map->forTemplate(); |
|
177 | - $this->assertContains('data-enablewindowzoom=1', $html); |
|
178 | - } |
|
179 | - |
|
180 | - public function testSetEnableAutomaticCenterZoom() { |
|
181 | - $map = $this->getMap(); |
|
182 | - $map->setEnableAutomaticCenterZoom(true); |
|
183 | - $html = $map->forTemplate(); |
|
184 | - $this->assertContains('data-enableautocentrezoom=1', $html); |
|
185 | - } |
|
186 | - |
|
187 | - public function testSetNoLocation() { |
|
188 | - $map = $this->getMap(); |
|
189 | - $html = $map->forTemplate(); |
|
190 | - $this->assertContains( |
|
191 | - 'data-centre=\'{"lat":48.856614,"lng":2.3522219}\'', |
|
192 | - $html |
|
193 | - ); |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * setCentre is mis-named, as the method expects text for a geocoder |
|
198 | - */ |
|
199 | - public function testSetCenter() { |
|
200 | - $map = $this->getMap(); |
|
201 | - $map->setCenter('Klong Tan, Bangkok, Thailand'); |
|
202 | - $html = $map->forTemplate(); |
|
203 | - |
|
204 | - //coordinates of Klong Tan in Bangkok |
|
205 | - $expected = 'data-centre=\'{"lat":13.7243075,"lng":100.5718086}'; |
|
206 | - $this->assertContains($expected, $html); |
|
207 | - $map->setCenter('Paris, France'); |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - public function testSetLatLongCenter() { |
|
212 | - $map = $this->getMap(); |
|
213 | - $llc = array('lat' => -23.714, 'lng' => 47.419); |
|
214 | - $map->setLatLongCenter($llc); |
|
215 | - $html = $map->forTemplate(); |
|
216 | - $expected = "data-centre='{\"lat\":-23.714,\"lng\":47.419}'"; |
|
217 | - $this->assertContains($expected, $html); |
|
218 | - |
|
219 | - // now test error conditions |
|
220 | - try { |
|
221 | - $map->setLatLongCenter('This is not a coordinate'); |
|
222 | - $this->fail('Should not be able to set coordinate as text'); |
|
223 | - } catch (InvalidArgumentException $e) { |
|
224 | - $message = $e->getMessage(); |
|
225 | - $this->assertEquals( |
|
226 | - 'Center must be an associative array containing lat,lng', |
|
227 | - $message |
|
228 | - ); |
|
229 | - } |
|
230 | - |
|
231 | - try { |
|
232 | - $badKeys = array('lat' => 47.2, 'wibble' => 76.10); |
|
233 | - $map->setLatLongCenter($badKeys); |
|
234 | - $this->fail('Should not be able to set coordinate as text'); |
|
235 | - } catch (InvalidArgumentException $e) { |
|
236 | - $message = $e->getMessage(); |
|
237 | - |
|
238 | - $this->assertEquals( |
|
239 | - 'Keys provided must be lat, lng', |
|
240 | - $message |
|
241 | - ); |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - public function testSetMapType() { |
|
249 | - $map = $this->getMap(); |
|
250 | - |
|
251 | - $mapTypes = array( |
|
252 | - 'road' => 'road', |
|
253 | - 'satellite' => 'satellite', |
|
254 | - 'hybrid' => 'hybrid', |
|
255 | - 'terrain' => 'terrain', |
|
256 | - 'google.maps.MapTypeId.ROADMAP' => 'road', |
|
257 | - 'google.maps.MapTypeId.SATELLITE' => 'satellite', |
|
258 | - 'google.maps.MapTypeId.G_HYBRID_MAP' => 'hybrid', |
|
259 | - 'google.maps.MapTypeId.G_PHYSICAL_MAP' => 'terrain', |
|
260 | - 'custom_layer' => 'custom_layer' |
|
261 | - ); |
|
262 | - |
|
263 | - foreach (array_keys($mapTypes) as $mapType) { |
|
264 | - $map->setMapType($mapType); |
|
265 | - $expected = "data-maptype='".$mapTypes[$mapType]."'"; |
|
266 | - $html = $map->forTemplate(); |
|
267 | - $this->assertContains($expected, $html); |
|
268 | - } |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - public function testSetAllowFullScreen() { |
|
273 | - $map = $this->getMap(); |
|
274 | - $map->setAllowFullScreen(false); |
|
275 | - $html = $map->forTemplate(); |
|
276 | - |
|
277 | - $this->assertContains("data-allowfullscreen='false'", $html); |
|
278 | - |
|
279 | - $map->setAllowFullScreen(true); |
|
280 | - $html = $map->forTemplate(); |
|
281 | - $this->assertContains("data-allowfullscreen='1'", $html); |
|
282 | - |
|
283 | - // deal with the null calse |
|
284 | - $map->setAllowFullScreen(null); |
|
285 | - $html = $map->forTemplate(); |
|
286 | - $expected = Config::inst()->get('Mappable', 'allow_full_screen'); |
|
287 | - $this->assertContains("data-allowfullscreen='{$expected}'", $html); |
|
288 | - } |
|
289 | - |
|
290 | - public function testMapWithMarkers() { |
|
291 | - $config = Config::inst(); |
|
292 | - |
|
293 | - $map = $this->getMapMultipleItems(); |
|
294 | - $html = $map->forTemplate(); |
|
295 | - $expected = 'data-mapmarkers=\'[{"latitude":23,"longitude":78,"html":"' |
|
296 | - . 'MEMBER: Fred Bloggs","category":"default","icon":false},{"latitude' |
|
297 | - . '":-12,"longitude":42.1,"html":"MEMBER: Kane Williamson","category"' |
|
298 | - . ':"default","icon":false}]\''; |
|
299 | - $this->assertContains($expected, $html); |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - public function testMapWithMarkersDifferentCategory() { |
|
304 | - $this->markTestSkipped('TODO'); |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - public function testSetDefaultHideMarker() { |
|
309 | - $map = $this->getMapMultipleItems(); |
|
310 | - $map->setDefaultHideMarker(false); |
|
311 | - $html = $map->forTemplate(); |
|
312 | - $this->assertContains( |
|
313 | - 'data-defaulthidemarker=false', |
|
314 | - $html |
|
315 | - ); |
|
316 | - |
|
317 | - $map = $this->getMapMultipleItems(); |
|
318 | - $map->setDefaultHideMarker(true); |
|
319 | - $html = $map->forTemplate(); |
|
320 | - $this->assertContains( |
|
321 | - 'data-defaulthidemarker=1', |
|
322 | - $html |
|
323 | - ); |
|
324 | - } |
|
325 | - |
|
326 | - public function testGetContent() { |
|
327 | - $map = $this->getMap(); |
|
328 | - $filepath = 'file://'.Director::baseFolder() |
|
329 | - . '/mappable/tests/kml/example.kml'; |
|
330 | - $content = $map->getContent($filepath); |
|
331 | - $textHash = hash('ripemd160', $content); |
|
332 | - $fileHash = hash_file('ripemd160', $filepath); |
|
333 | - $this->assertEquals($fileHash, $textHash); |
|
334 | - } |
|
335 | - |
|
336 | - public function testGeocoding() { |
|
337 | - $map = $this->getMap(); |
|
338 | - $location = $map->geocoding("Nonthaburi, Thailand"); |
|
339 | - $expected = array( |
|
340 | - 'lat' => 13.8621125, |
|
341 | - 'lon' => 100.5143528, |
|
342 | - 'geocoded' => true |
|
343 | - ); |
|
344 | - $this->assertEquals($expected, $location); |
|
345 | - } |
|
346 | - |
|
347 | - public function testGeocodingNoResultsFound() { |
|
348 | - $map = $this->getMap(); |
|
349 | - $location = $map->geocoding("aasdfsafsfdsfasdf"); |
|
350 | - $expected = array(); |
|
351 | - $this->assertEquals($expected, $location); |
|
352 | - } |
|
353 | - |
|
354 | - public function testAddMarkerByAddress() { |
|
355 | - //$address, $content = '', $category = '', $icon = '' |
|
356 | - $map = $this->getMap(); |
|
357 | - $map->addMarkerByAddress( |
|
358 | - 'Koh Kred, Nonthaburi, Thailand', |
|
359 | - 'Small island in the Chao Phraya river', |
|
360 | - 'testing', |
|
361 | - 'http://www.test.com/icon.png' |
|
362 | - ); |
|
363 | - $html = $map->forTemplate(); |
|
364 | - $expected = 'data-mapmarkers=\'[{"latitude":13.9114455,"longitude":100.4761897,"html":"Small island in the Chao Phraya river","category":"testing","icon":"http://www.test.com/icon.png"}]\''; |
|
365 | - $this->assertContains($expected, $html); |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - public function testAddArrayMarkerByCoords() { |
|
370 | - $map = $this->getMap(); |
|
371 | - |
|
372 | - $markerArray = array(); |
|
373 | - $marker1 = array(48.2, 27, 'Description marker 1', 'Marker Test', ''); |
|
374 | - $marker2 = array(-12.2, 47, 'Description marker 2', 'Marker Test', ''); |
|
375 | - |
|
376 | - array_push($markerArray, $marker1); |
|
377 | - array_push($markerArray, $marker2); |
|
378 | - |
|
379 | - $map->addArrayMarkerByCoords($markerArray); |
|
380 | - $html = $map->forTemplate(); |
|
381 | - $expected = 'data-mapmarkers=\'[{"latitude":48.2,"longitude":27,"html":"Description marker 1","category":"","icon":""},{"latitude":-12.2,"longitude":47,"html":"Description marker 2","category":"","icon":""}]\''; |
|
382 | - $this->assertContains($expected, $html); |
|
383 | - } |
|
384 | - |
|
385 | - public function testAddMarkerByCoords() { |
|
386 | - $map = $this->getMap(); |
|
387 | - $map->addMarkerByCoords( |
|
388 | - 13.91, |
|
389 | - 100.47, |
|
390 | - 'Description of marker', |
|
391 | - 'testing', |
|
392 | - 'http://www.test.com/icon.png' |
|
393 | - ); |
|
394 | - $html = $map->forTemplate(); |
|
395 | - $expected = |
|
396 | - 'data-mapmarkers=\'[{"latitude":13.91,"longitude":100.47,"html":"Description of marker","category":"testing","icon":"http://www.test.com/icon.png"}]'; |
|
397 | - |
|
398 | - $this->assertContains($expected, $html); |
|
399 | - } |
|
400 | - |
|
401 | - |
|
402 | - public function testAddMarkerAsObject() { |
|
403 | - $map = $this->getMap(); |
|
404 | - $member = new Member(); |
|
405 | - $member->FirstName = 'Test'; |
|
406 | - $member->Surname = 'User'; |
|
407 | - $member->Lat = 24.2; |
|
408 | - $member->Lon = -40; |
|
409 | - $member->write(); |
|
410 | - $params = array(); |
|
411 | - $map->addMarkerAsObject( |
|
412 | - $member, |
|
413 | - $params |
|
414 | - ); |
|
415 | - |
|
416 | - $html = $map->forTemplate(); |
|
417 | - $expected = 'data-mapmarkers=\'[{"latitude":24.2,"longitude":-40,"html":"MEMBER: Test User","category":"default","icon":false}]\''; |
|
418 | - $this->assertContains($expected, $html); |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - public function testAddMarkerThatIsMappableAsObject() { |
|
423 | - $map = $this->getMap(); |
|
424 | - $member = new MappableExampleClass(); |
|
425 | - //$member->write(); |
|
426 | - $params = array(); |
|
427 | - $map->addMarkerAsObject( |
|
428 | - $member, |
|
429 | - $params |
|
430 | - ); |
|
431 | - |
|
432 | - $html = $map->forTemplate(); |
|
433 | - $expected = 'data-mapmarkers=\'[{"latitude":13.4,"longitude":100.7,"html":"example content","category":"default","icon":null}]\''; |
|
434 | - $this->assertContains($expected, $html); |
|
435 | - } |
|
436 | - |
|
437 | - |
|
438 | - public function testConnectPoints() { |
|
439 | - $members = $this->getGeolocatedMembers(); |
|
440 | - $member1 = $members->pop(); |
|
441 | - $member2 = $members->pop(); |
|
442 | - $map = $this->getMap(); |
|
443 | - $map->connectPoints($member1, $member2); |
|
444 | - $html = $map->forTemplate(); |
|
445 | - $expected = 'data-lines=\'[{"lat1":-12,"lon1":42.1,"lat2":23,"lon2":78,"color":"#FF3300"}]\''; |
|
446 | - $this->assertContains($expected, $html); |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - public function testAddKML() { |
|
451 | - $map = $this->getMap(); |
|
452 | - $map->addKml('http://www.test.com/route1.kml'); |
|
453 | - $map->addKml('http://www.test.com/route2.kml'); |
|
454 | - $html = $map->forTemplate(); |
|
455 | - $expected = 'data-kmlfiles=\'["http://www.test.com/route1.kml","http://www.test.com/route2.kml"]\''; |
|
456 | - $this->assertContains($expected, $html); |
|
457 | - } |
|
458 | - |
|
459 | - |
|
460 | - public function testAddLine() { |
|
461 | - $map = $this->getMap(); |
|
462 | - $map->addLine( |
|
463 | - array(13, 101), |
|
464 | - array(13.2, 101.4), |
|
465 | - '#F32' |
|
466 | - ); |
|
467 | - |
|
468 | - $map->addLine( |
|
469 | - array(13.2, 101.4), |
|
470 | - array(14.2, 99.8) |
|
471 | - ); |
|
472 | - |
|
473 | - $html = $map->forTemplate(); |
|
474 | - $expected = 'data-lines=\'[{"lat1":13,"lon1":101,"lat2":13.2,"lon2":101.4,"color":"#F32"},{"lat1":13.2,"lon1":101.4,"lat2":14.2,"lon2":99.8,"color":"#FF3300"}]\''; |
|
475 | - $this->assertContains($expected, $html); |
|
476 | - } |
|
477 | - |
|
478 | - /** |
|
479 | - * This tests out a specific case of passing null for template values |
|
480 | - */ |
|
481 | - public function testProcessTemplate() { |
|
482 | - $map = $this->getMap(); |
|
483 | - $html = $map->processTemplateHTML('Map', null); |
|
484 | - $expected = <<<HTML |
|
119 | + $this->assertEquals($expected, $html); |
|
120 | + $map->setMapStyle(null); |
|
121 | + } |
|
122 | + |
|
123 | + public function testSetDivId() { |
|
124 | + $map = $this->getMap(); |
|
125 | + $map->setDivId('mymapid'); |
|
126 | + $html = $map->forTemplate(); |
|
127 | + $expected = '<div id="mymapid" data-google-map-lang="en" style='; |
|
128 | + $this->assertContains($expected, $html); |
|
129 | + } |
|
130 | + |
|
131 | + public function testSetSize() { |
|
132 | + $map = $this->getMap(); |
|
133 | + $map->setSize('432px', '1234px'); |
|
134 | + $html = $map->forTemplate(); |
|
135 | + $this->assertContains('style="width:432px; height: 1234px;"', $html); |
|
136 | + } |
|
137 | + |
|
138 | + public function testSetLang() { |
|
139 | + Config::inst()->update('Mappable', 'language', 'fr'); |
|
140 | + $map = $this->getMap(); |
|
141 | + $html = $map->forTemplate(); |
|
142 | + $this->assertContains( |
|
143 | + '<div id="google_map_1" data-google-map-lang="fr" ', |
|
144 | + $html |
|
145 | + ); |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + public function testSetZoom() { |
|
150 | + $map = $this->getMap(); |
|
151 | + $map->setZoom(4); |
|
152 | + $html = $map->forTemplate(); |
|
153 | + $this->assertContains('data-zoom=4', $html); |
|
154 | + $map->setZoom(12); |
|
155 | + $html = $map->forTemplate(); |
|
156 | + $this->assertContains('data-zoom=12', $html); |
|
157 | + } |
|
158 | + |
|
159 | + public function testSetInfoWindowZoom() { |
|
160 | + $map = $this->getMap(); |
|
161 | + $map->setInfoWindowZoom(4); |
|
162 | + $html = $map->forTemplate(); |
|
163 | + $this->assertContains('data-infowindowzoom=4', $html); |
|
164 | + $map->setInfoWindowZoom(12); |
|
165 | + $html = $map->forTemplate(); |
|
166 | + $this->assertContains('data-infowindowzoom=12', $html); |
|
167 | + |
|
168 | + } |
|
169 | + |
|
170 | + public function testSetEnableWindowZoom() { |
|
171 | + $map = $this->getMap(); |
|
172 | + $map->setEnableWindowZoom(false); |
|
173 | + $html = $map->forTemplate(); |
|
174 | + $this->assertContains('data-enablewindowzoom=false', $html); |
|
175 | + $map->setEnableWindowZoom(true); |
|
176 | + $html = $map->forTemplate(); |
|
177 | + $this->assertContains('data-enablewindowzoom=1', $html); |
|
178 | + } |
|
179 | + |
|
180 | + public function testSetEnableAutomaticCenterZoom() { |
|
181 | + $map = $this->getMap(); |
|
182 | + $map->setEnableAutomaticCenterZoom(true); |
|
183 | + $html = $map->forTemplate(); |
|
184 | + $this->assertContains('data-enableautocentrezoom=1', $html); |
|
185 | + } |
|
186 | + |
|
187 | + public function testSetNoLocation() { |
|
188 | + $map = $this->getMap(); |
|
189 | + $html = $map->forTemplate(); |
|
190 | + $this->assertContains( |
|
191 | + 'data-centre=\'{"lat":48.856614,"lng":2.3522219}\'', |
|
192 | + $html |
|
193 | + ); |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * setCentre is mis-named, as the method expects text for a geocoder |
|
198 | + */ |
|
199 | + public function testSetCenter() { |
|
200 | + $map = $this->getMap(); |
|
201 | + $map->setCenter('Klong Tan, Bangkok, Thailand'); |
|
202 | + $html = $map->forTemplate(); |
|
203 | + |
|
204 | + //coordinates of Klong Tan in Bangkok |
|
205 | + $expected = 'data-centre=\'{"lat":13.7243075,"lng":100.5718086}'; |
|
206 | + $this->assertContains($expected, $html); |
|
207 | + $map->setCenter('Paris, France'); |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + public function testSetLatLongCenter() { |
|
212 | + $map = $this->getMap(); |
|
213 | + $llc = array('lat' => -23.714, 'lng' => 47.419); |
|
214 | + $map->setLatLongCenter($llc); |
|
215 | + $html = $map->forTemplate(); |
|
216 | + $expected = "data-centre='{\"lat\":-23.714,\"lng\":47.419}'"; |
|
217 | + $this->assertContains($expected, $html); |
|
218 | + |
|
219 | + // now test error conditions |
|
220 | + try { |
|
221 | + $map->setLatLongCenter('This is not a coordinate'); |
|
222 | + $this->fail('Should not be able to set coordinate as text'); |
|
223 | + } catch (InvalidArgumentException $e) { |
|
224 | + $message = $e->getMessage(); |
|
225 | + $this->assertEquals( |
|
226 | + 'Center must be an associative array containing lat,lng', |
|
227 | + $message |
|
228 | + ); |
|
229 | + } |
|
230 | + |
|
231 | + try { |
|
232 | + $badKeys = array('lat' => 47.2, 'wibble' => 76.10); |
|
233 | + $map->setLatLongCenter($badKeys); |
|
234 | + $this->fail('Should not be able to set coordinate as text'); |
|
235 | + } catch (InvalidArgumentException $e) { |
|
236 | + $message = $e->getMessage(); |
|
237 | + |
|
238 | + $this->assertEquals( |
|
239 | + 'Keys provided must be lat, lng', |
|
240 | + $message |
|
241 | + ); |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + public function testSetMapType() { |
|
249 | + $map = $this->getMap(); |
|
250 | + |
|
251 | + $mapTypes = array( |
|
252 | + 'road' => 'road', |
|
253 | + 'satellite' => 'satellite', |
|
254 | + 'hybrid' => 'hybrid', |
|
255 | + 'terrain' => 'terrain', |
|
256 | + 'google.maps.MapTypeId.ROADMAP' => 'road', |
|
257 | + 'google.maps.MapTypeId.SATELLITE' => 'satellite', |
|
258 | + 'google.maps.MapTypeId.G_HYBRID_MAP' => 'hybrid', |
|
259 | + 'google.maps.MapTypeId.G_PHYSICAL_MAP' => 'terrain', |
|
260 | + 'custom_layer' => 'custom_layer' |
|
261 | + ); |
|
262 | + |
|
263 | + foreach (array_keys($mapTypes) as $mapType) { |
|
264 | + $map->setMapType($mapType); |
|
265 | + $expected = "data-maptype='".$mapTypes[$mapType]."'"; |
|
266 | + $html = $map->forTemplate(); |
|
267 | + $this->assertContains($expected, $html); |
|
268 | + } |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + public function testSetAllowFullScreen() { |
|
273 | + $map = $this->getMap(); |
|
274 | + $map->setAllowFullScreen(false); |
|
275 | + $html = $map->forTemplate(); |
|
276 | + |
|
277 | + $this->assertContains("data-allowfullscreen='false'", $html); |
|
278 | + |
|
279 | + $map->setAllowFullScreen(true); |
|
280 | + $html = $map->forTemplate(); |
|
281 | + $this->assertContains("data-allowfullscreen='1'", $html); |
|
282 | + |
|
283 | + // deal with the null calse |
|
284 | + $map->setAllowFullScreen(null); |
|
285 | + $html = $map->forTemplate(); |
|
286 | + $expected = Config::inst()->get('Mappable', 'allow_full_screen'); |
|
287 | + $this->assertContains("data-allowfullscreen='{$expected}'", $html); |
|
288 | + } |
|
289 | + |
|
290 | + public function testMapWithMarkers() { |
|
291 | + $config = Config::inst(); |
|
292 | + |
|
293 | + $map = $this->getMapMultipleItems(); |
|
294 | + $html = $map->forTemplate(); |
|
295 | + $expected = 'data-mapmarkers=\'[{"latitude":23,"longitude":78,"html":"' |
|
296 | + . 'MEMBER: Fred Bloggs","category":"default","icon":false},{"latitude' |
|
297 | + . '":-12,"longitude":42.1,"html":"MEMBER: Kane Williamson","category"' |
|
298 | + . ':"default","icon":false}]\''; |
|
299 | + $this->assertContains($expected, $html); |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + public function testMapWithMarkersDifferentCategory() { |
|
304 | + $this->markTestSkipped('TODO'); |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + public function testSetDefaultHideMarker() { |
|
309 | + $map = $this->getMapMultipleItems(); |
|
310 | + $map->setDefaultHideMarker(false); |
|
311 | + $html = $map->forTemplate(); |
|
312 | + $this->assertContains( |
|
313 | + 'data-defaulthidemarker=false', |
|
314 | + $html |
|
315 | + ); |
|
316 | + |
|
317 | + $map = $this->getMapMultipleItems(); |
|
318 | + $map->setDefaultHideMarker(true); |
|
319 | + $html = $map->forTemplate(); |
|
320 | + $this->assertContains( |
|
321 | + 'data-defaulthidemarker=1', |
|
322 | + $html |
|
323 | + ); |
|
324 | + } |
|
325 | + |
|
326 | + public function testGetContent() { |
|
327 | + $map = $this->getMap(); |
|
328 | + $filepath = 'file://'.Director::baseFolder() |
|
329 | + . '/mappable/tests/kml/example.kml'; |
|
330 | + $content = $map->getContent($filepath); |
|
331 | + $textHash = hash('ripemd160', $content); |
|
332 | + $fileHash = hash_file('ripemd160', $filepath); |
|
333 | + $this->assertEquals($fileHash, $textHash); |
|
334 | + } |
|
335 | + |
|
336 | + public function testGeocoding() { |
|
337 | + $map = $this->getMap(); |
|
338 | + $location = $map->geocoding("Nonthaburi, Thailand"); |
|
339 | + $expected = array( |
|
340 | + 'lat' => 13.8621125, |
|
341 | + 'lon' => 100.5143528, |
|
342 | + 'geocoded' => true |
|
343 | + ); |
|
344 | + $this->assertEquals($expected, $location); |
|
345 | + } |
|
346 | + |
|
347 | + public function testGeocodingNoResultsFound() { |
|
348 | + $map = $this->getMap(); |
|
349 | + $location = $map->geocoding("aasdfsafsfdsfasdf"); |
|
350 | + $expected = array(); |
|
351 | + $this->assertEquals($expected, $location); |
|
352 | + } |
|
353 | + |
|
354 | + public function testAddMarkerByAddress() { |
|
355 | + //$address, $content = '', $category = '', $icon = '' |
|
356 | + $map = $this->getMap(); |
|
357 | + $map->addMarkerByAddress( |
|
358 | + 'Koh Kred, Nonthaburi, Thailand', |
|
359 | + 'Small island in the Chao Phraya river', |
|
360 | + 'testing', |
|
361 | + 'http://www.test.com/icon.png' |
|
362 | + ); |
|
363 | + $html = $map->forTemplate(); |
|
364 | + $expected = 'data-mapmarkers=\'[{"latitude":13.9114455,"longitude":100.4761897,"html":"Small island in the Chao Phraya river","category":"testing","icon":"http://www.test.com/icon.png"}]\''; |
|
365 | + $this->assertContains($expected, $html); |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + public function testAddArrayMarkerByCoords() { |
|
370 | + $map = $this->getMap(); |
|
371 | + |
|
372 | + $markerArray = array(); |
|
373 | + $marker1 = array(48.2, 27, 'Description marker 1', 'Marker Test', ''); |
|
374 | + $marker2 = array(-12.2, 47, 'Description marker 2', 'Marker Test', ''); |
|
375 | + |
|
376 | + array_push($markerArray, $marker1); |
|
377 | + array_push($markerArray, $marker2); |
|
378 | + |
|
379 | + $map->addArrayMarkerByCoords($markerArray); |
|
380 | + $html = $map->forTemplate(); |
|
381 | + $expected = 'data-mapmarkers=\'[{"latitude":48.2,"longitude":27,"html":"Description marker 1","category":"","icon":""},{"latitude":-12.2,"longitude":47,"html":"Description marker 2","category":"","icon":""}]\''; |
|
382 | + $this->assertContains($expected, $html); |
|
383 | + } |
|
384 | + |
|
385 | + public function testAddMarkerByCoords() { |
|
386 | + $map = $this->getMap(); |
|
387 | + $map->addMarkerByCoords( |
|
388 | + 13.91, |
|
389 | + 100.47, |
|
390 | + 'Description of marker', |
|
391 | + 'testing', |
|
392 | + 'http://www.test.com/icon.png' |
|
393 | + ); |
|
394 | + $html = $map->forTemplate(); |
|
395 | + $expected = |
|
396 | + 'data-mapmarkers=\'[{"latitude":13.91,"longitude":100.47,"html":"Description of marker","category":"testing","icon":"http://www.test.com/icon.png"}]'; |
|
397 | + |
|
398 | + $this->assertContains($expected, $html); |
|
399 | + } |
|
400 | + |
|
401 | + |
|
402 | + public function testAddMarkerAsObject() { |
|
403 | + $map = $this->getMap(); |
|
404 | + $member = new Member(); |
|
405 | + $member->FirstName = 'Test'; |
|
406 | + $member->Surname = 'User'; |
|
407 | + $member->Lat = 24.2; |
|
408 | + $member->Lon = -40; |
|
409 | + $member->write(); |
|
410 | + $params = array(); |
|
411 | + $map->addMarkerAsObject( |
|
412 | + $member, |
|
413 | + $params |
|
414 | + ); |
|
415 | + |
|
416 | + $html = $map->forTemplate(); |
|
417 | + $expected = 'data-mapmarkers=\'[{"latitude":24.2,"longitude":-40,"html":"MEMBER: Test User","category":"default","icon":false}]\''; |
|
418 | + $this->assertContains($expected, $html); |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + public function testAddMarkerThatIsMappableAsObject() { |
|
423 | + $map = $this->getMap(); |
|
424 | + $member = new MappableExampleClass(); |
|
425 | + //$member->write(); |
|
426 | + $params = array(); |
|
427 | + $map->addMarkerAsObject( |
|
428 | + $member, |
|
429 | + $params |
|
430 | + ); |
|
431 | + |
|
432 | + $html = $map->forTemplate(); |
|
433 | + $expected = 'data-mapmarkers=\'[{"latitude":13.4,"longitude":100.7,"html":"example content","category":"default","icon":null}]\''; |
|
434 | + $this->assertContains($expected, $html); |
|
435 | + } |
|
436 | + |
|
437 | + |
|
438 | + public function testConnectPoints() { |
|
439 | + $members = $this->getGeolocatedMembers(); |
|
440 | + $member1 = $members->pop(); |
|
441 | + $member2 = $members->pop(); |
|
442 | + $map = $this->getMap(); |
|
443 | + $map->connectPoints($member1, $member2); |
|
444 | + $html = $map->forTemplate(); |
|
445 | + $expected = 'data-lines=\'[{"lat1":-12,"lon1":42.1,"lat2":23,"lon2":78,"color":"#FF3300"}]\''; |
|
446 | + $this->assertContains($expected, $html); |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + public function testAddKML() { |
|
451 | + $map = $this->getMap(); |
|
452 | + $map->addKml('http://www.test.com/route1.kml'); |
|
453 | + $map->addKml('http://www.test.com/route2.kml'); |
|
454 | + $html = $map->forTemplate(); |
|
455 | + $expected = 'data-kmlfiles=\'["http://www.test.com/route1.kml","http://www.test.com/route2.kml"]\''; |
|
456 | + $this->assertContains($expected, $html); |
|
457 | + } |
|
458 | + |
|
459 | + |
|
460 | + public function testAddLine() { |
|
461 | + $map = $this->getMap(); |
|
462 | + $map->addLine( |
|
463 | + array(13, 101), |
|
464 | + array(13.2, 101.4), |
|
465 | + '#F32' |
|
466 | + ); |
|
467 | + |
|
468 | + $map->addLine( |
|
469 | + array(13.2, 101.4), |
|
470 | + array(14.2, 99.8) |
|
471 | + ); |
|
472 | + |
|
473 | + $html = $map->forTemplate(); |
|
474 | + $expected = 'data-lines=\'[{"lat1":13,"lon1":101,"lat2":13.2,"lon2":101.4,"color":"#F32"},{"lat1":13.2,"lon1":101.4,"lat2":14.2,"lon2":99.8,"color":"#FF3300"}]\''; |
|
475 | + $this->assertContains($expected, $html); |
|
476 | + } |
|
477 | + |
|
478 | + /** |
|
479 | + * This tests out a specific case of passing null for template values |
|
480 | + */ |
|
481 | + public function testProcessTemplate() { |
|
482 | + $map = $this->getMap(); |
|
483 | + $html = $map->processTemplateHTML('Map', null); |
|
484 | + $expected = <<<HTML |
|
485 | 485 | |
486 | 486 | |
487 | 487 | <div id="" |
@@ -505,42 +505,42 @@ discard block |
||
505 | 505 | </div> |
506 | 506 | |
507 | 507 | HTML; |
508 | - $this->assertEquals($expected, $html->getValue()); |
|
509 | - } |
|
510 | - |
|
511 | - private function getMap() { |
|
512 | - $instance = new Member(); |
|
513 | - return $instance->getRenderableMap(); |
|
514 | - } |
|
515 | - |
|
516 | - private function getMapMultipleItems() { |
|
517 | - $members = $this->getGeolocatedMembers(); |
|
518 | - return $members->getRenderableMap(); |
|
519 | - } |
|
520 | - |
|
521 | - private function getGeolocatedMembers() { |
|
522 | - $members = new ArrayList(); |
|
523 | - |
|
524 | - $member1 = new Member(); |
|
525 | - $member1->Lat = 23; |
|
526 | - $member1->Lon = 78; |
|
527 | - $member1->MapPinEdited = true; |
|
528 | - $member1->FirstName = 'Fred'; |
|
529 | - $member1->Surname = 'Bloggs'; |
|
530 | - $member1->write(); |
|
531 | - $members->push($member1); |
|
532 | - |
|
533 | - $member2 = new Member(); |
|
534 | - $member2->Lat = -12; |
|
535 | - $member2->Lon = 42.1; |
|
536 | - $member2->MapPinEdited = true; |
|
537 | - $member2->FirstName = 'Kane'; |
|
538 | - $member2->Surname = 'Williamson'; |
|
539 | - $member2->write(); |
|
540 | - $members->push($member2); |
|
541 | - |
|
542 | - return $members; |
|
543 | - } |
|
508 | + $this->assertEquals($expected, $html->getValue()); |
|
509 | + } |
|
510 | + |
|
511 | + private function getMap() { |
|
512 | + $instance = new Member(); |
|
513 | + return $instance->getRenderableMap(); |
|
514 | + } |
|
515 | + |
|
516 | + private function getMapMultipleItems() { |
|
517 | + $members = $this->getGeolocatedMembers(); |
|
518 | + return $members->getRenderableMap(); |
|
519 | + } |
|
520 | + |
|
521 | + private function getGeolocatedMembers() { |
|
522 | + $members = new ArrayList(); |
|
523 | + |
|
524 | + $member1 = new Member(); |
|
525 | + $member1->Lat = 23; |
|
526 | + $member1->Lon = 78; |
|
527 | + $member1->MapPinEdited = true; |
|
528 | + $member1->FirstName = 'Fred'; |
|
529 | + $member1->Surname = 'Bloggs'; |
|
530 | + $member1->write(); |
|
531 | + $members->push($member1); |
|
532 | + |
|
533 | + $member2 = new Member(); |
|
534 | + $member2->Lat = -12; |
|
535 | + $member2->Lon = 42.1; |
|
536 | + $member2->MapPinEdited = true; |
|
537 | + $member2->FirstName = 'Kane'; |
|
538 | + $member2->Surname = 'Williamson'; |
|
539 | + $member2->write(); |
|
540 | + $members->push($member2); |
|
541 | + |
|
542 | + return $members; |
|
543 | + } |
|
544 | 544 | |
545 | 545 | } |
546 | 546 | |
@@ -549,19 +549,19 @@ discard block |
||
549 | 549 | // basic implementation of Mappable interface for some of the tests |
550 | 550 | class MappableExampleClass extends ViewableData implements TestOnly, Mappable { |
551 | 551 | |
552 | - public function getMappableLatitude() { |
|
553 | - return 13.4; |
|
554 | - } |
|
552 | + public function getMappableLatitude() { |
|
553 | + return 13.4; |
|
554 | + } |
|
555 | 555 | |
556 | - public function getMappableLongitude() { |
|
557 | - return 100.7; |
|
558 | - } |
|
556 | + public function getMappableLongitude() { |
|
557 | + return 100.7; |
|
558 | + } |
|
559 | 559 | |
560 | - public function getMappableMapPin() { |
|
561 | - return null; |
|
562 | - } |
|
560 | + public function getMappableMapPin() { |
|
561 | + return null; |
|
562 | + } |
|
563 | 563 | |
564 | - public function getMappableMapContent() { |
|
565 | - return 'example content'; |
|
566 | - } |
|
564 | + public function getMappableMapContent() { |
|
565 | + return 'example content'; |
|
566 | + } |
|
567 | 567 | } |