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 | 8 | public function getParameterInfo(): array { |
|
46 | 8 | global $egMapsGMaps3Type, $egMapsGMaps3Types, $egMapsGMaps3Controls, $egMapsGMaps3Layers; |
|
47 | 8 | global $egMapsGMaps3DefTypeStyle, $egMapsGMaps3DefZoomStyle, $egMapsGMaps3AutoInfoWindows; |
|
48 | 8 | global $egMapsResizableByDefault; |
|
49 | |||
50 | 8 | $params = MapsFunctions::getCommonParameters(); |
|
51 | |||
52 | 8 | $params['visitedicon'] = [ |
|
53 | 'default' => '', |
||
54 | 'message' => 'maps-displaymap-par-visitedicon', |
||
55 | ]; |
||
56 | |||
57 | 8 | $params['wmsoverlay'] = [ |
|
58 | 'type' => 'wmsoverlay', |
||
59 | 'default' => false, |
||
60 | 'delimiter' => ' ', |
||
61 | 'message' => 'maps-displaymap-par-wmsoverlay', |
||
62 | ]; |
||
63 | |||
64 | 8 | $params['zoom'] = [ |
|
65 | 8 | 'type' => 'integer', |
|
66 | 'range' => [ 0, 20 ], |
||
67 | 8 | 'default' => $GLOBALS['egMapsGMaps3Zoom'], |
|
68 | 8 | 'message' => 'maps-par-zoom', |
|
69 | ]; |
||
70 | |||
71 | 8 | $params['type'] = [ |
|
72 | 8 | 'default' => $egMapsGMaps3Type, |
|
73 | 8 | 'values' => self::getTypeNames(), |
|
74 | 8 | 'message' => 'maps-googlemaps3-par-type', |
|
75 | 'post-format' => function ( $value ) { |
||
76 | 8 | return GoogleMapsService::MAP_TYPES[strtolower( $value )]; |
|
77 | 8 | }, |
|
78 | ]; |
||
79 | |||
80 | 8 | $params['types'] = [ |
|
81 | 8 | 'dependencies' => 'type', |
|
82 | 8 | 'default' => $egMapsGMaps3Types, |
|
83 | 8 | 'values' => self::getTypeNames(), |
|
84 | 8 | 'message' => 'maps-googlemaps3-par-types', |
|
85 | 'islist' => true, |
||
86 | 'post-format' => function ( array $value ) { |
||
87 | 8 | foreach ( $value as &$part ) { |
|
88 | 8 | $part = self::MAP_TYPES[strtolower( $part )]; |
|
89 | } |
||
90 | |||
91 | 8 | return $value; |
|
92 | 8 | }, |
|
93 | ]; |
||
94 | |||
95 | 8 | $params['layers'] = [ |
|
96 | 8 | 'default' => $egMapsGMaps3Layers, |
|
97 | 'values' => [ |
||
98 | 'traffic', |
||
99 | 'bicycling', |
||
100 | 'transit' |
||
101 | ], |
||
102 | 8 | 'message' => 'maps-googlemaps3-par-layers', |
|
103 | 'islist' => true, |
||
104 | ]; |
||
105 | |||
106 | 8 | $params['controls'] = [ |
|
107 | 8 | 'default' => $egMapsGMaps3Controls, |
|
108 | 'values' => [ |
||
109 | 'pan', |
||
110 | 'zoom', |
||
111 | 'type', |
||
112 | 'scale', |
||
113 | 'streetview', |
||
114 | 'rotate' |
||
115 | ], |
||
116 | 8 | 'message' => 'maps-googlemaps3-par-controls', |
|
117 | 'islist' => true, |
||
118 | 'post-format' => function ( $value ) { |
||
119 | 8 | return array_map( 'strtolower', $value ); |
|
120 | 8 | }, |
|
121 | ]; |
||
122 | |||
123 | 8 | $params['zoomstyle'] = [ |
|
124 | 8 | 'default' => $egMapsGMaps3DefZoomStyle, |
|
125 | 'values' => [ 'default', 'small', 'large' ], |
||
126 | 8 | 'message' => 'maps-googlemaps3-par-zoomstyle', |
|
127 | 8 | 'post-format' => 'strtoupper', |
|
128 | ]; |
||
129 | |||
130 | 8 | $params['typestyle'] = [ |
|
131 | 8 | 'default' => $egMapsGMaps3DefTypeStyle, |
|
132 | 8 | 'values' => array_keys( self::TYPE_CONTROL_STYLES ), |
|
133 | 8 | 'message' => 'maps-googlemaps3-par-typestyle', |
|
134 | 'post-format' => function ( $value ) { |
||
135 | 8 | return self::TYPE_CONTROL_STYLES[strtolower( $value )]; |
|
136 | 8 | }, |
|
137 | ]; |
||
138 | |||
139 | 8 | $params['autoinfowindows'] = [ |
|
140 | 8 | 'type' => 'boolean', |
|
141 | 8 | 'default' => $egMapsGMaps3AutoInfoWindows, |
|
142 | 8 | 'message' => 'maps-googlemaps3-par-autoinfowindows', |
|
143 | ]; |
||
144 | |||
145 | 8 | $params['resizable'] = [ |
|
146 | 8 | 'type' => 'boolean', |
|
147 | 8 | 'default' => $egMapsResizableByDefault, |
|
148 | 8 | 'message' => 'maps-par-resizable', |
|
149 | ]; |
||
150 | |||
151 | 8 | $params['kmlrezoom'] = [ |
|
152 | 8 | 'type' => 'boolean', |
|
153 | 8 | 'default' => $GLOBALS['egMapsRezoomForKML'], |
|
154 | 8 | 'message' => 'maps-googlemaps3-par-kmlrezoom', |
|
155 | ]; |
||
156 | |||
157 | 8 | $params['poi'] = [ |
|
158 | 8 | 'type' => 'boolean', |
|
159 | 8 | 'default' => $GLOBALS['egMapsShowPOI'], |
|
160 | 8 | 'message' => 'maps-googlemaps3-par-poi', |
|
161 | ]; |
||
162 | |||
163 | 8 | $params['cluster'] = [ |
|
164 | 'aliases' => [ 'markercluster' ], |
||
165 | 'type' => 'boolean', |
||
166 | 'default' => false, |
||
167 | 'message' => 'maps-par-markercluster', |
||
168 | ]; |
||
169 | |||
170 | 8 | $params['clustergridsize'] = [ |
|
171 | 'type' => 'integer', |
||
172 | 'default' => 60, |
||
173 | 'message' => 'maps-googlemaps3-par-clustergridsize', |
||
174 | ]; |
||
175 | |||
176 | 8 | $params['clustermaxzoom'] = [ |
|
177 | 'type' => 'integer', |
||
178 | 'default' => 20, |
||
179 | 'message' => 'maps-par-clustermaxzoom', |
||
180 | ]; |
||
181 | |||
182 | 8 | $params['clusterzoomonclick'] = [ |
|
183 | 'type' => 'boolean', |
||
184 | 'default' => true, |
||
185 | 'message' => 'maps-par-clusterzoomonclick', |
||
186 | ]; |
||
187 | |||
188 | 8 | $params['clusteraveragecenter'] = [ |
|
189 | 'type' => 'boolean', |
||
190 | 'default' => true, |
||
191 | 'message' => 'maps-googlemaps3-par-clusteraveragecenter', |
||
192 | ]; |
||
193 | |||
194 | 8 | $params['clusterminsize'] = [ |
|
195 | 'type' => 'integer', |
||
196 | 'default' => 2, |
||
197 | 'message' => 'maps-googlemaps3-par-clusterminsize', |
||
198 | ]; |
||
199 | |||
200 | 8 | $params['imageoverlays'] = [ |
|
201 | 'type' => 'mapsimageoverlay', |
||
202 | 'default' => [], |
||
203 | 'delimiter' => ';', |
||
204 | 'islist' => true, |
||
205 | 'message' => 'maps-googlemaps3-par-imageoverlays', |
||
206 | ]; |
||
207 | |||
208 | 8 | $params['kml'] = [ |
|
209 | 8 | 'default' => [], |
|
210 | 8 | 'message' => 'maps-par-kml', |
|
211 | 'islist' => true, |
||
212 | 'post-format' => function( array $kmlFileNames ) { |
||
213 | 8 | return array_values( |
|
214 | 8 | array_filter( |
|
215 | 8 | array_map( |
|
216 | function( string $fileName ) { |
||
217 | 1 | return wfExpandUrl( MapsFunctions::getFileUrl( $fileName ) ); |
|
|
|||
218 | 8 | }, |
|
219 | $kmlFileNames |
||
220 | ), |
||
221 | function( string $fileName ) { |
||
222 | 1 | return $fileName !== ''; |
|
223 | 8 | } |
|
224 | ) |
||
225 | ); |
||
226 | 8 | } |
|
227 | ]; |
||
228 | |||
229 | 8 | $params['gkml'] = [ |
|
230 | 'default' => [], |
||
231 | 'message' => 'maps-googlemaps3-par-gkml', |
||
232 | 'islist' => true, |
||
233 | ]; |
||
234 | |||
235 | 8 | $params['searchmarkers'] = [ |
|
236 | 'default' => '', |
||
237 | 'message' => 'maps-par-searchmarkers', |
||
238 | // new CriterionSearchMarkers() FIXME |
||
239 | ]; |
||
240 | |||
241 | 8 | $params['fullscreen'] = [ |
|
242 | 'aliases' => [ 'enablefullscreen' ], |
||
243 | 'type' => 'boolean', |
||
244 | 'default' => false, |
||
245 | 'message' => 'maps-par-enable-fullscreen', |
||
246 | ]; |
||
247 | |||
248 | 8 | $params['scrollwheelzoom'] = [ |
|
249 | 'aliases' => [ 'scrollzoom' ], |
||
250 | 'type' => 'boolean', |
||
251 | 'default' => false, |
||
252 | 'message' => 'maps-par-scrollwheelzoom', |
||
253 | ]; |
||
254 | |||
255 | 8 | return $params; |
|
256 | } |
||
257 | |||
258 | /** |
||
259 | * Returns the names of all supported map types. |
||
260 | */ |
||
261 | 8 | private function getTypeNames(): array { |
|
264 | |||
265 | 8 | public function newMapId(): string { |
|
266 | 8 | static $mapsOnThisPage = 0; |
|
267 | |||
272 | |||
273 | 8 | public function getResourceModules( array $params ): array { |
|
276 | |||
277 | 8 | public static function getApiScript( $langCode, array $urlArgs = [] ) { |
|
293 | |||
294 | /** |
||
295 | * Maps language codes to Google Maps API v3 compatible values. |
||
296 | */ |
||
297 | 8 | private static function getMappedLanguageCode( string $code ): string { |
|
310 | |||
311 | 8 | public function getDependencyHtml( array $params ): string { |
|
325 | |||
326 | 8 | private function getDependencies(): array { |
|
334 | |||
335 | 8 | public function processingResultToMapParams( ProcessingResult $processingResult ): array { |
|
352 | |||
353 | |||
354 | 1 | private function getParameterWithValue( ProcessedParam $param, $value ) { |
|
363 | |||
364 | 8 | public function processedParamsToMapParams( array $params ): array { |
|
367 | |||
368 | } |
||
369 |
This method has been deprecated.