Completed
Push — cln ( 863127 )
by Jeroen De
28:10 queued 22:04
created

GeoJsonContent::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Maps\MediaWiki\Content;
4
5
use Html;
6
use ParserOptions;
7
use ParserOutput;
8
use Title;
9
10
class GeoJsonContent extends \JsonContent {
11
12
	public const CONTENT_MODEL_ID = 'GeoJSON';
13
14
	public function __construct( string $text, string $modelId = self::CONTENT_MODEL_ID ) {
15
		parent::__construct( $text, $modelId );
16
	}
17
18
	protected function fillParserOutput( Title $title, $revId, ParserOptions $options,
19
		$generateHtml, ParserOutput &$output ) {
20
21
		if ( $generateHtml && $this->isValid() ) {
22
			$output->setText( $this->getMapHtml( $this->beautifyJSON() ) );
23
			$output->addModules( 'ext.maps.leaflet.editor' );
24
		} else {
25
			$output->setText( '' );
26
		}
27
	}
28
29
	private function getMapHtml( string $jsonString ): string {
30
		return
31
			Html::element(
32
				'div',
33
				[
34
					'id' => 'GeoJsonMap',
35
					'class' => 'GeoJsonMap',
36
				]
37
			)
38
			. '<style>'
39
			. '.GeoJsonMap {width: "100%"; height: 600px; display: "inline-block"}'
40
			. '</style>'
41
			.
42
			Html::element(
43
				'script',
44
				[],
45
				'var GeoJson =' . $jsonString . ';'
46
			);
47
	}
48
49
}