コード例 #1
0
 /**
  * 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);
 }