public function testCoordinateWithLatitudeAndLongitude() { $latitude = 1; $longitude = 2; $this->polygon->addCoordinate($latitude, $longitude, true); $coordinates = $this->polygon->getCoordinates(); $this->assertArrayHasKey(0, $coordinates); $this->assertSame($latitude, $coordinates[0]->getLatitude()); $this->assertSame($longitude, $coordinates[0]->getLongitude()); $this->assertTrue($coordinates[0]->isNoWrap()); }
/** * Renders a polygon. * * @param \Ivory\GoogleMap\Overlays\Polygon $polygon The polygon. * @param \Ivory\GoogleMapl\Map $map The map. * * @return string Ths JS output. */ public function render(Polygon $polygon, Map $map) { $this->jsonBuilder->reset()->setValue('[map]', $map->getJavascriptVariable(), false)->setValue('[paths]', array()); foreach ($polygon->getCoordinates() as $index => $coordinate) { $this->jsonBuilder->setValue(sprintf('[paths][%d]', $index), $coordinate->getJavascriptVariable(), false); } $this->jsonBuilder->setValues($polygon->getOptions()); return sprintf('%s = new google.maps.Polygon(%s);' . PHP_EOL, $polygon->getJavascriptVariable(), $this->jsonBuilder->build()); }
public function testRenderWithOptions() { $map = $this->getMock('Ivory\\GoogleMap\\Map'); $map->expects($this->once())->method('getJavascriptVariable')->will($this->returnValue('map')); $polygon = new Polygon(); $polygon->setJavascriptVariable('polygon'); $polygon->addCoordinate(1.1, 2.1); $polygon->addCoordinate(3.1, 4.2); $polygon->addCoordinate(7.4, 12.6); foreach ($polygon->getCoordinates() as $index => $coordinate) { $coordinate->setJavascriptVariable('coordinate' . $index); } $polygon->setOptions(array('option1' => 'value1', 'option2' => 'value2')); $expected = 'polygon = new google.maps.Polygon({' . '"map":map,' . '"paths":[' . 'coordinate0,' . 'coordinate1,' . 'coordinate2' . '],' . '"option1":"value1",' . '"option2":"value2"' . '});' . PHP_EOL; $this->assertSame($expected, $this->polygonHelper->render($polygon, $map)); }
public function testRenderJsContainerCoordinates() { $map = new Map(); $map->setJavascriptVariable('map'); $map->getCenter()->setJavascriptVariable('map_center'); $map->addRectangle($rectangle = new Rectangle()); $rectangle->getBound()->getSouthWest()->setJavascriptVariable('rectangle_south_west'); $rectangle->getBound()->getNorthEast()->setJavascriptVariable('rectangle_north_east'); $map->addCircle($circle = new Circle()); $circle->getCenter()->setJavascriptVariable('circle_center'); $map->addInfoWindow($infoWindow = new InfoWindow()); $infoWindow->setPosition(1, 2, true); $infoWindow->getPosition()->setJavascriptVariable('info_window_position'); $map->addMarker($marker = new Marker()); $marker->getPosition()->setJavascriptVariable('marker_position'); $map->addPolygon($polygon = new Polygon()); $polygon->addCoordinate(1.1, 2.1); $polygon->addCoordinate(3.1, 4.2); foreach ($polygon->getCoordinates() as $index => $polygonCoordinate) { $polygonCoordinate->setJavascriptVariable('polygon_coordinate_' . $index); } $map->addPolyline($polyline = new Polyline()); $polyline->addCoordinate(1.2, 2.6); $polyline->addCoordinate(3.2, 4.9); foreach ($polyline->getCoordinates() as $index => $polyline) { $polyline->setJavascriptVariable('polyline_coordinate_' . $index); } $expected = <<<EOF map_container.coordinates.map_center = map_center = new google.maps.LatLng(0, 0, true); map_container.coordinates.rectangle_south_west = rectangle_south_west = new google.maps.LatLng(-1, -1, true); map_container.coordinates.rectangle_north_east = rectangle_north_east = new google.maps.LatLng(1, 1, true); map_container.coordinates.circle_center = circle_center = new google.maps.LatLng(0, 0, true); map_container.coordinates.info_window_position = info_window_position = new google.maps.LatLng(1, 2, true); map_container.coordinates.marker_position = marker_position = new google.maps.LatLng(0, 0, true); map_container.coordinates.polygon_coordinate_0 = polygon_coordinate_0 = new google.maps.LatLng(1.1, 2.1, true); map_container.coordinates.polygon_coordinate_1 = polygon_coordinate_1 = new google.maps.LatLng(3.1, 4.2, true); map_container.coordinates.polyline_coordinate_0 = polyline_coordinate_0 = new google.maps.LatLng(1.2, 2.6, true); map_container.coordinates.polyline_coordinate_1 = polyline_coordinate_1 = new google.maps.LatLng(3.2, 4.9, true); EOF; $this->assertSame($expected, $this->mapHelper->renderJsContainerCoordinates($map)); }