/** * Add a ground overlay to the map. * * @param \Ivory\GoogleMapBundle\Model\Overlays\GroupOverlay $groundOverlay The ground overlay to add. */ public function addGroundOverlay(GroundOverlay $groundOverlay) { $this->groundOverlays[] = $groundOverlay; if ($this->autoZoom) { $this->bound->extend($groundOverlay); } }
/** * Sets the autocomplete bound. * * Available prototypes: * - function setBound(Ivory\GoogleMap\Base\Bound $bound = null) * - function setBount(Ivory\GoogleMap\Base\Coordinate $southWest, Ivory\GoogleMap\Base\Coordinate $northEast) * - function setBound( * double $southWestLatitude, * double $southWestLongitude, * double $northEastLatitude, * double $northEastLongitude, * boolean southWestNoWrap = true, * boolean $northEastNoWrap = true * ) * * @throws \Ivory\GoogleMap\Exception\PlaceException If the bound is not valid (prototypes). */ public function setBound() { $args = func_get_args(); if (isset($args[0]) && $args[0] instanceof Bound) { $this->bound = $args[0]; } elseif (isset($args[0]) && $args[0] instanceof Coordinate && (isset($args[1]) && $args[1] instanceof Coordinate)) { if ($this->bound === null) { $this->bound = new Bound(); } $this->bound->setSouthWest($args[0]); $this->bound->setNorthEast($args[1]); } elseif (isset($args[0]) && is_numeric($args[0]) && (isset($args[1]) && is_numeric($args[1])) && (isset($args[2]) && is_numeric($args[2])) && (isset($args[3]) && is_numeric($args[3]))) { if ($this->bound === null) { $this->bound = new Bound(); } $this->bound->setSouthWest(new Coordinate($args[0], $args[1])); $this->bound->setNorthEast(new Coordinate($args[2], $args[3])); if (isset($args[4]) && is_bool($args[4])) { $this->bound->getSouthWest()->setNoWrap($args[4]); } if (isset($args[5]) && is_bool($args[5])) { $this->bound->getNorthEast()->setNoWrap($args[5]); } } elseif (!isset($args[0])) { $this->bound = null; } else { throw PlaceException::invalidAutocompleteBound(); } }
/** * Sets the ground overlay bound. * * Available prototypes: * - function setBound(Ivory\GoogleMap\Base\Bound $bound) * - function setBount(Ivory\GoogleMap\Base\Coordinate $southWest, Ivory\GoogleMap\Base\Coordinate $northEast) * - function setBound( * double $southWestLatitude, * double $southWestLongitude, * double $northEastLatitude, * double $northEastLongitude, * boolean southWestNoWrap = true, * boolean $northEastNoWrap = true * ) * * @throws \Ivory\GoogleMap\Exception\OverlayException If the ground overlay bound is not valid (prototypes). */ public function setBound() { $args = func_get_args(); if (isset($args[0]) && $args[0] instanceof Bound) { if ($args[0]->hasCoordinates()) { $this->bound = $args[0]; } else { throw OverlayException::invalidGroundOverlayBoundCoordinates(); } } elseif (isset($args[0]) && $args[0] instanceof Coordinate && (isset($args[1]) && $args[1] instanceof Coordinate)) { $this->bound->setSouthWest($args[0]); $this->bound->setNorthEast($args[1]); } elseif (isset($args[0]) && is_numeric($args[0]) && (isset($args[1]) && is_numeric($args[1])) && (isset($args[2]) && is_numeric($args[2])) && (isset($args[3]) && is_numeric($args[3]))) { $this->bound->setSouthWest(new Coordinate($args[0], $args[1])); $this->bound->setNorthEast(new Coordinate($args[2], $args[3])); if (isset($args[4]) && is_bool($args[4])) { $this->bound->getSouthWest()->setNoWrap($args[4]); } if (isset($args[5]) && is_bool($args[5])) { $this->bound->getNorthEast()->setNoWrap($args[5]); } } else { throw OverlayException::invalidGroundOverlayBound(); } }
public function testRenderWithOptions() { $map = $this->getMock('Ivory\\GoogleMap\\Map'); $map->expects($this->once())->method('getJavascriptVariable')->will($this->returnValue('map')); $bound = new Bound(); $bound->setJavascriptVariable('bound'); $bound->setSouthWest(-1.1, -2.1, true); $bound->setNorthEast(1.1, 2.1, true); $groundOverlay = new GroundOverlay('url', $bound); $groundOverlay->setJavascriptVariable('groundOverlay'); $groundOverlay->setOptions(array('option1' => 'value1', 'option2' => 'value2')); $expected = <<<EOF groundOverlay = new google.maps.GroundOverlay("url", bound, {"map":map,"option1":"value1","option2":"value2"}); EOF; $this->assertSame($expected, $this->groundOverlayHelper->render($groundOverlay, $map)); }
public function testRenderWithOptions() { $map = $this->getMock('Ivory\\GoogleMap\\Map'); $map->expects($this->once())->method('getJavascriptVariable')->will($this->returnValue('map')); $bound = new Bound(); $bound->setJavascriptVariable('rectangleBound'); $bound->setSouthWest(-1.1, -2.1); $bound->setNorthEast(1.1, 2.1); $rectangle = new Rectangle($bound); $rectangle->setJavascriptVariable('rectangle'); $rectangle->setOptions(array('option1' => 'value1', 'option2' => 'value2')); $expected = <<<EOF rectangle = new google.maps.Rectangle({"map":map,"bounds":rectangleBound,"option1":"value1","option2":"value2"}); EOF; $this->assertSame($expected, $this->rectangleHelper->render($rectangle, $map)); }
public function testCenter() { $this->bound->setSouthWest(-1, 0, false); $this->bound->setNorthEast(1, 2, false); $center = $this->bound->getCenter(); $this->assertSame(0, $center->getLatitude()); $this->assertSame(1, $center->getLongitude()); $this->assertTrue($center->isNoWrap()); }
public function testRenderExtends() { $bound = new Bound(); $bound->setJavascriptVariable('bound'); $circle = $this->getMock('Ivory\\GoogleMap\\Overlays\\Circle'); $circle->expects($this->once())->method('getJavascriptVariable')->will($this->returnValue('circle')); $groundOverlayBound = $this->getMock('Ivory\\GoogleMap\\Base\\Bound'); $groundOverlayBound->expects($this->once())->method('getJavascriptVariable')->will($this->returnValue('groundOverlayBound')); $groundOverlay = $this->getMock('Ivory\\GoogleMap\\Overlays\\GroundOverlay'); $groundOverlay->expects($this->once())->method('getBound')->will($this->returnValue($groundOverlayBound)); $infoWindow = $this->getMock('Ivory\\GoogleMap\\Overlays\\InfoWindow'); $infoWindow->expects($this->once())->method('getJavascriptVariable')->will($this->returnValue('infoWindow')); $marker = $this->getMock('Ivory\\GoogleMap\\Overlays\\Marker'); $marker->expects($this->once())->method('getJavascriptVariable')->will($this->returnValue('marker')); $polygon = $this->getMock('Ivory\\GoogleMap\\Overlays\\Polygon'); $polygon->expects($this->once())->method('getJavascriptVariable')->will($this->returnValue('polygon')); $polyline = $this->getMock('Ivory\\GoogleMap\\Overlays\\Polyline'); $polyline->expects($this->once())->method('getJavascriptVariable')->will($this->returnValue('polyline')); $rectangleBound = $this->getMock('Ivory\\GoogleMap\\Base\\Bound'); $rectangleBound->expects($this->once())->method('getJavascriptVariable')->will($this->returnValue('rectangleBound')); $rectangle = $this->getMock('Ivory\\GoogleMap\\Overlays\\Rectangle'); $rectangle->expects($this->once())->method('getBound')->will($this->returnValue($rectangleBound)); $bound->extend($circle); $bound->extend($groundOverlay); $bound->extend($infoWindow); $bound->extend($marker); $bound->extend($polygon); $bound->extend($polyline); $bound->extend($rectangle); $expected = <<<EOF bound.union(circle.getBounds()); bound.union(groundOverlayBound); bound.extend(infoWindow.getPosition()); bound.extend(marker.getPosition()); polygon.getPath().forEach(function(element){bound.extend(element)}); polyline.getPath().forEach(function(element){bound.extend(element)}); bound.union(rectangleBound); EOF; $this->assertSame($expected, $this->boundHelper->renderExtends($bound)); }
/** * Renders the bound's extend of a marker. * * @param \Ivory\GoogleMap\Base\Bound $bound The bound. * * @return string The JS output. */ public function renderExtends(Bound $bound) { $output = array(); foreach ($bound->getExtends() as $extend) { if ($extend instanceof Marker || $extend instanceof InfoWindow) { $output[] = sprintf('%s.extend(%s.getPosition());' . PHP_EOL, $bound->getJavascriptVariable(), $extend->getJavascriptVariable()); } elseif ($extend instanceof Polyline || $extend instanceof EncodedPolyline || $extend instanceof Polygon) { $output[] = sprintf('%s.getPath().forEach(function(element){%s.extend(element)});' . PHP_EOL, $extend->getJavascriptVariable(), $bound->getJavascriptVariable()); } elseif ($extend instanceof Rectangle || $extend instanceof GroundOverlay) { $output[] = sprintf('%s.union(%s);' . PHP_EOL, $bound->getJavascriptVariable(), $extend->getBound()->getJavascriptVariable()); } elseif ($extend instanceof Circle) { $output[] = sprintf('%s.union(%s.getBounds());' . PHP_EOL, $bound->getJavascriptVariable(), $extend->getJavascriptVariable()); } } return implode('', $output); }