Beispiel #1
0
 /**
  * Render map
  *
  * @param Map $map
  *
  * @return mixed
  */
 public function renderMap(Map $map) : array
 {
     $mapHelper = new MapHelper();
     $jsMap = $mapHelper->renderJsLibraries($map);
     $jsMap = $this->removeJsCaller($jsMap);
     $jsMap .= '<script type="text/javascript"> function load_ivory_google_map(){' . $mapHelper->renderJsContainer($map) . '}</script>';
     return ['html' => $mapHelper->renderHtmlContainer($map) . $mapHelper->renderStylesheets($map), 'js' => $jsMap];
 }
    public function testRender()
    {
        $map = new Map();
        $map->setJavascriptVariable('map');
        $map->getCenter()->setJavascriptVariable('map_center');
        $expected = <<<EOF
<div id="map_canvas" style="width:300px;height:300px;"></div>
<style type="text/css">
#map_canvas{
width:300px;
height:300px;
}
</style>
<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.map = map = new google.maps.Map(document.getElementById("map_canvas"), {"mapTypeId":google.maps.MapTypeId.ROADMAP,"zoom":3});
map.setCenter(map_center);
</script>

EOF;
        $this->assertSame($expected, $this->mapHelper->render($map));
    }
 /**
  * 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]);
 }
 public function testRenderJavascripts()
 {
     $map = $this->getMock('Ivory\\GoogleMap\\Map');
     $this->mapHelperMock->expects($this->once())->method('renderJavascripts')->with($map)->will($this->returnValue('foo'));
     $this->assertSame('foo', $this->templateHelper->renderJavascripts($map));
 }
 /**
  * @Route ("vertodos/")
  * @Template("YacareBaseBundle:DispositivoRastreadorGps:ver.html.twig")
  */
 public function vertodosAction(Request $request)
 {
     $em = $this->getEm();
     $Dispositivos = $em->getRepository('Yacare\\BaseBundle\\Entity\\DispositivoRastreadorGps')->findAll();
     $map = $this->CrearMapa();
     foreach ($Dispositivos as $Dispositivo) {
         $id = $Dispositivo->getId();
         $res = parent::verAction($request, $id);
         $entity = $res['entity'];
         if ($entity->getObs() == null) {
             $entity->setObs('Serie ' . $entity->getNumeroSerie());
         }
         $UltimoRastreo = $em->getRepository('Yacare\\BaseBundle\\Entity\\DispositivoRastreo')->findBy(array('Dispositivo' => $id), array('id' => 'DESC'), 1);
         if ($UltimoRastreo) {
             $UltimoRastreo = $UltimoRastreo[0];
             $map->addMarker($this->CrearMarcador($UltimoRastreo, $entity));
             // $map->setCenter($UltimoRastreo->getUbicacion()->getX(), $UltimoRastreo->getUbicacion()->getY(),
             // true);
         }
     }
     $mapHelper = new MapHelper();
     $mapHelper->setExtensionHelper('gps_extension_helper', new GpsExtensionHelper());
     $output = $mapHelper->renderJavascripts($map);
     $res['dispositivos'] = $Dispositivos;
     $res['js'] = $output;
     $res['map'] = $map;
     $res['uno'] = false;
     return $res;
 }
 /**
  * Renders the google map javascripts.
  *
  * @param \Ivory\GoogleMap\Map $map The map.
  *
  * @return string The html output.
  */
 public function renderJavascripts(Map $map)
 {
     return $this->mapHelper->renderJavascripts($map);
 }
 /**
  * View action
  * @param int $id
  * @throws \Exception
  */
 public function viewAction($id = null)
 {
     if (is_null($id)) {
         throw new \Exception('Bad request');
     }
     $id = abs((int) $id);
     $userId = $this->session->get('uid');
     $model = $this->loadModel('events');
     $comments = $this->loadModel('comment');
     $event = $model->getEvent($id);
     $isJoined = $model->checkJoinedUser($id, $userId);
     $attendingUsers = $model->getAttendingUsers($id);
     /** Google Maps API */
     $map = new Map();
     $markerPositions = $instructions = $commonInfo = [];
     $map->setLanguage('uk');
     $map->setAutoZoom(true);
     $map->setPrefixJavascriptVariable('map_');
     $map->setHtmlContainerId('map-canvas-view');
     $map->setMapOptions(array('disableDefaultUI' => true, 'disableDoubleClickZoom' => true, 'mapTypeId' => 'roadmap'));
     $map->setStylesheetOptions(array('width' => '58%', 'height' => 'calc(100% - 0)', 'position' => 'absolute', 'right' => '0px', 'top' => '50px', 'bottom' => '2px', 'overflow' => 'hidden'));
     // Build directions
     $request = new DirectionsRequest();
     $request->setLanguage('uk');
     $request->setUnitSystem(UnitSystem::METRIC);
     $request->setTravelMode($event['routeMode']);
     $request->setOrigin($event['routeFrom']);
     $request->setDestination($event['routeTo']);
     // @TODO: Do it
     // $request->addWaypoint($event['routeVia']);
     // $request->setOptimizeWaypoints(true);
     // $request->setAvoidHighways(true);
     // $request->setAvoidTolls(true);
     // $request->setProvideRouteAlternatives(true);
     $directions = new Directions(new CurlHttpAdapter());
     $response = $directions->route($request);
     if ($response->getStatus() === 'OK') {
         $routes = $response->getRoutes();
         foreach ($routes as $route) {
             $overviewPolyline = $route->getOverviewPolyline();
             //$waypointOrder = $route->getWaypointOrder();  // Get the waypoint order
             foreach ($route->getLegs() as $leg) {
                 // Set the start location & the end location into array
                 $markerPositions = ['start' => [$leg->getStartLocation()->getLatitude(), $leg->getStartLocation()->getLongitude()], 'end' => [$leg->getEndLocation()->getLatitude(), $leg->getEndLocation()->getLongitude()]];
                 $commonInfo = ['distance' => $leg->getDistance()->getText(), 'duration' => $leg->getDuration()->getText(), 'startAddress' => $leg->getStartAddress(), 'endAddress' => $leg->getEndAddress()];
                 // Set the directions steps
                 foreach ($leg->getSteps() as $key => $step) {
                     $instructions[] = [$step->getInstructions(), $step->getDistance()->getText(), $step->getDuration()->getText(), $step->getTravelMode()];
                 }
             }
         }
         // Build markers
         foreach ($markerPositions as $latlng) {
             $position = new Coordinate($latlng[0], $latlng[1], true);
             $marker = new Marker($position, 'drop', null, null, null, new InfoWindow());
             $map->addMarker($marker);
         }
         // Build Polyline
         $encodedPolyline = new EncodedPolyline();
         $encodedPolyline->setValue($overviewPolyline->getValue());
         $encodedPolyline->setOptions(array('geodesic' => true, 'strokeColor' => '#3079ed', 'strokeOpacity' => 0.8, 'strokeWeight' => 5));
         $map->addEncodedPolyline($encodedPolyline);
     } else {
         $position = new Coordinate($event['latTo'], $event['lngTo']);
         $info = $event['routeTo'];
         $info .= !empty($event['date']) ? '<hr><i class="glyphicon glyphicon-time"></i> ' . $event['date'] : '';
         $info .= !empty($event['end_date']) ? '<br><i class="glyphicon glyphicon-time"></i> ' . $event['end_date'] : '';
         $marker = new Marker($position, 'drop', null, null, null, new InfoWindow($info));
         $map->addMarker($marker);
     }
     // Render map
     $mapHelper = new MapHelper();
     $this->view->map = $mapHelper->render($map);
     $this->view->event = $event;
     $this->view->comments = $comments->getComments($id);
     $this->view->commentsAccess = (bool) $userId;
     $this->view->isJoined = (bool) $isJoined;
     $this->view->attendingUsers = $attendingUsers;
     $this->view->instructions = $instructions;
     $this->view->render('events/view');
 }