1 | <?php |
||
22 | class DisplayMapRenderer { |
||
23 | |||
24 | public $service; |
||
25 | |||
26 | /** |
||
27 | * @var LocationParser |
||
28 | */ |
||
29 | private $locationParser; |
||
30 | |||
31 | /** |
||
32 | * @var MediaWikiFileUrlFinder |
||
33 | */ |
||
34 | private $fileUrlFinder; |
||
35 | |||
36 | /** |
||
37 | * @var WikitextParser |
||
38 | */ |
||
39 | private $wikitextParser; |
||
40 | /** |
||
41 | * @var ElementJsonSerializer |
||
42 | */ |
||
43 | private $elementSerializer; |
||
44 | |||
45 | 20 | public function __construct( MappingService $service = null ) { |
|
48 | |||
49 | /** |
||
50 | * Handles the request from the parser hook by doing the work that's common for all |
||
51 | * mapping services, calling the specific methods and finally returning the resulting output. |
||
52 | * |
||
53 | * @param array $params |
||
54 | * @param Parser $parser |
||
55 | * |
||
56 | * @return string |
||
57 | */ |
||
58 | 20 | public final function renderMap( array $params, Parser $parser ) { |
|
85 | |||
86 | /** |
||
87 | * Converts the data in the coordinates parameter to JSON-ready objects. |
||
88 | * These get stored in the locations parameter, and the coordinates on gets deleted. |
||
89 | */ |
||
90 | 20 | private function handleMarkerData( array &$params ) { |
|
103 | |||
104 | 20 | private function getCenter( $coordinatesOrAddress ) { |
|
120 | |||
121 | 20 | private function getLocationJson( array $params ) { |
|
122 | 20 | $iconUrl = $this->fileUrlFinder->getUrlForFileName( $params['icon'] ); |
|
123 | 20 | $visitedIconUrl = $this->fileUrlFinder->getUrlForFileName( $params['visitedicon'] ); |
|
124 | |||
125 | 20 | $locationJsonObjects = []; |
|
126 | |||
127 | 20 | foreach ( $params['coordinates'] as $coordinatesOrAddress ) { |
|
128 | try { |
||
129 | 15 | $location = $this->locationParser->parse( $coordinatesOrAddress ); |
|
130 | } |
||
131 | 1 | catch ( \Exception $ex ) { |
|
132 | // TODO: somehow report this to the user |
||
133 | 1 | continue; |
|
134 | } |
||
135 | |||
136 | 14 | $locationJsonObjects[] = $this->getLocationJsonObject( |
|
137 | 14 | $location, |
|
138 | $params, |
||
139 | $iconUrl, |
||
140 | $visitedIconUrl |
||
141 | ); |
||
142 | } |
||
143 | |||
144 | 20 | return $locationJsonObjects; |
|
145 | } |
||
146 | |||
147 | 14 | private function getLocationJsonObject( Location $location, array $params, $iconUrl, $visitedIconUrl ) { |
|
161 | |||
162 | 20 | private function handleShapeData( array &$params ) { |
|
179 | |||
180 | /** |
||
181 | * Returns the HTML to display the map. |
||
182 | * |
||
183 | * @param array $params |
||
184 | * @param string $mapName |
||
185 | * |
||
186 | * @return string |
||
187 | */ |
||
188 | 20 | protected function getMapHTML( array $params, $mapName ) { |
|
204 | |||
205 | } |
||
206 |