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