예제 #1
0
 public function testPrePersistWithAutozoom()
 {
     $this->map->setCenter(-1.1, -2.2);
     $this->map->setBound(1, 2, 3, 4);
     $this->map->setAutoZoom(true);
     $this->map->prePersist();
     $this->assertNull($this->map->getCenter());
     $this->assertSame(1, $this->map->getBound()->getSouthWest()->getLatitude());
     $this->assertSame(2, $this->map->getBound()->getSouthWest()->getLongitude());
     $this->assertSame(3, $this->map->getBound()->getNorthEast()->getLatitude());
     $this->assertSame(4, $this->map->getBound()->getNorthEast()->getLongitude());
 }
예제 #2
0
 public function testGroundOverlayWithAutoZoom()
 {
     $groundOverlay = $this->getMock('Ivory\\GoogleMap\\Overlays\\GroundOverlay');
     $this->map->setAutoZoom(true);
     $this->setUpBound();
     $this->map->getBound()->expects($this->once())->method('extend')->with($this->equalTo($groundOverlay));
     $this->map->addGroundOverlay($groundOverlay);
     $this->assertSame(array($groundOverlay), $this->map->getGroundOverlays());
 }
예제 #3
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;
 }
예제 #4
0
파일: MapService.php 프로젝트: chadyred/crm
 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;
 }
