示例#1
0
        private MemoryLayer GetPoiLayer(Route route)
        {
            var layer = new MemoryLayer
            {
                DataSource = new MemoryProvider(
                    route.Waypoints
                    .OfType <PointOfInterest>()
                    .ToList()
                    .Select(poi => new Feature
                {
                    Geometry = SphericalMercator.FromLonLat(poi.Longitude, poi.Latitude)
                })
                    ),
                IsMapInfoLayer = true,
                Style          = new SymbolStyle
                {
                    BitmapId     = GetBitmapIdForEmbeddedResource("FamilieWandelPad.RouteImager.Assets.Pin.svg"),
                    SymbolScale  = 1d,
                    SymbolOffset = new Offset(0.0, 0.5, true),
                    Enabled      = true
                }
            };

            return(layer);
        }
示例#2
0
        private void LocatorOnPositionChanged(object sender, PositionEventArgs positionEventArgs)
        {
            var position = positionEventArgs.Position;

            _deviceLocation.Geometry = SphericalMercator.FromLonLat(position.Longitude, position.Latitude);
            OnDataChanged(new DataChangedEventArgs());
        }
        public void Update(Route route)
        {
            _memoryProvider.Clear();
            _memoryProvider.ReplaceFeatures(
                route.Waypoints.Select(routePoint =>
            {
                switch (routePoint)
                {
                case WayPoint wp:
                    return(new WaypointFeature
                    {
                        RoutePoint = wp,
                        Geometry = SphericalMercator.FromLonLat(wp.Longitude, wp.Latitude)
                    });

                case PointOfInterest poi:
                    return(new PointOfInterestFeature
                    {
                        RoutePoint = poi,
                        Geometry = SphericalMercator.FromLonLat(poi.Longitude, poi.Latitude)
                    });

                default:
                    throw new NotImplementedException();
                }
            })
                );

            DataHasChanged();
        }
示例#4
0
        private ILayer LayerRouteW(Route route)
        {
            var p = new System.Collections.Generic.List <Point>();

            foreach (Coordinate coordinate in route.Shape)
            {
                var spherical = SphericalMercator.FromLonLat(coordinate.Longitude, coordinate.Latitude);
                p.Add(new Point(spherical.X, spherical.Y));
            }
            var ls = new LineString(p);
            var f  = new Feature
            {
                Geometry = ls,
                ["Name"] = "Line 1",
                Styles   = new List <IStyle> {
                    new VectorStyle {
                        Line = new Pen(Color.Blue, 6)
                    }
                }
            };

            return(new MemoryLayer
            {
                Name = "Route",
                DataSource = new MemoryProvider(f),
                Style = null
            });
        }
示例#5
0
        private static void NavigateToPoland(Map map)
        {
            map.NavigateTo(map.Resolutions[6]);
            var centerPoland = SphericalMercator.FromLonLat(19.226, 52.039);

            map.NavigateTo(centerPoland);
        }
示例#6
0
        public MapsUiView()
        {
            Map = new Mapsui.Map
            {
                BackColor = Color.White,
                Home      = n => n.NavigateTo(SphericalMercator.FromLonLat(52.22002, 4.55835), 0.2)
            };
            IsMyLocationButtonVisible = false;
            IsNorthingButtonVisible   = false;
            IsZoomButtonVisible       = false;
            MyLocationEnabled         = false;

            CancellationTokenSource cancelToken = null;

            TouchStarted += (sender, args) => _isPanning = true;
            TouchEnded   += async(sender, args) =>
            {
                cancelToken?.Cancel();
                cancelToken = new CancellationTokenSource();

                try {
                    await Task.Delay(2000, cancelToken.Token);

                    _isPanning = false;
                }
                catch (OperationCanceledException) {}
            };

            Navigator = new AnimatedNavigatorWithRotation(Map, (IViewport)Viewport);
        }
