Polygon objects are similar to polyline objects in that they consist of a series of coordinates in an ordered sequence. However, instead of being open-ended, polygons are designed to define regions within a closed loop.
First of all, if you want to render a polygon, you will need to build one. So let's go:
use Ivory\GoogleMap\Overlay\Polygon;
$polygon = new Polygon();
The polygon constructor does not require anything but It accepts additional parameters such as coordinates (default empty) and options (default empty):
use Ivory\GoogleMap\Base\Coordinate;
use Ivory\GoogleMap\Overlay\Polygon;
$polygon = new Polygon(
[
new Coordinate(25.774, -80.190),
new Coordinate(18.466, -66.118),
new Coordinate(32.321, -64.757),
new Coordinate(25.774, -80.190),
],
['fillOpacity' => 0.5]
);
A variable is automatically generated when creating a polygon but if you want to update it, you can use:
$polygon->setVariable('polygon');
If you want to update the polygon coordinates, you can use:
$polygon->setCoordinates([]);
The polygon options allows you to configure additional polygon aspects. See the list of available options in the official documentation. Then, to configure them, you can use:
$polygon->setOption('fillOpacity', 0.5);
After building your polygon, you need to add it to a map with:
$map->getOverlayManager()->addPolygon($polygon);