예제 #5
0
 /**
  * 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;
 }
예제 #6
0
    public function testRenderJsContainerWithComplexMap()
    {
        $map = new Map();
        $map->setJavascriptVariable('map');
        $map->setAutoZoom(true);
        $map->getBound()->setJavascriptVariable('map_bound');
        $map->addCircle($circle = new Circle());
        $circle->setJavascriptVariable('circle');
        $circle->getCenter()->setJavascriptVariable('circle_center');
        $map->addEncodedPolyline($encodedPolyline = new EncodedPolyline('foo'));
        $encodedPolyline->setJavascriptVariable('encoded_polyline');
        $map->addGroundOverlay($groundOverlay = new GroundOverlay('url'));
        $groundOverlay->setJavascriptVariable('ground_overlay');
        $groundOverlay->getBound()->setJavascriptVariable('ground_overlay_bound');
        $groundOverlay->getBound()->setSouthWest(1, 2, true);
        $groundOverlay->getBound()->getSouthWest()->setJavascriptVariable('ground_overlay_bound_south_west');
        $groundOverlay->getBound()->setNorthEast(3, 4, true);
        $groundOverlay->getBound()->getNorthEast()->setJavascriptVariable('ground_overlay_bound_north_east');
        $map->addPolygon($polygon = new Polygon());
        $polygon->setJavascriptVariable('polygon');
        $map->addPolyline($polyline = new Polyline());
        $polyline->setJavascriptVariable('polyline');
        $map->addRectangle($rectangle = new Rectangle());
        $rectangle->setJavascriptVariable('rectangle');
        $rectangle->getBound()->setJavascriptVariable('rectangle_bound');
        $rectangle->getBound()->setSouthWest(1, 2, true);
        $rectangle->getBound()->getSouthWest()->setJavascriptVariable('rectangle_bound_south_west');
        $rectangle->getBound()->setNorthEast(3, 4, true);
        $rectangle->getBound()->getNorthEast()->setJavascriptVariable('rectangle_bound_north_east');
        $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->setJavascriptVariable('marker');
        $marker->getPosition()->setJavascriptVariable('marker_position');
        $marker->setInfoWindow($markerInfoWindow = new InfoWindow());
        $markerInfoWindow->setJavascriptVariable('marker_info_window');
        $marker->setIcon('url');
        $marker->getIcon()->setJavascriptVariable('marker_icon');
        $marker->setShadow('url');
        $marker->getShadow()->setJavascriptVariable('marker_shadow');
        $map->addKMLLayer($kmlLayer = new KMLLayer('url'));
        $kmlLayer->setJavascriptVariable('kml_layer');
        $map->getEventManager()->addEvent($event = new Event('instance', 'click', 'function(){}', false));
        $event->setJavascriptVariable('event');
        $expected = <<<EOF
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.ground_overlay_bound_south_west = ground_overlay_bound_south_west = new google.maps.LatLng(1, 2, true);
map_container.coordinates.ground_overlay_bound_north_east = ground_overlay_bound_north_east = new google.maps.LatLng(3, 4, true);
map_container.coordinates.rectangle_bound_south_west = rectangle_bound_south_west = new google.maps.LatLng(1, 2, true);
map_container.coordinates.rectangle_bound_north_east = rectangle_bound_north_east = new google.maps.LatLng(3, 4, true);
map_container.coordinates.circle_center = circle_center = new google.maps.LatLng(0, 0, true);
map_container.coordinates.map_info_window_position = map_info_window_position = new google.maps.LatLng(1, 2, true);
map_container.coordinates.marker_position = marker_position = new google.maps.LatLng(0, 0, true);
map_container.bounds.map_bound = map_bound = new google.maps.LatLngBounds();
map_container.bounds.ground_overlay_bound = ground_overlay_bound = new google.maps.LatLngBounds(ground_overlay_bound_south_west, ground_overlay_bound_north_east);
map_container.bounds.rectangle_bound = rectangle_bound = new google.maps.LatLngBounds(rectangle_bound_south_west, rectangle_bound_north_east);
map_container.map = map = new google.maps.Map(document.getElementById("map_canvas"), {"mapTypeId":google.maps.MapTypeId.ROADMAP});
map_container.circles.circle = circle = new google.maps.Circle({"map":map,"center":circle_center,"radius":1});
map_container.encoded_polylines.encoded_polyline = encoded_polyline = new google.maps.Polyline({"map":map,"path":google.maps.geometry.encoding.decodePath("foo")});
map_container.ground_overlays.ground_overlay = ground_overlay = new google.maps.GroundOverlay("url", ground_overlay_bound, {"map":map});
map_container.polygons.polygon = polygon = new google.maps.Polygon({"map":map,"paths":[]});
map_container.polylines.polyline = polyline = new google.maps.Polyline({"map":map,"path":[]});
map_container.rectangles.rectangle = rectangle = new google.maps.Rectangle({"map":map,"bounds":rectangle_bound});
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.marker_images.marker_icon = marker_icon = new google.maps.MarkerImage("url", null, null, null, null);
map_container.marker_images.marker_shadow = marker_shadow = new google.maps.MarkerImage("url", null, null, null, null);
map_container.markers.marker = marker = new google.maps.Marker({"position":marker_position,"map":map,"icon":marker_icon,"shadow":marker_shadow});
map_container.kml_layers.kml_layer = kml_layer = new google.maps.KmlLayer("url", {"map":map});
map_container.event_manager.events.event = event = google.maps.event.addListener(instance, "click", function(){});
map_container.event_manager.events.marker_info_window_event = marker_info_window_event = google.maps.event.addListener(marker, "click", function () {
    for (var info_window in map_container.closable_info_windows) {
        map_container.closable_info_windows[info_window].close();
    }
    marker_info_window.open(map, marker);

});
map_bound.union(circle.getBounds());
encoded_polyline.getPath().forEach(function(element){map_bound.extend(element)});
map_bound.union(ground_overlay_bound);
polygon.getPath().forEach(function(element){map_bound.extend(element)});
polyline.getPath().forEach(function(element){map_bound.extend(element)});
map_bound.union(rectangle_bound);
map_bound.extend(map_info_window.getPosition());
map_bound.extend(marker.getPosition());
map.fitBounds(map_bound);

EOF;
        $this->assertSame($expected, $this->mapHelper->renderJsContainer($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');
 }
예제 #8
0
파일: routes.php 프로젝트: myorb/remapent
|--------------------------------------------------------------------------
|
| 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');
});