Exemplo n.º 1
0
        void mapControl1_MapMouseClick(MapControlEventArgs e)
        {
            if (_router != null)
            {
                var routerPoint = _router.Resolve(Vehicle.Car, e.Position);
                if (routerPoint != null)
                {
                    _points.Add(routerPoint);
                    _layerPrimitives.AddPoint(routerPoint.Location, 15, SimpleColor.FromKnownColor(KnownColor.Black).Value);
                    _layerPrimitives.AddPoint(routerPoint.Location, 7, SimpleColor.FromKnownColor(KnownColor.White).Value);
                }

                if (_points.Count > 1)
                {
                    var tspRouter = new RouterTSPWrapper <RouterTSPAEXGenetic>(
                        new RouterTSPAEXGenetic(), _router);

                    var route = tspRouter.CalculateTSP(Vehicle.Car, _points.ToArray());
                    if (route != null)
                    {
                        _layerRoute.Clear();
                        _layerRoute.AddRoute(route);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void UserPositionChanged(object sender, PositionEventArgs e)
        {
            if (layerUser != null && IsShowingUser)
            {
                var center = new GeoCoordinate(e.Position.Latitude, e.Position.Longitude);

                layerUser.Clear();
                layerAccuracy.Clear();

                if (IsShowingUserInCenter)
                {
                    mapView.MapCenter = center;
                }

                layerAccuracy.AddPoint(center, 2.2f + mapView.Density * (float)e.Position.Accuracy, SimpleColor.FromArgb(32, 0, 0, 255).Value);

                layerUser.AddPoint(center, mapView.Density * 2.2f, SimpleColor.FromKnownColor(KnownColor.Blue).Value);
                layerUser.AddPoint(center, mapView.Density * 1.8f, SimpleColor.FromKnownColor(KnownColor.White).Value);
                layerUser.AddPoint(center, mapView.Density * 1.2f, SimpleColor.FromKnownColor(KnownColor.Blue).Value);
            }
        }
Exemplo n.º 3
0
        private void DrawUserIcon(GeoCoordinate coord, double accuracy)
        {
            // If there no coordiantes, we have nothing to do
            if (coord == null)
            {
                return;
            }

            if (layerAccuracy == null)
            {
                // Create layer for accuracy
                layerAccuracy = new LayerPrimitives(map.Projection);
                // Add new accuracy layer
                map.AddLayer(layerAccuracy);
            }

            if (layerUser == null)
            {
                // Create layer for user icon
                layerUser = new LayerPrimitives(map.Projection);
                // Add layer for user icon
                map.AddLayer(layerUser);
            }

            var repaintUserIcon = coord.Latitude != lastKnownPosition?.Latitude || coord.Longitude != lastKnownPosition?.Longitude;
            var repaintAccuracy = true;

            // Stop painting
            layerAccuracy.Pause();
            layerUser.Pause();

            if (repaintAccuracy)
            {
                layerAccuracy.Clear();
            }

            if (repaintUserIcon)
            {
                layerUser.Clear();
            }

            if (IsShowingUserInCenter)
            {
                mapView.MapCenter = coord;
            }

            if (repaintAccuracy)
            {
                var size = 2.2f + mapView.Density * (float)accuracy;
                layerAccuracy.AddPoint(coord, size > 40 ? 40 : size, SimpleColor.FromArgb(32, 0, 0, 255).Value);
            }

            if (repaintUserIcon)
            {
                layerUser.AddPoint(coord, mapView.Density * 2.2f, SimpleColor.FromKnownColor(KnownColor.Blue).Value);
                layerUser.AddPoint(coord, mapView.Density * 1.8f, SimpleColor.FromKnownColor(KnownColor.White).Value);
                layerUser.AddPoint(coord, mapView.Density * 1.2f, SimpleColor.FromKnownColor(KnownColor.Blue).Value);
            }

            layerAccuracy.Resume();
            layerUser.Resume();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes the View property.
        /// </summary>
        public override void LoadView()
        {
            base.LoadView();

            // initialize OsmSharp native hooks.
            Native.Initialize();

            // enable the loggging.
            OsmSharp.Logging.Log.Enable();
            OsmSharp.Logging.Log.RegisterListener(new OsmSharp.iOS.UI.Log.ConsoleTraceListener());

            // initialize map.
            var map = new Map();

            // add a tile layer.
            map.AddLayer(new LayerTile(@"http://otile1.mqcdn.com/tiles/1.0.0/osm/{0}/{1}/{2}.png"));
//            map.AddLayer(new LayerMBTile(SQLiteConnection.CreateFrom(
//                Assembly.GetExecutingAssembly().GetManifestResourceStream(@"OsmSharp.iOS.UI.Sample.kempen.mbtiles"), "map")));

            // add an online osm-data->mapCSS translation layer.
            //map.AddLayer(new OsmLayer(dataSource, mapCSSInterpreter));
            // add a pre-processed vector data file.
//			var sceneStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
//				"OsmSharp.iOS.UI.Sample.default.map");
//			map.AddLayer(new LayerScene(Scene2D.Deserialize(sceneStream, true)));

            var primitivesLayer = new LayerPrimitives(map.Projection);

            primitivesLayer.AddPoint(new GeoCoordinate(51.26371, 4.78601), 10,
                                     SimpleColor.FromKnownColor(KnownColor.Blue).Value);
            map.AddLayer(primitivesLayer);

//			// define dummy from and to points.
            var from = new GeoCoordinate(51.261203, 4.780760);
            var to   = new GeoCoordinate(51.267797, 4.801362);

//
//			// deserialize the pre-processed graph.
//			var routingSerializer = new CHEdgeDataDataSourceSerializer(false);
//			TagsCollectionBase metaData = null;
//			var graphStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
//				"OsmSharp.iOS.UI.Sample.kempen-big.osm.pbf.routing");
//			var graphDeserialized = routingSerializer.Deserialize(graphStream, out metaData, true);
//
//			// initialize router.
//			_router = Router.CreateCHFrom(graphDeserialized, new CHRouter(), new OsmRoutingInterpreter());
//
//			// resolve points.
//			RouterPoint routerPoint1 = _router.Resolve(Vehicle.Car, from);
//			RouterPoint routerPoint2 = _router.Resolve(Vehicle.Car, to);
//
//			// calculate route.
//			Route route = _router.Calculate(Vehicle.Car, routerPoint1, routerPoint2);
//			RouteTracker routeTracker = new RouteTracker(route, new OsmRoutingInterpreter());
//			_enumerator = route.GetRouteEnumerable(10).GetEnumerator();
//
//			// add a router layer.
//			_routeLayer = new LayerRoute(map.Projection);
//			_routeLayer.AddRoute (route, SimpleColor.FromKnownColor(KnownColor.Blue, 125).Value, 12);
//			map.AddLayer(_routeLayer);

            // define the mapview.
            _mapView = new MapView();
            //_mapView.MapTapEvent += new MapViewEvents.MapTapEventDelegate(_mapView_MapTapEvent);
            _mapView.MapAllowTilt    = false;
            _mapView.Map             = map;
            _mapView.MapMaxZoomLevel = 19;
            _mapView.MapMinZoomLevel = 0;
            _mapView.MapTilt         = 0;
            _mapView.MapCenter       = new GeoCoordinate(51.26371, 4.78601);
            _mapView.MapZoom         = 18;

            // add markers.
            // _mapView.AddMarker (from);
            _mapView.AddMarker(to);

            // add control.
            var textView = new UITextView();

            textView.Text            = "Hey, now there's text on top of the map! Yay!";
            textView.BackgroundColor = UIColor.FromWhiteAlpha(0.5f, 0.5f);
            var textViewControl = new MapControl <UITextView>(textView, from, MapControlAlignmentType.CenterBottom, 75, 75);

            _mapView.AddControl(textViewControl);

            // create the route tracker animator.
            // _routeTrackerAnimator = new RouteTrackerAnimator(_mapView, routeTracker, 5, 17);

//			// simulate a number of gps-location update along the calculated route.
//			Timer timer = new Timer(250);
//			timer.Elapsed += new ElapsedEventHandler(TimerHandler);
//			timer.Start();

            View = _mapView;
        }