Example #1
0
 /**
  * Sets the marker shape.
  *
  * Available prototypes:
  *  - function setShape(Ivory\GoogleMap\Overlays\MarkerShape $shape = null)
  *  - function setShape(string $type, array $coordinates)
  *
  * @throws \Ivory\GoogleMap\Exception\OverlayException If the shape is not valid.
  */
 public function setShape()
 {
     $args = func_get_args();
     if (isset($args[0]) && $args[0] instanceof MarkerShape) {
         if (!$args[0]->hasCoordinates()) {
             throw OverlayException::invalidMarkerShapeCoordinates();
         }
         $this->shape = $args[0];
     } elseif (isset($args[0]) && is_string($args[0]) && (isset($args[1]) && is_array($args[1]))) {
         if ($this->shape === null) {
             $this->shape = new MarkerShape();
         }
         $this->shape->setType($args[0]);
         $this->shape->setCoordinates($args[1]);
     } elseif (!isset($args[0])) {
         $this->shape = null;
     } else {
         throw OverlayException::invalidMarkerShape();
     }
 }
 /**
  * @expectedException \Ivory\GoogleMap\Exception\OverlayException
  * @expectedExceptionMessage The x & y coordinates of a poly marker shape must be numeric values.
  */
 public function testAddPolyCoordinateWithInvalidValue()
 {
     $this->markerShape->setType('poly');
     $this->markerShape->addPolyCoordinate(true, false);
 }
 public function testRenderWithRectangleType()
 {
     $markerShape = new MarkerShape('rect', array(-1, -1, 1, 1));
     $markerShape->setJavascriptVariable('markerShape');
     $this->assertSame('markerShape = new google.maps.MarkerShape({"type":"rect","coords":[-1,-1,1,1]});' . PHP_EOL, $this->markerShapeHelper->render($markerShape));
 }
 /**
  * Renders a marker shape.
  *
  * @param \Ivory\GoogleMap\Overlays\MarkerShape $markerShape The marker shape.
  *
  * @return string The JS output.
  */
 public function render(MarkerShape $markerShape)
 {
     return sprintf('%s = new google.maps.MarkerShape(%s);' . PHP_EOL, $markerShape->getJavascriptVariable(), json_encode(array('type' => $markerShape->getType(), 'coords' => $markerShape->getCoordinates())));
 }