public function testRenderJsContainerWithComplexMap() { $map = new Map(); $map->setJavascriptVariable('map'); $map->setAutoZoom(true); $map->getBound()->setJavascriptVariable('map_bound'); $map->addCircle($circle = new Circle()); $circle->setJavascriptVariable('circle'); $circle->getCenter()->setJavascriptVariable('circle_center'); $map->addEncodedPolyline($encodedPolyline = new EncodedPolyline('foo')); $encodedPolyline->setJavascriptVariable('encoded_polyline'); $map->addGroundOverlay($groundOverlay = new GroundOverlay('url')); $groundOverlay->setJavascriptVariable('ground_overlay'); $groundOverlay->getBound()->setJavascriptVariable('ground_overlay_bound'); $groundOverlay->getBound()->setSouthWest(1, 2, true); $groundOverlay->getBound()->getSouthWest()->setJavascriptVariable('ground_overlay_bound_south_west'); $groundOverlay->getBound()->setNorthEast(3, 4, true); $groundOverlay->getBound()->getNorthEast()->setJavascriptVariable('ground_overlay_bound_north_east'); $map->addPolygon($polygon = new Polygon()); $polygon->setJavascriptVariable('polygon'); $map->addPolyline($polyline = new Polyline()); $polyline->setJavascriptVariable('polyline'); $map->addRectangle($rectangle = new Rectangle()); $rectangle->setJavascriptVariable('rectangle'); $rectangle->getBound()->setJavascriptVariable('rectangle_bound'); $rectangle->getBound()->setSouthWest(1, 2, true); $rectangle->getBound()->getSouthWest()->setJavascriptVariable('rectangle_bound_south_west'); $rectangle->getBound()->setNorthEast(3, 4, true); $rectangle->getBound()->getNorthEast()->setJavascriptVariable('rectangle_bound_north_east'); $map->addInfoWindow($mapInfoWindow = new InfoWindow()); $mapInfoWindow->setJavascriptVariable('map_info_window'); $mapInfoWindow->setPosition(1, 2, true); $mapInfoWindow->getPosition()->setJavascriptVariable('map_info_window_position'); $map->addMarker($marker = new Marker()); $marker->setJavascriptVariable('marker'); $marker->getPosition()->setJavascriptVariable('marker_position'); $marker->setInfoWindow($markerInfoWindow = new InfoWindow()); $markerInfoWindow->setJavascriptVariable('marker_info_window'); $marker->setIcon('url'); $marker->getIcon()->setJavascriptVariable('marker_icon'); $marker->setShadow('url'); $marker->getShadow()->setJavascriptVariable('marker_shadow'); $map->addKMLLayer($kmlLayer = new KMLLayer('url')); $kmlLayer->setJavascriptVariable('kml_layer'); $map->getEventManager()->addEvent($event = new Event('instance', 'click', 'function(){}', false)); $event->setJavascriptVariable('event'); $expected = <<<EOF map_container = {"map":null,"coordinates":{},"bounds":{},"points":{},"sizes":{},"circles":{},"encoded_polylines":{},"ground_overlays":{},"polygons":{},"polylines":{},"rectangles":{},"info_windows":{},"marker_images":{},"marker_shapes":{},"markers":{},"marker_cluster":null,"kml_layers":{},"event_manager":{"dom_events":{},"dom_events_once":{},"events":{},"events_once":{}},"closable_info_windows":{},"functions":{"to_array":function (object) { var array = []; for (var key in object) { array.push(object[key]); } return array; }}}; map_container.coordinates.ground_overlay_bound_south_west = ground_overlay_bound_south_west = new google.maps.LatLng(1, 2, true); map_container.coordinates.ground_overlay_bound_north_east = ground_overlay_bound_north_east = new google.maps.LatLng(3, 4, true); map_container.coordinates.rectangle_bound_south_west = rectangle_bound_south_west = new google.maps.LatLng(1, 2, true); map_container.coordinates.rectangle_bound_north_east = rectangle_bound_north_east = new google.maps.LatLng(3, 4, true); map_container.coordinates.circle_center = circle_center = new google.maps.LatLng(0, 0, true); map_container.coordinates.map_info_window_position = map_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.bounds.map_bound = map_bound = new google.maps.LatLngBounds(); map_container.bounds.ground_overlay_bound = ground_overlay_bound = new google.maps.LatLngBounds(ground_overlay_bound_south_west, ground_overlay_bound_north_east); map_container.bounds.rectangle_bound = rectangle_bound = new google.maps.LatLngBounds(rectangle_bound_south_west, rectangle_bound_north_east); map_container.map = map = new google.maps.Map(document.getElementById("map_canvas"), {"mapTypeId":google.maps.MapTypeId.ROADMAP}); map_container.circles.circle = circle = new google.maps.Circle({"map":map,"center":circle_center,"radius":1}); map_container.encoded_polylines.encoded_polyline = encoded_polyline = new google.maps.Polyline({"map":map,"path":google.maps.geometry.encoding.decodePath("foo")}); map_container.ground_overlays.ground_overlay = ground_overlay = new google.maps.GroundOverlay("url", ground_overlay_bound, {"map":map}); map_container.polygons.polygon = polygon = new google.maps.Polygon({"map":map,"paths":[]}); map_container.polylines.polyline = polyline = new google.maps.Polyline({"map":map,"path":[]}); map_container.rectangles.rectangle = rectangle = new google.maps.Rectangle({"map":map,"bounds":rectangle_bound}); map_container.info_windows.map_info_window = map_info_window = new google.maps.InfoWindow({"position":map_info_window_position,"content":"<p>Default content<\\/p>"}); map_container.info_windows.marker_info_window = marker_info_window = new google.maps.InfoWindow({"content":"<p>Default content<\\/p>"}); map_container.marker_images.marker_icon = marker_icon = new google.maps.MarkerImage("url", null, null, null, null); map_container.marker_images.marker_shadow = marker_shadow = new google.maps.MarkerImage("url", null, null, null, null); map_container.markers.marker = marker = new google.maps.Marker({"position":marker_position,"map":map,"icon":marker_icon,"shadow":marker_shadow}); map_container.kml_layers.kml_layer = kml_layer = new google.maps.KmlLayer("url", {"map":map}); map_container.event_manager.events.event = event = google.maps.event.addListener(instance, "click", function(){}); map_container.event_manager.events.marker_info_window_event = marker_info_window_event = google.maps.event.addListener(marker, "click", function () { for (var info_window in map_container.closable_info_windows) { map_container.closable_info_windows[info_window].close(); } marker_info_window.open(map, marker); }); map_bound.union(circle.getBounds()); encoded_polyline.getPath().forEach(function(element){map_bound.extend(element)}); map_bound.union(ground_overlay_bound); polygon.getPath().forEach(function(element){map_bound.extend(element)}); polyline.getPath().forEach(function(element){map_bound.extend(element)}); map_bound.union(rectangle_bound); map_bound.extend(map_info_window.getPosition()); map_bound.extend(marker.getPosition()); map.fitBounds(map_bound); EOF; $this->assertSame($expected, $this->mapHelper->renderJsContainer($map)); }
/** * @expectedException \Ivory\GoogleMap\Exception\OverlayException * @expectedExceptionMessage The icon setter arguments is invalid. * The available prototypes are : * - function setIcon(Ivory\GoogleMap\Overlays\MarkerImage $markerImage = null) * - function setIcon(string $url = null) */ public function testIconWithInvalidValue() { $this->marker->setIcon(true); }
public function testRenderWitoutMap() { $marker = new Marker(); $marker->setJavascriptVariable('marker'); $marker->setAnimation(Animation::BOUNCE); $marker->setPosition(1.1, 2.1, true); $marker->getPosition()->setJavascriptVariable('position'); $marker->setIcon('url'); $marker->getIcon()->setJavascriptVariable('icon'); $marker->setShadow('url'); $marker->getShadow()->setJavascriptVariable('shadow'); $marker->setShape('poly', array(1, 2, 3, 4)); $marker->getShape()->setJavascriptVariable('shape'); $expected = 'marker = new google.maps.Marker({' . '"position":position,' . '"animation":google.maps.Animation.BOUNCE,' . '"icon":icon,' . '"shadow":shadow,' . '"shape":shape' . '});' . PHP_EOL; $this->assertSame($expected, $this->markerHelper->render($marker)); }
/** * Render a Google Map in an iframe. If $identifier is specified then a small map will be output with a single * marker. Otherwise a large map will be output with a marker for each venue. * * @param null|string $identifier * * @return \Symfony\Component\HttpFoundation\Response */ public function mapAction($identifier = null) { $repo = $this->getDoctrine()->getManager()->getRepository('ActsCamdramBundle:Venue'); if ($identifier) { $venues = array($repo->findOneBySlug($identifier)); } else { $venues = $repo->findAllOrderedByName(); } $map = $this->get('ivory_google_map.map'); $map->setPrefixJavascriptVariable('map_'); $map->setHtmlContainerId('map_canvas'); $map->setStylesheetOptions(array('width' => '100%', 'height' => '100%')); $one_venue = count($venues) == 1; if ($one_venue) { $map->setMapOption('zoom', 16); $map->setCenter($venues[0]->getLatitude(), $venues[0]->getLongitude(), true); } else { $map->setMapOption('zoom', 14); $map->setCenter(52.20531, 0.12179, true); } $letter = ord('A'); $info_boxes = array(); foreach ($venues as $venue) { if ($venue->getLatitude() && $venue->getLongitude()) { $content = $this->render('ActsCamdramBundle:Venue:infobox.html.twig', array('venue' => $venue, 'one_venue' => $one_venue))->getContent(); $infoWindow = new InfoWindow(); $infoWindow->setPrefixJavascriptVariable('info_window_'); $infoWindow->setPosition($venue->getLatitude(), $venue->getLongitude(), true); $infoWindow->setContent($content); $infoWindow->setAutoOpen(true); $infoWindow->setOpenEvent(MouseEvent::CLICK); $infoWindow->setAutoClose(true); $infoWindow->setOption('zIndex', 10); $map->addInfoWindow($infoWindow); $marker = new Marker(); $marker->setPrefixJavascriptVariable('marker_'); $marker->setPosition($venue->getLatitude(), $venue->getLongitude(), true); if ($one_venue) { $marker->setIcon($this->getMarkerUrl('')); } else { $marker->setIcon($this->getMarkerUrl(chr($letter))); } $marker->setInfoWindow($infoWindow); $marker->setOption('clickable', true); $map->addMarker($marker); $info_boxes[] = array('image' => $this->getMarkerUrl(chr($letter)), 'box_id' => $infoWindow->getJavascriptVariable(), 'marker_id' => $marker->getJavascriptVariable(), 'map_id' => $map->getJavascriptVariable(), 'slug' => $venue->getSlug()); $letter++; if ($letter == ord('Z') + 1) { $letter = ord('A'); } } } return $this->render('ActsCamdramBundle:Venue:map.html.twig', array('map' => $map, 'info_boxes' => $info_boxes)); }