Completed
Push — mapview ( 59d78b )
by Jeroen De
03:31
created

GeoJsonContent::getMapHtml()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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