public function format(Polygon $polygon): string
    {
        if ($polygon->getNumberOfPoints() < 3) {
            throw new InvalidPolygonException('A polygon must consist of at least three points.');
        }

        $points = [];

        /** @var Coordinate $point */
        foreach ($polygon->getPoints() as $point) {
            $points[] = [$point->getLng(), $point->getLat()];
        }

        return json_encode(
            [
                'type' => 'Polygon',
                'coordinates' => [$points],
            ]
        );
    }
public function format(Polygon $polygon): string
    {
        if ($polygon->getNumberOfPoints() < 3) {
            throw new InvalidPolygonException('A polygon must consist of at least three points.');
        }

        $points = [];

        
        foreach ($polygon->getPoints() as $point) {
            $points[] = [$point->getLng(), $point->getLat()];
        }

        return json_encode(
            [
                'type' => 'Polygon',
                'coordinates' => [$points],
            ]
        );
    }
public function format ( Polygon $ polygon ) : string { if ( $ polygon -> getNumberOfPoints ( ) < 3 ) { throw new InvalidPolygonException ( 'A polygon must consist of at least three points.' ) ; } $ points = [ ] ; /** @var Coordinate $point */ foreach ( $ polygon -> getPoints ( ) as $ point ) { $ points [ ] = [ $ point -> getLng ( ) , $ point -> getLat ( ) ] ; } return json_encode ( [ 'type' => 'Polygon' , 'coordinates' => [ $ points ] , ] ) ; }
@param Polygon $polygon

@return string

@throws InvalidPolygonException
@param Polygon $polygon