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

GeoJsonContent   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 40
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\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
}