示例#7
0
        public void AddPoint(double lat, double lon, double speed)
        {
            if (_positionLayer != null)
            {
                MemoryProvider dataSource = ((MemoryProvider)((MemoryLayer)_positionLayer).DataSource);
                dataSource.Features.Clear();
                dataSource.Features.Add(new Feature()
                {
                    Geometry = SphericalMercator.FromLonLat(lon, lat)
                });
                MapControl.RefreshData();

                if (_track)
                {
                    double offset = 0.05;
                    if (speed < 30)
                    {
                        offset = 0.001;
                    }
                    else if (speed < 60)
                    {
                        offset = 0.005;
                    }
                    MoveToArea(lat, lon, offset);
                }
            }
        }
示例#8
0
        private static Features GetStops()
        {
            // Prepare a features variable, and build the data to populate it.
            var features = new Features();
            List <StopsLocations> list = new List <StopsLocations>();

            list.Add(new StopsLocations("someday", 115.85713, -31.95496));
            list.Add(new StopsLocations("something", 115.859821, -31.958627));

            // Add each stop as a feature to features.
            foreach (var stop in list)
            {
                // Get the coordinates for each stop.
                var          coordinates = SphericalMercator.FromLonLat(stop.X, stop.Y);
                List <Style> styles      = new List <Style>();

                // Styles are usefull for adding a group of elements to the map, you can add more than a label if you like.
                styles.Add(new LabelStyle {
                    Text = stop.Name
                });

                // Add the new Feature to Features.
                features.Add(new Feature
                {
                    Geometry  = coordinates,
                    ["Label"] = stop.Name,
                    Styles    = styles.ToArray()
                });
            }
            // Return the features.
            return(features);
        }
示例#9
0
        public MapView()
        {
            InitializeComponent();

            var ubication = new Point(-3.7025600, 40.4165000);
            var sphericalMercatorCoordinate = SphericalMercator.FromLonLat(ubication.X, ubication.Y);

            var mapControl = new MapsUIView();


            mapControl.NativeMap.NavigateTo(sphericalMercatorCoordinate);
            mapControl.NativeMap.Layers.Add(OpenStreetMap.CreateTileLayer());
            mapControl.NativeMap.NavigateTo(mapControl.NativeMap.Resolutions[9]);



            var layer = GenerateIconLayer();

            mapControl.NativeMap.Layers.Add(layer);
            mapControl.NativeMap.InfoLayers.Add(layer);

            ContentGrid.Children.Add(mapControl);

            mapControl.NativeMap.Info += (sender, args) =>
            {
                var layername    = args.MapInfo?.Layer.Name;
                var featureLabel = args.MapInfo.Feature?["Label"]?.ToString();
                var featureType  = args.MapInfo.Feature?["Type"]?.ToString();

                if (featureType != null && featureType.Equals("Point"))
                {
                    ShowPopup(featureLabel);
                }
            };
        }
示例#10
0
        private void DrawMarkers(IEnumerable <Land> landPieces)
        {
            if (landPieces == null)
            {
                return;
            }

            ClearGraphics();

            foreach (var land in landPieces)
            {
                var sphericalMid = SphericalMercator.FromLonLat(land.Longitude, land.Latitude);
                var feature      = new Feature
                {
                    Geometry = new Mapsui.Geometries.Point(sphericalMid.x, sphericalMid.y)
                };
                var symbolStyle = new SymbolStyle {
                    Symbol = GetSymbol("warning.png"), SymbolType = SymbolType.Rectangle
                };
                feature.Styles.Add(symbolStyle);

                source.Features.Add(feature);
            }

            Current.Instance.MapControl.OnViewChanged(true);
        }
示例#11
0
        public static void ZoomToHexagon(MapControl mapcontrol, string geohex)
        {
            var zone = GeoHex.Decode(geohex);

            if (zone == null)
            {
                var ws = new WarningScreen("Sorry this land is not available");
                ws.Show();
                return;
            }

            var       coordinates          = zone.getHexCoords();
            var       sphericalTopLeft     = SphericalMercator.FromLonLat(coordinates[0].Longitude, coordinates[1].Latitude);
            var       sphericalBottomRight = SphericalMercator.FromLonLat(coordinates[3].Longitude, coordinates[4].Latitude);
            const int marge = 8000;

            mapcontrol.ZoomToBox(new Mapsui.Geometries.Point(sphericalTopLeft.x - marge, sphericalTopLeft.y - marge), new Mapsui.Geometries.Point(sphericalBottomRight.x + marge, sphericalBottomRight.y + marge));

            //TODO: Blergh awfull dirty dirty hack to show hexagon after zoomToHexagon (problem = Extend is a center point after ZoomToBox)
            mapcontrol.ZoomIn();
            mapcontrol.ZoomOut();

            var hexLayer = (HexagonLayer)Current.Instance.LayerHelper.FindLayer(Constants.Hexagonlayername);

            hexLayer.UpdateHexagonsInView();
            Current.Instance.MapControl.OnViewChanged(true);
        }
