public function testRender() { $map = $this->getMock('Ivory\\GoogleMap\\Map'); $map->expects($this->once())->method('getJavascriptVariable')->will($this->returnValue('map')); $circle = new Circle(); $circle->setJavascriptVariable('circle'); $circle->setCenter(1.1, 2.1, true); $circle->getCenter()->setJavascriptVariable('center'); $circle->setRadius(2); $circle->setOptions(array('option1' => 'value1', 'option2' => 'value2')); $expected = 'circle = new google.maps.Circle({' . '"map":map,' . '"center":center,' . '"radius":2,' . '"option1":"value1",' . '"option2":"value2"' . '});' . PHP_EOL; $this->assertSame($expected, $this->circleHelper->render($circle, $map)); }
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 radius of a circle must be a numeric value. */ public function testRadiusWithInvalidValue() { $this->circle->setRadius(true); }
/** * Renders a circle. * * @param \Ivory\GoogleMap\Overlays\Circle $circle The circle. * @param \Ivory\GoogleMap\Map $map The map. * * @return string The JS output. */ public function render(Circle $circle, Map $map) { $this->jsonBuilder->reset()->setValue('[map]', $map->getJavascriptVariable(), false)->setValue('[center]', $circle->getCenter()->getJavascriptVariable(), false)->setValue('[radius]', $circle->getRadius())->setValues($circle->getOptions()); return sprintf('%s = new google.maps.Circle(%s);' . PHP_EOL, $circle->getJavascriptVariable(), $this->jsonBuilder->build()); }