public function testIfAddPointsWorksAsExpected() { $polygon = new Polygon(); $this->assertEquals(array(), $polygon->getPoints()); $point1 = new Coordinate(10, 10); $polygon->addPoint($point1); $this->assertEquals(array($point1), $polygon->getPoints()); $point2 = new Coordinate(10, 20); $polygon->addPoint($point2); $this->assertEquals(array($point1, $point2), $polygon->getPoints()); }
/** * @param \Location\Polygon $polygon * * @return string */ public function format(Polygon $polygon) { $points = array(); foreach ($polygon->getPoints() as $point) { $points[] = array($point->getLng(), $point->getLat()); } return json_encode(array('type' => 'Polygon', 'coordinates' => $points)); }
/** * @param \Location\Polygon $polygon * * @return string */ public function format(Polygon $polygon) { $points = []; foreach ($polygon->getPoints() as $point) { $points[] = [$point->getLng(), $point->getLat()]; } return json_encode(['type' => 'Polygon', 'coordinates' => $points]); }