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; }
/** * 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); }
/** * 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)); }