summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Maps/src/Presentation/WikitextParsers/PolygonParser.php
blob: 1bf14a7fc6d4501c669229c6b6fff7ca91758979 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php

namespace Maps\Presentation\WikitextParsers;

use Maps\Elements\Line;
use Maps\Elements\Polygon;

/**
 * ValueParser that parses the string representation of a polygon.
 *
 * @since 3.0
 *
 * @licence GNU GPL v2+
 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 */
class PolygonParser extends LineParser {

	protected function constructShapeFromLatLongValues( array $locations ) {
		return new Polygon( $locations );
	}

	protected function handleCommonParams( array &$params, Line &$line ) {
		parent::handleCommonParams( $params, $line );
		$this->handlePolygonParams( $params, $line );
	}

	protected function handlePolygonParams( array &$params, Polygon &$polygon ) {
		if ( $fillColor = array_shift( $params ) ) {
			$polygon->setFillColor( $fillColor );
		}

		if ( $fillOpacity = array_shift( $params ) ) {
			$polygon->setFillOpacity( $fillOpacity );
		}

		if ( $showOnlyOnHover = array_shift( $params ) ) {
			$polygon->setOnlyVisibleOnHover( strtolower( trim( $showOnlyOnHover ) ) === 'on' );
		}
	}

}