1 | <?php |
||
14 | class GoogleMapsService implements MappingService { |
||
15 | |||
16 | /** |
||
17 | * Maps user input map types to the Google Maps names for the map types. |
||
18 | */ |
||
19 | private const MAP_TYPES = [ |
||
20 | 'normal' => 'ROADMAP', |
||
21 | 'roadmap' => 'ROADMAP', |
||
22 | 'satellite' => 'SATELLITE', |
||
23 | 'hybrid' => 'HYBRID', |
||
24 | 'terrain' => 'TERRAIN', |
||
25 | 'physical' => 'TERRAIN', |
||
26 | 'earth' => 'earth' |
||
27 | ]; |
||
28 | |||
29 | private const TYPE_CONTROL_STYLES = [ |
||
30 | 'default' => 'DEFAULT', |
||
31 | 'horizontal' => 'HORIZONTAL_BAR', |
||
32 | 'dropdown' => 'DROPDOWN_MENU' |
||
33 | ]; |
||
34 | |||
35 | private $addedDependencies = []; |
||
36 | |||
37 | 24 | public function getName(): string { |
|
38 | 24 | return 'googlemaps3'; |
|
39 | } |
||
40 | |||
41 | 24 | public function getAliases(): array { |
|
42 | 24 | return [ 'googlemaps', 'google' ]; |
|
43 | } |
||
44 | |||
45 | public function hasAlias( string $alias ): bool { |
||
46 | return in_array( $alias, [ 'googlemaps', 'google' ] ); |
||
47 | } |
||
48 | |||
49 | 8 | public function getParameterInfo(): array { |
|
50 | 8 | global $egMapsGMaps3Type, $egMapsGMaps3Types, $egMapsGMaps3Controls, $egMapsGMaps3Layers; |
|
51 | 8 | global $egMapsGMaps3DefTypeStyle, $egMapsGMaps3DefZoomStyle, $egMapsGMaps3AutoInfoWindows; |
|
52 | 8 | global $egMapsResizableByDefault; |
|
53 | |||
54 | 8 | $params = MapsFunctions::getCommonParameters(); |
|
55 | |||
56 | 8 | $params['visitedicon'] = [ |
|
57 | 'default' => '', |
||
58 | 'message' => 'maps-displaymap-par-visitedicon', |
||
59 | ]; |
||
60 | |||
61 | 8 | $params['wmsoverlay'] = [ |
|
62 | 'type' => 'wmsoverlay', |
||
63 | 'default' => false, |
||
64 | 'delimiter' => ' ', |
||
65 | 'message' => 'maps-displaymap-par-wmsoverlay', |
||
66 | ]; |
||
67 | |||
68 | 8 | $params['zoom'] = [ |
|
69 | 8 | 'type' => 'integer', |
|
70 | 'range' => [ 0, 20 ], |
||
71 | 8 | 'default' => $GLOBALS['egMapsGMaps3Zoom'], |
|
72 | 8 | 'message' => 'maps-par-zoom', |
|
73 | ]; |
||
74 | |||
75 | 8 | $params['type'] = [ |
|
76 | 8 | 'default' => $egMapsGMaps3Type, |
|
77 | 8 | 'values' => self::getTypeNames(), |
|
78 | 8 | 'message' => 'maps-googlemaps3-par-type', |
|
79 | 'post-format' => function ( $value ) { |
||
80 | 8 | return GoogleMapsService::MAP_TYPES[strtolower( $value )]; |
|
81 | 8 | }, |
|
82 | ]; |
||
83 | |||
84 | 8 | $params['types'] = [ |
|
85 | 8 | 'dependencies' => 'type', |
|
86 | 8 | 'default' => $egMapsGMaps3Types, |
|
87 | 8 | 'values' => self::getTypeNames(), |
|
88 | 8 | 'message' => 'maps-googlemaps3-par-types', |
|
89 | 'islist' => true, |
||
90 | 'post-format' => function ( array $value ) { |
||
91 | 8 | foreach ( $value as &$part ) { |
|
92 | 8 | $part = self::MAP_TYPES[strtolower( $part )]; |
|
93 | } |
||
94 | |||
95 | 8 | return $value; |
|
96 | 8 | }, |
|
97 | ]; |
||
98 | |||
99 | 8 | $params['layers'] = [ |
|
100 | 8 | 'default' => $egMapsGMaps3Layers, |
|
101 | 'values' => [ |
||
102 | 'traffic', |
||
103 | 'bicycling', |
||
104 | 'transit' |
||
105 | ], |
||
106 | 8 | 'message' => 'maps-googlemaps3-par-layers', |
|
107 | 'islist' => true, |
||
108 | ]; |
||
109 | |||
110 | 8 | $params['controls'] = [ |
|
111 | 8 | 'default' => $egMapsGMaps3Controls, |
|
112 | 'values' => [ |
||
113 | 'pan', |
||
114 | 'zoom', |
||
115 | 'type', |
||
116 | 'scale', |
||
117 | 'streetview', |
||
118 | 'rotate' |
||
119 | ], |
||
120 | 8 | 'message' => 'maps-googlemaps3-par-controls', |
|
121 | 'islist' => true, |
||
122 | 'post-format' => function ( $value ) { |
||
123 | 8 | return array_map( 'strtolower', $value ); |
|
124 | 8 | }, |
|
125 | ]; |
||
126 | |||
127 | 8 | $params['zoomstyle'] = [ |
|
128 | 8 | 'default' => $egMapsGMaps3DefZoomStyle, |
|
129 | 'values' => [ 'default', 'small', 'large' ], |
||
130 | 8 | 'message' => 'maps-googlemaps3-par-zoomstyle', |
|
131 | 8 | 'post-format' => 'strtoupper', |
|
132 | ]; |
||
133 | |||
134 | 8 | $params['typestyle'] = [ |
|
135 | 8 | 'default' => $egMapsGMaps3DefTypeStyle, |
|
136 | 8 | 'values' => array_keys( self::TYPE_CONTROL_STYLES ), |
|
137 | 8 | 'message' => 'maps-googlemaps3-par-typestyle', |
|
138 | 'post-format' => function ( $value ) { |
||
139 | 8 | return self::TYPE_CONTROL_STYLES[strtolower( $value )]; |
|
140 | 8 | }, |
|
141 | ]; |
||
142 | |||
143 | 8 | $params['autoinfowindows'] = [ |
|
144 | 8 | 'type' => 'boolean', |
|
145 | 8 | 'default' => $egMapsGMaps3AutoInfoWindows, |
|
146 | 8 | 'message' => 'maps-googlemaps3-par-autoinfowindows', |
|
147 | ]; |
||
148 | |||
149 | 8 | $params['resizable'] = [ |
|
150 | 8 | 'type' => 'boolean', |
|
151 | 8 | 'default' => $egMapsResizableByDefault, |
|
152 | 8 | 'message' => 'maps-par-resizable', |
|
153 | ]; |
||
154 | |||
155 | 8 | $params['kmlrezoom'] = [ |
|
156 | 8 | 'type' => 'boolean', |
|
157 | 8 | 'default' => $GLOBALS['egMapsRezoomForKML'], |
|
158 | 8 | 'message' => 'maps-googlemaps3-par-kmlrezoom', |
|
159 | ]; |
||
160 | |||
161 | 8 | $params['poi'] = [ |
|
162 | 8 | 'type' => 'boolean', |
|
163 | 8 | 'default' => $GLOBALS['egMapsShowPOI'], |
|
164 | 8 | 'message' => 'maps-googlemaps3-par-poi', |
|
165 | ]; |
||
166 | |||
167 | 8 | $params['cluster'] = [ |
|
168 | 'aliases' => [ 'markercluster' ], |
||
169 | 'type' => 'boolean', |
||
170 | 'default' => false, |
||
171 | 'message' => 'maps-par-markercluster', |
||
172 | ]; |
||
173 | |||
174 | 8 | $params['clustergridsize'] = [ |
|
175 | 'type' => 'integer', |
||
176 | 'default' => 60, |
||
177 | 'message' => 'maps-googlemaps3-par-clustergridsize', |
||
178 | ]; |
||
179 | |||
180 | 8 | $params['clustermaxzoom'] = [ |
|
181 | 'type' => 'integer', |
||
182 | 'default' => 20, |
||
183 | 'message' => 'maps-par-clustermaxzoom', |
||
184 | ]; |
||
185 | |||
186 | 8 | $params['clusterzoomonclick'] = [ |
|
187 | 'type' => 'boolean', |
||
188 | 'default' => true, |
||
189 | 'message' => 'maps-par-clusterzoomonclick', |
||
190 | ]; |
||
191 | |||
192 | 8 | $params['clusteraveragecenter'] = [ |
|
193 | 'type' => 'boolean', |
||
194 | 'default' => true, |
||
195 | 'message' => 'maps-googlemaps3-par-clusteraveragecenter', |
||
196 | ]; |
||
197 | |||
198 | 8 | $params['clusterminsize'] = [ |
|
199 | 'type' => 'integer', |
||
200 | 'default' => 2, |
||
201 | 'message' => 'maps-googlemaps3-par-clusterminsize', |
||
202 | ]; |
||
203 | |||
204 | 8 | $params['imageoverlays'] = [ |
|
205 | 'type' => 'mapsimageoverlay', |
||
206 | 'default' => [], |
||
207 | 'delimiter' => ';', |
||
208 | 'islist' => true, |
||
209 | 'message' => 'maps-googlemaps3-par-imageoverlays', |
||
210 | ]; |
||
211 | |||
212 | 8 | $params['kml'] = [ |
|
213 | 8 | 'default' => [], |
|
214 | 8 | 'message' => 'maps-par-kml', |
|
215 | 'islist' => true, |
||
216 | 'post-format' => function( array $kmlFileNames ) { |
||
217 | 8 | return array_values( |
|
218 | 8 | array_filter( |
|
219 | 8 | array_map( |
|
220 | function( string $fileName ) { |
||
221 | 1 | return wfExpandUrl( MapsFunctions::getFileUrl( $fileName ) ); |
|
|
|||
222 | 8 | }, |
|
223 | $kmlFileNames |
||
224 | ), |
||
225 | function( string $fileName ) { |
||
226 | 1 | return $fileName !== ''; |
|
227 | 8 | } |
|
228 | ) |
||
229 | ); |
||
230 | 8 | } |
|
231 | ]; |
||
232 | |||
233 | 8 | $params['gkml'] = [ |
|
234 | 'default' => [], |
||
235 | 'message' => 'maps-googlemaps3-par-gkml', |
||
236 | 'islist' => true, |
||
237 | ]; |
||
238 | |||
239 | 8 | $params['searchmarkers'] = [ |
|
240 | 'default' => '', |
||
241 | 'message' => 'maps-par-searchmarkers', |
||
242 | // new CriterionSearchMarkers() FIXME |
||
243 | ]; |
||
244 | |||
245 | 8 | $params['fullscreen'] = [ |
|
246 | 'aliases' => [ 'enablefullscreen' ], |
||
247 | 'type' => 'boolean', |
||
248 | 'default' => false, |
||
249 | 'message' => 'maps-par-enable-fullscreen', |
||
250 | ]; |
||
251 | |||
252 | 8 | $params['scrollwheelzoom'] = [ |
|
253 | 'aliases' => [ 'scrollzoom' ], |
||
254 | 'type' => 'boolean', |
||
255 | 'default' => false, |
||
256 | 'message' => 'maps-par-scrollwheelzoom', |
||
257 | ]; |
||
258 | |||
259 | 8 | return $params; |
|
260 | } |
||
261 | |||
262 | /** |
||
263 | * Returns the names of all supported map types. |
||
264 | */ |
||
265 | 8 | private function getTypeNames(): array { |
|
266 | 8 | return array_keys( self::MAP_TYPES ); |
|
267 | } |
||
268 | |||
269 | 8 | public function newMapId(): string { |
|
270 | 8 | static $mapsOnThisPage = 0; |
|
271 | |||
272 | 8 | $mapsOnThisPage++; |
|
273 | |||
274 | 8 | return 'map_google3_' . $mapsOnThisPage; |
|
275 | } |
||
276 | |||
277 | 8 | public function getResourceModules( array $params ): array { |
|
278 | 8 | return [ 'ext.maps.googlemaps3', 'ext.maps.googlemaps3ajax' ]; |
|
279 | } |
||
280 | |||
281 | 8 | public static function getApiScript( $langCode, array $urlArgs = [] ) { |
|
282 | 8 | $urlArgs = array_merge( |
|
283 | [ |
||
284 | 8 | 'language' => self::getMappedLanguageCode( $langCode ) |
|
285 | ], |
||
286 | $urlArgs |
||
287 | ); |
||
288 | 8 | if ( $GLOBALS['egMapsGMaps3ApiKey'] !== '' ) { |
|
289 | $urlArgs['key'] = $GLOBALS['egMapsGMaps3ApiKey']; |
||
290 | } |
||
291 | 8 | if ( $GLOBALS['egMapsGMaps3ApiVersion'] !== '' ) { |
|
292 | $urlArgs['v'] = $GLOBALS['egMapsGMaps3ApiVersion']; |
||
293 | } |
||
294 | |||
295 | 8 | return Html::linkedScript( '//maps.googleapis.com/maps/api/js?' . wfArrayToCgi( $urlArgs ) ); |
|
296 | } |
||
297 | |||
298 | /** |
||
299 | * Maps language codes to Google Maps API v3 compatible values. |
||
300 | */ |
||
301 | 8 | private static function getMappedLanguageCode( string $code ): string { |
|
314 | |||
315 | 8 | public function getDependencyHtml( array $params ): string { |
|
316 | 8 | $dependencies = []; |
|
317 | |||
318 | // Only add dependencies that have not yet been added. |
||
319 | 8 | foreach ( $this->getDependencies() as $dependency ) { |
|
320 | 8 | if ( !in_array( $dependency, $this->addedDependencies ) ) { |
|
321 | 8 | $dependencies[] = $dependency; |
|
329 | |||
330 | 8 | private function getDependencies(): array { |
|
338 | |||
339 | 8 | public function processingResultToMapParams( ProcessingResult $processingResult ): array { |
|
356 | |||
357 | |||
358 | 1 | private function getParameterWithValue( ProcessedParam $param, $value ) { |
|
367 | |||
368 | 8 | public function processedParamsToMapParams( array $params ): array { |
|
371 | |||
372 | } |
||
373 |
This method has been deprecated.