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

GeoJsonContent   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 40
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A fillParserOutput() 0 10 3
A getMapHtml() 0 19 1
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
}