示例#12
0
        private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (isTracking)
            {
                Array lines = data.ToArray();
                parsed = ParseNmea(lines);

                ReceivedTextBox.Text = "";
                //foreach (KeyValuePair<string, string> entry in parsed)
                //{
                //    ReceivedTextBox.AppendText(entry.Key + ": " + entry.Value + "\n");
                //    ReceivedTextBox.ScrollToEnd();
                //}
                ReceivedTextBox.AppendText("time: " + parsed["time"]);
                ReceivedTextBox.AppendText("\nlongitude: " + parsed["lon_readable"]);
                ReceivedTextBox.AppendText("\nlatitude: " + parsed["lat_readable"]);
                ReceivedTextBox.AppendText("\nsatellites: " + parsed["sats"]);


                map = new Map();
                map.Layers.Add(OpenStreetMap.CreateTileLayer());
                var center = CalcPosition();
                var sphericalMercatorCoordinate = SphericalMercator.FromLonLat(center.X, center.Y);
                map.Home         = n => n.NavigateTo(sphericalMercatorCoordinate, map.Resolutions[9]);
                MyMapControl.Map = map;

                worker.RunWorkerAsync();
            }
        }
示例#13
0
        private void UpdateLayer_Points()
        {
            var newFeaturesNormalPoints = new List <IFeature>();

            var selectedTour = _selectedTours.FirstOrDefault();

            if ((selectedTour != null) &&
                (_selectedTours.Count == 1))
            {
                foreach (var actWaypoint in selectedTour.Waypoints)
                {
                    // Create point
                    var point = SphericalMercator.FromLonLat(
                        actWaypoint.RawWaypointData.Longitude,
                        actWaypoint.RawWaypointData.Latitude);
                    var feature = new Feature();
                    feature.Geometry = point;
                    feature.Styles.Add(new LabelStyle()
                    {
                        Text    = actWaypoint.RawWaypointData.Name,
                        Opacity = 0.8f,
                        Offset  = new Offset(0, 1.0, isRelative: true)
                    });
                    newFeaturesNormalPoints.Add(feature);
                }
            }

            _layerPointsProvider.ReplaceFeatures(newFeaturesNormalPoints);
            _layerPoints.DataHasChanged();
        }
示例#14
0
        public MapPage()
        {
            InitializeComponent();

            SataticPoints = new List <Point>();
            Point point = SphericalMercator.FromLonLat(34.7609650, 32.0477280);

            SataticPoints.Add(point);

            mapView.MoveToCenter(new Position(32.0477280d, 34.7609650d));
            mapView.PropertyChanged += (s, e) => System.Diagnostics.Debug.WriteLine(e.PropertyName);
            mapView.Map.Layers.Add(OpenStreetMap.CreateTileLayer());

            SataticPoints.Add(new Point(mapView.Map.Envelope.Left, mapView.Map.Envelope.Bottom));
            SataticPoints.Add(new Point(mapView.Map.Envelope.Right, mapView.Map.Envelope.Top));
            //mapView.Map.Layers.Add(CreatePolygonLayer());
            //mapView.Map.Layers.Add(CreateLayerWithStyleOnLayer(mapView.Map.Envelope, 10));
            mapView.Map.Layers.Add(CreateLayerWithStyleOnFeature(mapView.Map.Envelope, 10));


            //mapView.Map.Layers.Add(new TileLayer(KnownTileSources.Create(KnownTileSource.OpenStreetMap)) { Name = "Open Street Map" });
            //mapView.Map.Widgets.Add(new ScaleBarWidget {

            mapView.Map.Viewport.ViewportChanged += (s, e) => System.Diagnostics.Debug.WriteLine(e.PropertyName);
        }
