1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
4
|
|
|
|
5
|
|
|
namespace Maps\Presentation; |
6
|
|
|
|
7
|
|
|
use Html; |
8
|
|
|
|
9
|
|
|
class GeoJsonPageOutput { |
10
|
|
|
|
11
|
|
|
private $json; |
12
|
|
|
|
13
|
|
|
public static function forNewPage(): self { |
14
|
|
|
return new self( null ); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public static function forExistingPage( string $mapJson ): self { |
18
|
|
|
return new self( $mapJson ); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
private function __construct( ?string $json ) { |
22
|
|
|
$this->json = $json; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function addToParserOutput( \ParserOutput $parserOutput ) { |
26
|
|
|
$parserOutput->setText( $this->getJavascript() . $this->getHtml() ); |
27
|
|
|
$parserOutput->addModules( $this->getResourceModules() ); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function addToOutputPage( \OutputPage $output ) { |
31
|
|
|
$output->addHTML( $this->getJavascript() . $this->getHtml() ); |
32
|
|
|
$output->addModules( $this->getResourceModules() ); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
private function getResourceModules(): array { |
36
|
|
|
return [ |
37
|
|
|
'ext.maps.leaflet.editor' |
38
|
|
|
]; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
private function getJavascript(): string { |
42
|
|
|
return Html::element( |
43
|
|
|
'script', |
44
|
|
|
[], |
45
|
|
|
$this->getJsonJs() |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
private function getJsonJs(): string { |
50
|
|
|
return 'var GeoJson =' |
51
|
|
|
. ( $this->json ?? 'null' ) |
52
|
|
|
. ';'; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
private function getHtml(): string { |
56
|
|
|
if ( $this->isExistingPage() ) { |
57
|
|
|
return $this->getMapHtml(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $this->getNewPageHtml(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
private function isExistingPage(): bool { |
64
|
|
|
return $this->json !== null; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
private function getMapHtml(): string { |
68
|
|
|
return $this->wrapHtmlInThumbDivs( |
69
|
|
|
Html::rawElement( |
70
|
|
|
'div', |
71
|
|
|
[ |
72
|
|
|
'id' => 'GeoJsonMap', |
73
|
|
|
'style' => 'width: 100%; height: 600px; background-color: #eeeeee; overflow: hidden;', |
74
|
|
|
'class' => 'maps-map maps-leaflet maps-geojson-editor' |
75
|
|
|
], |
76
|
|
|
Html::element( |
77
|
|
|
'div', |
78
|
|
|
[ |
79
|
|
|
'class' => 'maps-loading-message' |
80
|
|
|
], |
81
|
|
|
wfMessage( 'maps-loading-map' )->inContentLanguage()->text() |
82
|
|
|
) |
83
|
|
|
) |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
private function wrapHtmlInThumbDivs( string $html ): string { |
88
|
|
|
return Html::rawElement( |
89
|
|
|
'div', |
90
|
|
|
[ |
91
|
|
|
'class' => 'thumb' |
92
|
|
|
], |
93
|
|
|
Html::rawElement( |
94
|
|
|
'div', |
95
|
|
|
[ |
96
|
|
|
'class' => 'thumbinner' |
97
|
|
|
], |
98
|
|
|
$html |
99
|
|
|
) |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
private function getNewPageHtml(): string { |
104
|
|
|
return |
105
|
|
|
Html::element( |
106
|
|
|
'button', |
107
|
|
|
[ |
108
|
|
|
'id' => 'maps-geojson-new' |
109
|
|
|
], |
110
|
|
|
'Create this page' |
111
|
|
|
) |
112
|
|
|
. Html::rawElement( |
113
|
|
|
'div', |
114
|
|
|
[ |
115
|
|
|
'style' => 'display: none;', |
116
|
|
|
'id' => 'maps-geojson-map-wrapper' |
117
|
|
|
], |
118
|
|
|
$this->getMapHtml() |
119
|
|
|
); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
} |
123
|
|
|
|