diff options
author | Yaco <franco@reevo.org> | 2021-10-19 20:24:11 -0300 |
---|---|---|
committer | Yaco <franco@reevo.org> | 2021-10-19 20:24:11 -0300 |
commit | e3880a1c86acaa3bbd05786ad2f5c586e6511a58 (patch) | |
tree | ec77bfc5b69f259a159c95188797bd0dade92357 /www/wiki/extensions/Maps/src/Presentation/GeoJsonMapPageUi.php | |
parent | 20ca0685509f8010580d3b45036a64ab48616af1 (diff) |
updates Maps to 7.13.0
Diffstat (limited to 'www/wiki/extensions/Maps/src/Presentation/GeoJsonMapPageUi.php')
-rw-r--r-- | www/wiki/extensions/Maps/src/Presentation/GeoJsonMapPageUi.php | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/www/wiki/extensions/Maps/src/Presentation/GeoJsonMapPageUi.php b/www/wiki/extensions/Maps/src/Presentation/GeoJsonMapPageUi.php new file mode 100644 index 00000000..89440f1f --- /dev/null +++ b/www/wiki/extensions/Maps/src/Presentation/GeoJsonMapPageUi.php @@ -0,0 +1,83 @@ +<?php + +declare( strict_types = 1 ); + +namespace Maps\Presentation; + +use Html; + +class GeoJsonMapPageUi { + + private $json; + + public static function forExistingPage( string $mapJson ): self { + return new self( $mapJson ); + } + + private function __construct( ?string $json ) { + $this->json = $json; + } + + public function addToOutput( OutputFacade $output ) { + $leafletPath = $GLOBALS['wgScriptPath'] . '/extensions/Maps/resources/lib/leaflet'; + + $output->addHeadItem( + 'MapsGeoJsonHeadItem', + Html::linkedStyle( "$leafletPath/leaflet.css" ) . Html::linkedScript( "$leafletPath/leaflet.js" ) + ); + + $output->addHTML( $this->getJavascript() . $this->getHtml() ); + $output->addModules( 'ext.maps.geojson.page' ); + } + + private function getJavascript(): string { + return Html::element( + 'script', + [], + $this->getJsonJs() + ); + } + + private function getJsonJs(): string { + return 'var GeoJson =' + . $this->json + . ';'; + } + + private function getHtml(): string { + return $this->wrapHtmlInThumbDivs( + Html::rawElement( + 'div', + [ + 'id' => 'GeoJsonMap', + 'style' => 'width: 100%; height: 600px; background-color: #eeeeee; overflow: hidden;', + 'class' => 'maps-map maps-leaflet maps-geojson-editor' + ], + Html::element( + 'div', + [ + 'class' => 'maps-loading-message' + ], + wfMessage( 'maps-loading-map' )->inContentLanguage()->text() + ) + ) + ); + } + + private function wrapHtmlInThumbDivs( string $html ): string { + return Html::rawElement( + 'div', + [ + 'class' => 'thumb' + ], + Html::rawElement( + 'div', + [ + 'class' => 'thumbinner' + ], + $html + ) + ); + } + +} |