示例#15
0
        public MainWindow()
        {
            InitializeComponent();

            RouteController = new RouteController(this);

            UpdateRoute(RouteController.Route);

            // MapControl.Map.Layers.Add(GetKaagTileLayer());
            MapControl.Map.Layers.Add(new TileLayer(KnownTileSources.Create(KnownTileSource.OpenStreetMap)));
            MapControl.Map.Layers.Add(RouteLayer);
            MapControl.Map.Layers.Add(RoutePointsLayer);
            MapControl.Map.Layers.Add(SectionsLayer);
            MapControl.Map.Layers.Add(SectionPointsLayer);

            MapControl.Map.Home = navigator => navigator.NavigateTo(SphericalMercator.FromLonLat(4.55835, 52.22002), 6);

            var wayPointEditor = new WaypointEditor(MapControl, RouteController);
            var sectionEditor  = new SectionEditor(MapControl, RouteController);

            sectionEditor.OnDeselected();

            WaypointModeOption.Checked += (sender, args) => SetEditor(wayPointEditor);
            SectionModeOption.Checked  += (sender, args) => SetEditor(sectionEditor);
            ScreenshotButton.Click     += (sender, args) => Screenshot();

            WaypointModeOption.IsChecked = true;
        }
示例#16
0
        public ActionResult Index(int x, int y, int z)
        {
            var ymax = 1 << z;

            y = ymax - y - 1;
            var memoryStream = new MemoryStream();

            using (var bitmap = new Bitmap(256, 256))
                using (var g = Graphics.FromImage(bitmap))
                    using (var pen = new Pen(Color.Blue, 2.0f))
                    {
                        g.CompositingMode    = CompositingMode.SourceOver;
                        g.CompositingQuality = CompositingQuality.HighQuality;
                        var boundsGeographyLL = GetBoundingBoxInLatLng(x, y, z);
                        if (boundsGeographyLL.Bottom > 0)
                        {
                            var states  = new GeometryDataSource().Query(boundsGeographyLL.ToSqlGeography(), "states");
                            var builder = new GraphicsPathBuilder(SphericalMercator.FromLonLat(boundsGeographyLL), new Size(256, 256));
                            foreach (var state in states)
                            {
                                var geography = (SqlGeography)state["geom"];
                                {
                                    using (var gp = builder.Build(geography))
                                    {
                                        g.DrawPath(pen, gp);
                                    }
                                }
                            }
                        }
                        bitmap.Save(memoryStream, ImageFormat.Png);
                    }
            return(File(memoryStream.ToArray(), "image/png"));
        }
示例#17
0
        private IFeature CreateFeature()
        {
            var feature = new Feature();
            var point   = SphericalMercator.FromLonLat(Location.X, Location.Y);

            feature.Geometry = point;
            return(feature);
        }
示例#18
0
 public static IMarker CreateCustomMarker(Context context)
 {
     return(new Marker(context)
     {
         GeoPosition = SphericalMercator.FromLonLat(18.423889, -33.925278),
         View = CreateCustomView(context)
     });
 }
