/** * Checks the render method */ public function testRender() { $mapTest = new Map(); $polygonTest = new Polygon(); $polygonTest->setCoordinates(array(new Coordinate(1.1, 2.1, true), new Coordinate(3.1, 4.2, true), new Coordinate(7.4, 12.6, true))); $this->assertEquals(self::$polygonHelper->render($polygonTest, $mapTest), 'var ' . $polygonTest->getJavascriptVariable() . ' = new google.maps.Polygon({"map":' . $mapTest->getJavascriptVariable() . ',"paths":[new google.maps.LatLng(1.1, 2.1, true),new google.maps.LatLng(3.1, 4.2, true),new google.maps.LatLng(7.4, 12.6, true)]});' . PHP_EOL); $polygonTest->setOptions(array('option1' => 'value1', 'option2' => 'value2')); $this->assertEquals(self::$polygonHelper->render($polygonTest, $mapTest), 'var ' . $polygonTest->getJavascriptVariable() . ' = new google.maps.Polygon({"map":' . $mapTest->getJavascriptVariable() . ',"paths":[new google.maps.LatLng(1.1, 2.1, true),new google.maps.LatLng(3.1, 4.2, true),new google.maps.LatLng(7.4, 12.6, true)],"option1":"value1","option2":"value2"});' . PHP_EOL); }
/** * Renders the polygon * * @param Ivory\GoogleMapBundle\Model\Overlays\Polygon $polygon * @param Ivory\GoogleMapBundle\Model\Map $map * @return string HTML output */ public function render(Polygon $polygon, Map $map) { $polygonOptions = $polygon->getOptions(); $polygonCoordinates = array(); foreach ($polygon->getCoordinates() as $coordinate) { $polygonCoordinates[] = $this->coordinateHelper->render($coordinate); } $polygonJSONOptions = sprintf('{"map":%s,"paths":%s', $map->getJavascriptVariable(), '[' . implode(',', $polygonCoordinates) . ']'); if (!empty($polygonOptions)) { $polygonJSONOptions .= ',' . substr(json_encode($polygonOptions), 1); } else { $polygonJSONOptions .= '}'; } return sprintf('var %s = new google.maps.Polygon(%s);' . PHP_EOL, $polygon->getJavascriptVariable(), $polygonJSONOptions); }
/** * Checks the render polygons method */ public function testRenderPolygons() { $mapTest = new Model\Map(); $polygonTest = new Overlays\Polygon(); $polygonTest->setCoordinates(array(new Base\Coordinate(1.1, 2.1, true), new Base\Coordinate(3.1, 4.1, true))); $mapTest->addPolygon($polygonTest); $this->assertEquals(self::$mapHelper->renderPolygons($mapTest), 'var ' . $polygonTest->getJavascriptVariable() . ' = new google.maps.Polygon({"map":' . $mapTest->getJavascriptVariable() . ',"paths":[new google.maps.LatLng(1.1, 2.1, true),new google.maps.LatLng(3.1, 4.1, true)]});' . PHP_EOL); }
/** * Create a polygon */ public function __construct() { parent::__construct(); }