for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Maps\Elements;
use DataValues\Geo\Values\LatLongValue;
use InvalidArgumentException;
/**
* Class representing a collection of LatLongValue objects forming a line.
*
* @since 3.0
* @licence GNU GPL v2+
* @author Kim Eik < [email protected] >
* @author Jeroen De Dauw < [email protected] >
*/
class Line extends \MapsBaseStrokableElement {
* @var LatLongValue[]
protected $coordinates;
* @param LatLongValue[] $coordinates
* @throws InvalidArgumentException
public function __construct( array $coordinates = [] ) {
foreach ( $coordinates as $coordinate ) {
if ( !( $coordinate instanceof LatLongValue ) ) {
throw new InvalidArgumentException( 'Can only construct Line with LatLongValue objects' );
}
$this->coordinates = $coordinates;
parent::__construct();
* @return LatLongValue[]
public function getLineCoordinates() {
return $this->coordinates;
public function getJSONObject( string $defText = '', string $defTitle = '' ): array {
$parentArray = parent::getJSONObject( $defText, $defTitle );
$posArray = [];
foreach ( $this->coordinates as $mapLocation ) {
$posArray[] = [
'lat' => $mapLocation->getLatitude(),
'lon' => $mapLocation->getLongitude()
];
$posArray = [ 'pos' => $posArray ];
return array_merge( $parentArray, $posArray );