示例#19
0
        public async Task <List <Marker> > GetAllMarkers()
        {
            Debug.WriteLine("MarkerService.GetAllMarkers() called.");

            List <MarkerDto> markerDtos = null;
            var json = string.Empty;

            try
            {
                json = await _client.GetStringAsync($"/?q=mobileapi/markersjson.json");

                Debug.WriteLine("Loaded marker json:");
                Debug.WriteLine(json);
            }
            catch (Exception e)
            {
                Debug.WriteLine("Error fetching markersjson: " + e.ToString());
                // TODO: Show error to user.
            }
            try
            {
                markerDtos = JsonConvert.DeserializeObject <List <MarkerDto> >(json);
            }
            catch (JsonReaderException e)
            {
                Debug.WriteLine("Error parsing markersjson: " + e.ToString());
            }
            List <Marker> markersList = new List <Marker>();
            int           tempNodeId  = 1;

            foreach (MarkerDto markerDto in markerDtos)
            {
                string label = _htmlHelper.ExtractText(markerDto.title);

                try
                {
                    double lat       = Double.Parse(markerDto.Coordinates[0]);
                    double longitude = Double.Parse(markerDto.Coordinates[1]);
                    // Format (Long, Lat)
                    // Zoom to marker location
                    var currentMarker = new Mapsui.Geometries.Point(longitude, lat);
                    // OSM uses spherical mercator coordinates. So transform the lon lat coordinates to spherical mercator
                    Point  sphericalMercatorCoordinate = SphericalMercator.FromLonLat(currentMarker.X, currentMarker.Y);
                    string description = "Marker is located in city of " + _htmlHelper.ExtractText(markerDto.City)
                                         + " and county: " + _htmlHelper.ExtractText(markerDto.County);
                    var marker = new Marker(label, tempNodeId.ToString(), sphericalMercatorCoordinate, description);
                    marker.Latitude  = lat;
                    marker.Longitude = longitude;
                    markersList.Add(marker);
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Ignoring marker with bad or missing GPS location data! GPS coordinates are in invalid format for this marker: " + label + " exception: " + e.ToString());
                }
            }

            return(markersList);
        }
示例#20
0
        public PrimerMapa()
        {
            InitializeComponent();

            var mapControl = new Mapsui.UI.Forms.MapControl();

            mapControl.Map.Layers.Add(OpenStreetMap.CreateTileLayer());

            mapControl.Map.Widgets.Add(new ScaleBarWidget(mapControl.Map)
            {
                TextAlignment       = Alignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Top
            });

            mapControl.Map.Widgets.Add(new ZoomInOutWidget()
            {
                MarginX = 20,
                MarginY = 40
            });

            var gdl = lugares.First(x => x.Nombre == "Guadalajara");

            var coordenada         = new Point(gdl.Longitud, gdl.Latitud);
            var coordenadaMercator = SphericalMercator.FromLonLat(coordenada.X, coordenada.Y);

            mapControl.Map.Home = n => n.NavigateTo(coordenadaMercator, mapControl.Map.Resolutions[9]);

            var layer = GenerateIconLayer();

            layer.IsMapInfoLayer = true;
            mapControl.Map.Layers.Add(layer);

            mapControl.Info += (sender, args) =>
            {
                var layername    = args.MapInfo.Layer?.Name;
                var featureLabel = args.MapInfo.Feature?["Label"]?.ToString();
                var featureType  = args.MapInfo.Feature?["Type"]?.ToString();

                if (!string.IsNullOrWhiteSpace(featureLabel))
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        ShowPopup(featureLabel, featureType);
                    });
                }

                Debug.WriteLine("Info Event was invoked.");
                Debug.WriteLine("Layername: " + layername);
                Debug.WriteLine("Feature Label: " + featureLabel);
                Debug.WriteLine("Feature Type: " + featureType);

                Debug.WriteLine("World Position: {0:F4} , {1:F4}", args.MapInfo.WorldPosition?.X, args.MapInfo.WorldPosition?.Y);
                Debug.WriteLine("Screen Position: {0:F4} , {1:F4}", args.MapInfo.ScreenPosition?.X, args.MapInfo.ScreenPosition?.Y);
            };

            ContentGrid.Children.Add(mapControl);
        }
示例#21
0
 private LineString RenderPath(Route route)
 {
     return(new LineString
     {
         Vertices = route.Waypoints
                    .Select(wp => SphericalMercator.FromLonLat(wp.Longitude, wp.Latitude))
                    .ToList()
     });
 }
 public PointOfInterestLayer(IEnumerable <PointOfInterest> pointOfInterests)
 {
     DataSource = new MemoryProvider(pointOfInterests.Select(poi => new PointOfInterestFeature(poi)
     {
         Geometry = SphericalMercator.FromLonLat(poi.Longitude, poi.Latitude)
     }));
     IsMapInfoLayer = true;
     Style          = CreateSvgStyle("FamilieWandelPad.Assets.pin.svg", 0.8);
 }
