public function __construct(\Ivory\GoogleMap\Map $map, array $center) { $map->setCenter($center[0], $center[1], true); $map->setMapOption('zoom', 14); $map->setStylesheetOptions(array('width' => '100%', 'height' => '100%')); $this->map = $map; }
/** * Create empty map * * @param Coordinate $center * @param bool $async * * @return Map * @throws \Ivory\GoogleMap\Exception\AssetException * @throws \Ivory\GoogleMap\Exception\MapException */ public function createEmptyMap(Coordinate $center, bool $async = true) : Map { $map = new Map(); $map->setLanguage('en'); $map->setPrefixJavascriptVariable('map_'); $map->setHtmlContainerId('map_canvas'); $map->setMapOption('mapTypeId', MapTypeId::ROADMAP); $map->setAutoZoom(false); $map->setCenter($center); $map->setMapOption('zoom', 2); $map->setJavascriptVariable('location_map'); $map->setAsync($async); $map->setStylesheetOptions(['width' => '100%', 'height' => '300px']); return $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]); }
/** * Provides map for specified Track * @param Track $track * @throws \Ivory\GoogleMap\Exception\DirectionsException * @throws \Ivory\GoogleMap\Exception\MapException * @return Map */ public function getMap($track) { $directionsRequest = new DirectionsRequest(); $directionsRequest->setOrigin($track->getStartLatitude(), $track->getStartLongitude()); $directionsRequest->setDestination($track->getEndLatitude(), $track->getEndLongitude()); $directionsRequest->setTravelMode(TravelMode::DRIVING); $directions = new Directions(new CurlHttpAdapter()); $response = $directions->route($directionsRequest); $map = new Map(); $map->setCenter((double) ($track->getStartLatitude() + $track->getEndLatitude()) / 2, (double) ($track->getStartLongitude() + $track->getEndLongitude()) / 2); $map->setAutoZoom(false); $map->setMapOption('zoom', 14); $map->setMapOption('mapTypeId', MapTypeId::SATELLITE); $map->setMapOption('disableDefaultUI', true); $map->setMapOption('draggable', false); $map->setMapOption('scrollwheel', false); $map->setStylesheetOptions(array('width' => '100%', 'height' => '300px')); foreach ($response->getRoutes() as $route) { $overviewPolyline = $route->getOverviewPolyline(); $map->addEncodedPolyline($overviewPolyline); } return $map; }
public function testRenderStylesheets() { $map = new Map(); $map->setHtmlContainerId('html_container_id'); $map->setStylesheetOptions(array('width' => '200px', 'height' => '100px', 'option1' => 'value1')); $expected = <<<EOF <style type="text/css"> #html_container_id{ width:200px; height:100px; option1:value1; } </style> EOF; $this->assertSame($expected, $this->mapHelper->renderStylesheets($map)); }
public function testSetStylesheetOptionsWithValidValue() { $this->map->setStylesheetOptions(array('foo' => 'bar')); $this->assertSame('bar', $this->map->getStylesheetOption('foo')); }
/** * 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'); }
|-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It is a breeze. Simply tell Lumen the URIs it should respond to | and give it the Closure to call when that URI is requested. | */ use Ivory\GoogleMap\Map; use Ivory\GoogleMap\MapTypeId; $app->get('/', function () use($app) { return $app->version(); }); $app->get('map', function () use($app) { $map = new Map(); $map->setPrefixJavascriptVariable('map_'); $map->setHtmlContainerId('map_canvas'); $map->setAsync(false); $map->setAutoZoom(false); $map->setCenter(0, 0, true); $map->setMapOption('zoom', 3); $map->setBound(-2.1, -3.9, 2.6, 1.4, true, true); $map->setMapOption('mapTypeId', MapTypeId::ROADMAP); $map->setMapOption('mapTypeId', 'roadmap'); $map->setMapOption('disableDefaultUI', true); $map->setMapOption('disableDoubleClickZoom', true); $map->setMapOptions(array('disableDefaultUI' => true, 'disableDoubleClickZoom' => true)); $map->setStylesheetOption('width', '300px'); $map->setStylesheetOption('height', '300px'); $map->setStylesheetOptions(array('width' => '300px', 'height' => '300px')); $map->setLanguage('en'); });