/** @var Ivory\GoogleMapBundle\Model\Map */ public function generateGoogleMapAction($address, $city) { $locationInfo = [$address, $city]; $map = $this->get('ivory_google_map.map'); $curl = new \Ivory\HttpAdapter\CurlHttpAdapter(); $geocoder = new \Geocoder\Provider\GoogleMaps($curl); $json = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($locationInfo[0]) . '+' . urlencode($locationInfo[1])); $obj = json_decode($json); if (count($obj->results) === 0) { return $this->render('ConnectHollandPiccoloContentBundle:Block:googlemap.html.twig', array('map' => $map)); } $location = $geocoder->geocode($locationInfo[0] . ' ' . $locationInfo[1])->first(); $latitude = $location->getLatitude(); $longitude = $location->getLongitude(); $map->setCenter($latitude, $longitude, true); $map->setMapOption('zoom', 12); $marker = new Marker(); $marker->setPosition($latitude, $longitude, true); $marker->setOption('clickable', true); $map->addMarker($marker); $infoWindow = new InfoWindow(); $infoWindow->setContent('<p>' . $locationInfo[0] . '<br/>' . $locationInfo[1] . '</p>'); $infoWindow->setAutoClose(true); $marker->setInfoWindow($infoWindow); return $this->render('ConnectHollandPiccoloContentBundle:Block:googlemap.html.twig', array('map' => $map)); }
/** * Renders the info window open flag. * * @param \Ivory\GoogleMap\Overlays\InfoWindow $infoWindow The info window. * @param \Ivory\GoogleMap\Map $map The map. * @param \Ivory\GoogleMap\Overlays\Marker $marker The marker. * * @return string The JS output. */ public function renderOpen(InfoWindow $infoWindow, Map $map, Marker $marker = null) { if ($marker !== null) { return sprintf('%s.open(%s, %s);' . PHP_EOL, $infoWindow->getJavascriptVariable(), $map->getJavascriptVariable(), $marker->getJavascriptVariable()); } return sprintf('%s.open(%s);' . PHP_EOL, $infoWindow->getJavascriptVariable(), $map->getJavascriptVariable()); }
public function testRenderMarkers() { $map = new Map(); $map->setJavascriptVariable('map'); $map->addMarker($marker = new Marker()); $marker->setJavascriptVariable('marker'); $marker->getPosition()->setJavascriptVariable('marker_position'); $expected = <<<EOF map_container.markers.marker = marker = new google.maps.Marker({"position":marker_position}); EOF; $this->assertSame($expected, $this->helper->renderMarkers($map->getMarkerCluster(), $map)); }
public function testRenderMarkersWithAutoOpenInfoWindow() { $map = new Map(); $map->setJavascriptVariable('map'); $map->addMarker($marker = new Marker()); $marker->setJavascriptVariable('marker'); $marker->getPosition()->setJavascriptVariable('marker_position'); $marker->setInfoWindow($infoWindow = new InfoWindow()); $infoWindow->setJavascriptVariable('marker_info_window'); $infoWindow->setAutoOpen(true); $this->helper->renderMarkers($map->getMarkerCluster(), $map); $this->assertNotEmpty($map->getEventManager()->getEvents()); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { // $map = new Map(); $mapHelper = new MapHelper(); $geocoder = new Geocoder(); $geocoder->registerProviders(array(new GeocoderProvider(new CurlHttpAdapter()))); $response = $geocoder->geocode('23 Lapu-lapu Street, Agdao, Davao City, Philippines 8000'); foreach ($response->getResults() as $result) { $marker = new Marker(); $marker->setPosition($result->getGeometry()->getLocation()); $map->setCenter($result->getGeometry()->getLocation()); $map->addMarker($marker); } $map->setStylesheetOptions(array('width' => '100%', 'height' => '300px')); $map->setMapOption('zoom', 15); $map->setAsync(true); $data['map'] = $mapHelper->render($map); return view('pages.contact.index')->with(['data' => $data]); }
/** * Render map with marker * * @param Coordinate $point * @param string $info * @param bool $async * * @return mixed * @throws \Ivory\GoogleMap\Exception\AssetException * @throws \Ivory\GoogleMap\Exception\MapException * @throws \Ivory\GoogleMap\Exception\OverlayException */ public function renderMapWithMarker(Coordinate $point, string $info = '', bool $async = true) : array { $marker = new Marker(); $infoWindow = new InfoWindow(); $marker->setPrefixJavascriptVariable('marker_'); $marker->setPosition($point); $marker->setAnimation(Animation::DROP); $marker->setOption('clickable', true); $marker->setOption('flat', true); if ($info) { $infoWindow->setPrefixJavascriptVariable('info_window_'); $infoWindow->setContent("<p>{$info}</p>"); $infoWindow->setOpen(false); $infoWindow->setAutoOpen(true); $marker->setInfoWindow($infoWindow); } $map = $this->createEmptyMap($point, $async); $map->setMapOption('zoom', 13); $map->addMarker($marker); return $this->renderMap($map); }
protected function setMarkerOptions($markerPosition, $markerContent) { $position = explode(',', $markerPosition); $marker = new Marker(); $marker->setPrefixJavascriptVariable('londa_marker_'); $marker->setPosition($position[0], $position[1], true); $marker->setAnimation(Animation::DROP); $marker->setOptions(array('clickable' => true, 'flat' => true)); $infoWindow = $this->getGoogleMapMarkerInfo($markerContent); $marker->setInfoWindow($infoWindow); return $marker; }
public function generateAction($address, $info_bulle = '', $width = '100%', $height = '100%') { $geocoder = new \Geocoder\Geocoder(); $adapter = new \Geocoder\HttpAdapter\CurlHttpAdapter(); $chain = new \Geocoder\Provider\ChainProvider(array(new \Geocoder\Provider\FreeGeoIpProvider($adapter), new \Geocoder\Provider\HostIpProvider($adapter), new \Geocoder\Provider\GoogleMapsProvider($adapter, 'fr_FR', 'France', true), new \Geocoder\Provider\BingMapsProvider($adapter, 'AIzaSyBZ3sNuoMPrXGCNbhnEbGmfzGxOohhEX4E'))); $geocoder->registerProvider($chain); $address = urldecode($address); $info_bulle = urldecode($info_bulle); // Récupération des coordonnées du programme try { $coordonnees = $geocoder->geocode($address); } catch (ChainNoResultException $e) { try { $coordonnees = $geocoder->geocode('France'); } catch (ChainNoResultException $e) { return false; } } $info_content = '<div style="min-width:150px;text-align:center;">' . $info_bulle . '</div>'; $info_window = new InfoWindow(); $info_window->setAutoOpen(true); $info_window->setOpen(true); $info_window->setContent($info_content); $marker = new Marker(); $marker->setPosition($coordonnees->getLatitude(), $coordonnees->getLongitude(), true); $marker->setAnimation('drop'); $marker->setOption('clickable', true); $marker->setOption('flat', true); if ($info_bulle) { $marker->setInfoWindow($info_window); } // Création de la map $map = new Map(); $map->setPrefixJavascriptVariable('map_'); $map->setHtmlContainerId('map_canvas'); $map->setAsync(true); $map->setAutoZoom(false); $map->setCenter($coordonnees->getLatitude(), $coordonnees->getLongitude(), true); $map->setMapOption('zoom', 12); $map->setMapOption('mapTypeId', MapTypeId::ROADMAP); $map->setMapOption('disableDefaultUI', false); $map->setMapOption('disableDoubleClickZoom', false); $map->setStylesheetOption('width', $width); $map->setStylesheetOption('height', $height); $map->setLanguage('fr'); $map->addMarker($marker); return $map; }
public function testRenderJavascriptsWithMarkerInfoWindowOpened() { $infoWindow = new InfoWindow(); $infoWindow->setJavascriptVariable('info_window'); $infoWindow->setContent('foo'); $infoWindow->setAutoOpen(false); $infoWindow->setOpen(true); $marker = new Marker(); $marker->setJavascriptVariable('marker'); $marker->setPosition(1.2, 2.1, true); $marker->getPosition()->setJavascriptVariable('marker_position'); $marker->setInfoWindow($infoWindow); $map = new Map(); $map->setJavascriptVariable('map'); $map->getCenter()->setJavascriptVariable('map_center'); $map->addMarker($marker); $expected = <<<EOF <script type="text/javascript"> function load_ivory_google_map_api () { google.load("maps", "3", {"other_params":"language=en&sensor=false"}); }; </script> <script type="text/javascript" src="//www.google.com/jsapi?callback=load_ivory_google_map_api"></script> <script type="text/javascript"> 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.map_center = map_center = new google.maps.LatLng(0, 0, true); map_container.coordinates.marker_position = marker_position = new google.maps.LatLng(1.2, 2.1, true); map_container.map = map = new google.maps.Map(document.getElementById("map_canvas"), {"mapTypeId":google.maps.MapTypeId.ROADMAP,"zoom":3}); map_container.info_windows.info_window = info_window = new google.maps.InfoWindow({"content":"foo"}); map_container.markers.marker = marker = new google.maps.Marker({"position":marker_position,"map":map}); info_window.open(map, marker); map.setCenter(map_center); </script> EOF; $this->assertSame($expected, $this->mapHelper->renderJavascripts($map)); }
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)); }
/** * Renders a marker with the js map container. * * @param \Ivory\GoogleMap\Overlays\Marker $marker The marker. * @param \Ivory\GoogleMap\Map $map The map. * * @return string The JS output. */ protected function renderMarker(Marker $marker, Map $map) { return sprintf('%s.markers.%s = %s', $this->getJsContainerName($map), $marker->getJavascriptVariable(), $this->markerHelper->render($marker)); }
/** * create new marker * * @var float $latitude * @var float $longitude * @var boolean $noWrap * @var array $options * * @return Marker */ public function createMarker($latitude, $longitude, $noWrap, $options) { $marker = new Marker(); $marker->setPosition($latitude, $longitude, $noWrap); foreach ($options as $key => $value) { $marker->setOption($key, $value); } return $marker; }
public function testInfoWindow() { $infoWindow = $this->getMock('Ivory\\GoogleMap\\Overlays\\InfoWindow'); $this->marker->setInfoWindow($infoWindow); $this->assertSame($infoWindow, $this->marker->getInfoWindow()); }
/** * Renders a marker. * * @param Ivory\GoogleMap\Overlays\Marker $marker The marker. * @param Ivory\GoogleMap\Map $map The map. * * @return string The JS output. */ public function render(Marker $marker, Map $map = null) { $this->jsonBuilder->reset()->setValue('[position]', $marker->getPosition()->getJavascriptVariable(), false); if ($map !== null) { $this->jsonBuilder->setValue('[map]', $map->getJavascriptVariable(), false); } if ($marker->hasAnimation()) { $this->jsonBuilder->setValue('[animation]', $this->animationHelper->render($marker->getAnimation()), false); } if ($marker->hasIcon()) { $this->jsonBuilder->setValue('[icon]', $marker->getIcon()->getJavascriptVariable(), false); } if ($marker->hasShadow()) { $this->jsonBuilder->setValue('[shadow]', $marker->getShadow()->getJavascriptVariable(), false); } if ($marker->hasShape()) { $this->jsonBuilder->setValue('[shape]', $marker->getShape()->getJavascriptVariable(), false); } $this->jsonBuilder->setValues($marker->getOptions()); return sprintf('%s = new google.maps.Marker(%s);' . PHP_EOL, $marker->getJavascriptVariable(), $this->jsonBuilder->build()); }
/** * 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)); }