示例#23
0
        private void FocusOnLocation(Map map, Navigator navigator)
        {
            var center = NotableCoordinates.Volgograd;
            //convert to spherical mercator coordinates
            var osmCoordinates = SphericalMercator.FromLonLat(center.X, center.Y);
            var mapResolutions = map.Resolutions;

            navigator.NavigateTo(osmCoordinates, mapResolutions[12]);
        }
示例#24
0
        public static Point OffsetMeters(this Point point, double dx, double dy)
        {
            const double EarthRadius = 6_371_000;
            Point        lonLat      = SphericalMercator.ToLonLat(point.X, point.Y);
            var          newLon      = lonLat.X + (dx / EarthRadius) * (180 / Math.PI) / Math.Cos(lonLat.Y * Math.PI / 180);
            var          newLat      = lonLat.Y + (dy / EarthRadius) * (180 / Math.PI);

            return(SphericalMercator.FromLonLat(newLon, newLat));
        }
示例#25
0
        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            var sphericalMercatorCoordinate = SphericalMercator.FromLonLat(Convert.ToDouble(Longitude.Text), Convert.ToDouble(Latitude.Text));

            MyMapControl.Map.NavigateTo(sphericalMercatorCoordinate);
            MyMapControl.Map.NavigateTo(MyMapControl.Map.Resolutions[18]);
            MyMapControl.Map.Layers.Add(OpenStreetMap.CreateTileLayer());
            MyMapControl.Map.Layers.Add(Auxiliary.CreatePointLayer(sphericalMercatorCoordinate));
        }
示例#26
0
        //TODO
        private static IEnumerable <IFeature> GenerateLinesAndMarkers(Route route)
        {
            var line = new LineString
            {
                Vertices = (
                    from c in route.Shape
                    select SphericalMercator.FromLonLat(c.Longitude, c.Latitude)).ToList()
            };

            var lineFeature = new Feature()
            {
                Geometry = line,
                Styles   = new List <IStyle>()
                {
                    new SymbolStyle()
                    {
                        Line = new Pen()
                        {
                            Color        = Color.Blue,
                            PenStyle     = PenStyle.Solid,
                            Width        = 7,
                            PenStrokeCap = PenStrokeCap.Round
                        },
                        Opacity = 0.7f
                    }
                }
            };

            var markerStartFeature = new Feature()
            {
                Geometry = route.Stops[0].Coordinate.ToWorld(),
                Styles   = new List <IStyle>()
                {
                    new SymbolStyle()
                    {
                        BitmapId = GetBitmapIdForEmbeddedResource(MarkerAName), SymbolScale = 0.5
                    }
                }
            };

            var markerFinishFeature = new Feature()
            {
                Geometry = route.Stops[1].Coordinate.ToWorld(),
                Styles   = new List <IStyle>()
                {
                    new SymbolStyle()
                    {
                        BitmapId = GetBitmapIdForEmbeddedResource(MarkerBName), SymbolScale = 0.5
                    }
                }
            };

            return(new List <Feature> {
                lineFeature, markerStartFeature, markerFinishFeature
            });
        }
