/** @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));
 }
 protected function getGoogleMapMarkerInfo($markerContent)
 {
     $infoWindow = new InfoWindow();
     // Configure the info window options
     $infoWindow->setPrefixJavascriptVariable('info_window_');
     $infoWindow->setPosition(0, 0, true);
     $infoWindow->setPixelOffset(1.1, 2.1, 'px', 'pt');
     $infoWindow->setContent($markerContent);
     $infoWindow->setOpen(false);
     $infoWindow->setAutoOpen(true);
     $infoWindow->setOpenEvent(MouseEvent::CLICK);
     $infoWindow->setAutoClose(false);
     $infoWindow->setOption('disableAutoPan', true);
     $infoWindow->setOption('zIndex', 10);
     $infoWindow->setOptions(array('disableAutoPan' => true, 'zIndex' => 10));
     return $infoWindow;
 }
 /**
  * load court marker by id
  *
  * @var boolean $type   Should contain a boolean value to tell which markers to load
  *
  * @return array
  */
 public function loadMarkerById($id)
 {
     $map = clone $this->map;
     $court = $this->entityManager->getRepository('BasketPlannerMatchBundle:Court')->findOneBy(array('id' => $id));
     $map->setCenter($court->getLatitude(), $court->getLongitude(), true);
     $map->setMapOption('zoom', 10);
     $map->setMapOption('disableDefaultUI', false);
     $map->setMapOption('addMarker', false);
     $options = array('clickable' => true, 'markerID' => $court->getId(), 'markerAddress' => $court->getAddress());
     $marker = $this->createMarker($court->getLatitude(), $court->getLongitude(), true, $options);
     $infoWindow = new InfoWindow();
     $infoWindow->setContent($court->getAddress());
     $infoWindow->setAutoClose(true);
     $marker->setInfoWindow($infoWindow);
     $map->addMarker($marker);
     return $map;
 }
    public function testRenderJsContainerInfoWindowsWithClosableOnes()
    {
        $map = new Map();
        $map->setJavascriptVariable('map');
        $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->setInfoWindow($markerInfoWindow = new InfoWindow());
        $markerInfoWindow->setJavascriptVariable('marker_info_window');
        $markerInfoWindow->setPosition(1, 2, true);
        $markerInfoWindow->getPosition()->setJavascriptVariable('marker_info_window_position');
        $mapInfoWindow->setAutoClose(true);
        $markerInfoWindow->setAutoClose(true);
        $expected = <<<EOF
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.closable_info_windows.map_info_window = map_info_window;
map_container.closable_info_windows.marker_info_window = marker_info_window;

EOF;
        $this->assertSame($expected, $this->mapHelper->renderJsContainerInfoWindows($map));
    }
示例#5
0
 /**
  * Crée une fenêtre d'information pour un marker
  * @param $fiche, la fiche pour laquelle il créer une fenêtre d'informations
  * @return InfoWindow
  * @throws \Ivory\GoogleMap\Exception\AssetException
  * @throws \Ivory\GoogleMap\Exception\OverlayException
  */
 public function InfoWindowMarker($fiche)
 {
     $infoWindow = new InfoWindow();
     $infoWindow->setPrefixJavascriptVariable('info_window_');
     $infoWindow->setPosition($fiche->getLatitude(), $fiche->getLongitude(), true);
     $infoWindow->setPixelOffset(1.1, 2.1, 'px', 'pt');
     $infoWindow->setOpen(false);
     $infoWindow->setAutoOpen(true);
     $infoWindow->setOpenEvent('mouseover');
     $infoWindow->setAutoClose(true);
     $infoWindow->setOption('disableAutoPan', true);
     $infoWindow->setOptions(array('disableAutoPan' => true, 'zIndex' => 10));
     return $infoWindow;
 }
 /**
  * @expectedException \Ivory\GoogleMap\Exception\OverlayException
  * @expectedExceptionMessage The info window auto close flag must be a boolean value.
  */
 public function testAutoCloseWithInvalidValue()
 {
     $this->infoWindow->setAutoClose('foo');
 }
示例#7
0
 /**
  * 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));
 }