Exemple #1
0
 /**
  * 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;
 }
Exemple #2
0
 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;
 }
Exemple #3
0
 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;
 }
 /**
  * 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;
 }
 /**
  * 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 testRenderMapWithDisabledMapControls()
 {
     $map = new Map();
     $map->setJavascriptVariable('map');
     $map->setMapOption('mapTypeControl', false);
     $expected = 'map = new google.maps.Map(' . 'document.getElementById("map_canvas"), ' . '{"mapTypeId":google.maps.MapTypeId.ROADMAP,"mapTypeControl":false,"zoom":3}' . ');' . PHP_EOL;
     $this->assertSame($expected, $this->mapHelper->renderMap($map));
 }
 /**
  * @expectedException \Ivory\GoogleMap\Exception\MapException
  */
 public function testSetMapOptionWithInvalidValue()
 {
     $this->map->setMapOption(true, false);
 }
Exemple #8
0
|--------------------------------------------------------------------------
|
| 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');
});