示例#27
0
        void UpdateUserPosPoints()
        {
            var feature = new Feature();
            var point   = SphericalMercator.FromLonLat(UserPosition.Longitude.Degrees, UserPosition.Latitude.Degrees);

            feature.Geometry = point;
            feature["name"]  = "User";

            UserPosPointsLayer.DataSource = new MemoryProvider(feature);
        }
        public MainWindow()
        {
            InitializeComponent();

            var point          = new Point(8.542693, 47.368659);
            var sphericalPoint = SphericalMercator.FromLonLat(point.X, point.Y);

            MyMapControl.Map.NavigateTo(sphericalPoint);
            MyMapControl.Map.Viewport.Resolution = 12;
        }
        public void ShowRoutes()
        {
            Routes.Clear();

            List <QuestionList> questionLists = DBContext.Instance.QuestionLists.Where(x => x.Festival.Id == _festival.Id).ToList();
            List <Inspection>   inspections   = new List <Inspection>();

            foreach (QuestionList list in questionLists)
            {
                List <Inspection> listInspections = DBContext.Instance.Inspections.Where(x => x.QuestionList.Id == list.Id).ToList();
                foreach (Inspection add in listInspections)
                {
                    inspections.Add(add);
                }
            }

            foreach (Inspection inspection in inspections)
            {
                Employee employee = inspection.Employee;
                try
                {
                    var    responseRoute = _geodan.FindRoute($"&from={employee.City}%20{employee.Street}%20{employee.HouseNumber}&to={_festival.City}%20{_festival.Street}%20{_festival.HouseNumber}&srs=epsg:28992&returntype=coords&outputformat=json");
                    var    geometry      = responseRoute.features[0].geometry;
                    string code          = $"{geometry.type} (";
                    foreach (var coord in geometry.coordinates)
                    {
                        var i  = coord[0];
                        var sm = SphericalMercator.FromLonLat((float)coord[0], (float)coord[1]);
                        code += $"{sm.X} {sm.Y}".Replace(",", ".") + ", ";
                    }
                    code = code.Remove(code.Length - 2, 2) + ")";
                    var geoRoute = GeometryFromWKT.Parse(code);

                    var routeLayer = new Layer
                    {
                        DataSource = new MemoryProvider(geoRoute),

                        Style = new VectorStyle
                        {
                            Line = new Pen(Color.Black, 3),
                        }
                    };

                    MapControl.Map.Layers.Add(routeLayer);
                    Routes.Add(new RouteData(routeLayer, employee, (double)responseRoute.features[0].properties.route_distance, (double)responseRoute.features[0].properties.route_duration));
                }
                catch (NoRouteException)
                {
                    //No valid route was found
                    MessageBox.Show($"Geen route gevonden voor {employee.Name},\nControleer het adres van het festival en de medewerker.", "Geen route gevonden");
                    Routes.Add(new RouteData(null, employee, 999.9, 59940));
                }
            }
            UpdateRouteColors();
        }
示例#30
0
        public static Mapsui.Map CreateMap()
        {
            var map = new Mapsui.Map();

            map.Layers.Add(OpenStreetMap.CreateTileLayer());
            var b = CreateMbTilesLayer(mbpath);

            if (b != null)
            {
                map.Layers.Add(b);
            }
            var c = CreateMbTilesLayer(mbpath2);

            if (c != null)
            {
                map.Layers.Add(c);
            }

            // Get the lon lat coordinates from somewhere (Mapsui can not help you there)
            var centerOfLondonOntario = new Point(-81.2497, 42.9837);
            // OSM uses spherical mercator coordinates. So transform the lon lat coordinates to spherical mercator
            var sphericalMercatorCoordinate = SphericalMercator.FromLonLat(centerOfLondonOntario.X, centerOfLondonOntario.Y);

            // Set the center of the viewport to the coordinate. The UI will refresh automatically
            // Additionally you might want to set the resolution, this could depend on your specific purpose

            map.Layers.Add(CreatePointLayer());
            map.Layers.Add(CreateLayer());
            map.Layers.Add(CreateLineStringLayer());
            map.Layers.Add(new RasterizingLayer(CreateRandomPointLayer()));//, pixelDensity: pixelDensity));
            //map.Layers.Add(CreateMbTilesLayer());

            //mapView.Map.Layers.Add(CreateLineStringLayer());

            //mapView.Map.Viewport.Center = new Mapsui.Geometries.Point(-46.4, -23.2);
            //mapView.Rotation = false;
            // mapView.UnSnapRotationDegrees = 30;
            //mapView.ReSnapRotationDegrees = 5;

            //mapView.ev += OnPinClicked;
            //mapView.MapClicked += OnMapClicked;

            //mapView.la.UpdateMyLocation(new UI.Forms.Position());

            // mapView.Info += MapView_Info;

            //var abc = Task.Run(() => StartGPS());

            //setup(mapView);

            //Clicker = c;
            map.Home = n => n.NavigateTo(sphericalMercatorCoordinate, map.Resolutions[9]);

            return(map);
        }