Exemplo n.º 1
0
        private void InitializeMap(GeoPosition position)
        {
            _walkedPathLayer = new WalkedPathLayer(VisitedWaypoints, Consts.WalkedPathLayerName);
            _mapView.AddLayer(_walkedPathLayer);

            _positionLayer = new PositionLayer(position, new SymbolStyle
            {
                Fill        = new Brush(Color.FromString("#3366CC")),
                SymbolScale = 0.25,
                SymbolType  = SymbolType.Ellipse
            });
            _mapView.AddLayer(_positionLayer);

            _mapView.AddLayer(new PointOfInterestLayer(_route.Waypoints.OfType <PointOfInterest>()));

            _expectedPositionLayer = new PositionLayer(GetLastWayPoint(), new SymbolStyle
            {
                BitmapId      = GetBitMap("FamilieWandelPad.Assets.navigationArrow.svg"),
                SymbolScale   = 0.075,
                RotateWithMap = true
            });
            _mapView.AddLayer(_expectedPositionLayer);

            UpdateMap(position, GetLastWayPoint(), false);
        }
Exemplo n.º 2
0
        public void Render(object target, IReadOnlyViewport viewport, IEnumerable <ILayer> layers,
                           IEnumerable <IWidget> widgets, Color background = null)
        {
            var allWidgets = layers.Select(l => l.Attribution).ToList().Where(w => w != null).Concat(widgets).ToList();

            RenderTypeSave((Canvas)target, viewport, layers, allWidgets, background);
        }
Exemplo n.º 3
0
        public static void Draw(SKCanvas canvas, IViewport viewport, IStyle style, IGeometry geometry)
        {
            var lineString = ((LineString) geometry).Vertices;

            float lineWidth = 1;
            var lineColor = new Color();

            var vectorStyle = style as VectorStyle;

            if (vectorStyle != null)
            {
                lineWidth = (float) vectorStyle.Line.Width;
                lineColor = vectorStyle.Line.Color;
            }

            var line = WorldToScreen(viewport, lineString);
            var path = ToSkia(line);

            using (var paint = new SKPaint())
            {
                paint.IsStroke = true;
                paint.StrokeWidth = lineWidth;
                paint.Color = lineColor.ToSkia();
                paint.StrokeJoin = SKStrokeJoin.Round;

                canvas.DrawPath(path, paint);
            }
        }
Exemplo n.º 4
0
        public NetworkMap(BackgroundLayerSet backgroundLayerSet)
        {
            InitializeComponent();
            _backgroundLayerSet = backgroundLayerSet;
            _defaultColor       = Mapsui.Styles.Color.Black;
            _nodes      = new Dictionary <Mapsui.Providers.Feature, Node2>();
            _links      = new Dictionary <Mapsui.Providers.Feature, Link>();
            _nodeStyles = new Dictionary <System.Windows.Media.Color, SymbolStyle>();
            _linkStyles = new Dictionary <System.Windows.Media.Color, VectorStyle>();
            Clear();

            _nodeLegend = new Legend()
            {
                VerticalAlignment   = System.Windows.VerticalAlignment.Top,
                HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
                Margin     = new System.Windows.Thickness(5, 5, 0, 0),
                Visibility = System.Windows.Visibility.Collapsed,
            };
            _linkLegend = new Legend()
            {
                VerticalAlignment   = System.Windows.VerticalAlignment.Top,
                HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
                Margin     = new System.Windows.Thickness(5, 5, 0, 0),
                Visibility = System.Windows.Visibility.Collapsed,
            };
            root.Children.Add(_nodeLegend);
            root.Children.Add(_linkLegend);
        }
Exemplo n.º 5
0
 private void Render(Canvas canvas, IViewport viewport, IEnumerable<ILayer> layers, 
     IEnumerable<IWidget> widgets, Color background = null)
 {
     Clear(canvas, background);
     if (viewport.Initialized) Render(canvas, viewport, layers);
     Render(canvas, widgets);
 }
 public static Color Copy(this Color color)
 {
     if (color == null)
     {
         return(null);
     }
     return(new Color(color.R, color.G, color.B, color.A));
 }
Exemplo n.º 7
0
 public static WinColor ToXaml(this Color color)
 {
     if (color == null)
     {
         return(WinColor.FromArgb(0, 255, 255, 255));
     }
     return(WinColor.FromArgb((byte)color.A, (byte)color.R, (byte)color.G, (byte)color.B));
 }
Exemplo n.º 8
0
 public static IStyle CreateLineStringStyle()
 {
     return(new VectorStyle
     {
         Fill = null,
         Outline = null,
         Line = { Color = Color.FromString("Red"), Width = 4 }
     });
 }
Exemplo n.º 9
0
        private static void Clear(Canvas canvas, Color background)
        {
            canvas.Background = ToBackground(background);

            foreach (var child in canvas.Children)
            {
                (child as Canvas)?.Children.Clear();
            }

            canvas.Children.Clear();
        }
Exemplo n.º 10
0
        private void RenderTypeSave(Canvas canvas, IReadOnlyViewport viewport, IEnumerable <ILayer> layers,
                                    IEnumerable <IWidget> widgets, Color background = null)
        {
            if (!viewport.HasSize)
            {
                return;
            }

            Clear(canvas, background);
            Render(canvas, viewport, layers);
            Render(canvas, viewport, widgets);
        }
Exemplo n.º 11
0
        private static MemoryStream RenderToBitmapStreamStatic(IViewport viewport, IEnumerable <ILayer> layers, SymbolCache symbolCache,
                                                               Color background)
        {
            var canvas = new Canvas();

            Render(canvas, viewport, layers, background, symbolCache, true);
            var bitmapStream = BitmapRendering.BitmapConverter.ToBitmapStream(canvas, (int)viewport.Width, (int)viewport.Height);

            canvas.Children.Clear();
            canvas.Dispatcher.InvokeShutdown();
            return(bitmapStream);
        }
Exemplo n.º 12
0
        private static void Render(Canvas target, IViewport viewport, IEnumerable <ILayer> layers,
                                   Color background, bool rasterizing)
        {
#if !NETFX_CORE
            target.BeginInit();
#endif
            target.Background = background == null ? null : new XamlMedia.SolidColorBrush {
                Color = background.ToXaml()
            };

            target.Visibility = Visibility.Collapsed;

            foreach (var child in target.Children)
            {
                (child as Canvas)?.Children.Clear();
            }

            target.Children.Clear();

            layers = layers.ToList();

            foreach (var layer in layers)
            {
                if (!layer.Enabled)
                {
                    continue;
                }
                if (layer.MinVisible > viewport.Resolution)
                {
                    continue;
                }
                if (layer.MaxVisible < viewport.Resolution)
                {
                    continue;
                }

                RenderLayer(target, viewport, layer, rasterizing);
            }
            target.Arrange(new Rect(0, 0, viewport.Width, viewport.Height));
            target.Visibility = Visibility.Visible;

#if !NETFX_CORE
            if (DeveloperTools.DeveloperMode)
            {
                DrawDebugInfo(target, layers);
            }
#endif

#if !NETFX_CORE
            target.EndInit();
#endif
        }
Exemplo n.º 13
0
 public static ILayer CreateLineLayer(List <Feature> lines, Mapsui.Styles.Color colour)
 {
     return(new Layer("Lines")
     {
         CRS = "EPSG:3857",
         DataSource = new MemoryProvider(lines),
         IsMapInfoLayer = true,
         Style = new VectorStyle
         {
             Fill = null,
             Outline = null,
             Line =
             {
                 Color = colour,
                 Width = 5
             }
         }
     });
 }
Exemplo n.º 14
0
 public static ILayer CreatePolygonLayer(List <Feature> polygons, Mapsui.Styles.Color lineColour, Mapsui.Styles.Color fillColour)
 {
     return(new Layer("Polygons")
     {
         CRS = "EPSG:3857",
         DataSource = new MemoryProvider(polygons),
         IsMapInfoLayer = true,
         Style = new VectorStyle
         {
             Fill = new Mapsui.Styles.Brush(fillColour),
             Outline = new Pen
             {
                 Color = lineColour,
                 Width = 5,
                 PenStyle = PenStyle.Solid,
                 PenStrokeCap = PenStrokeCap.Round
             }
         }
     });
 }
Exemplo n.º 15
0
 public static ILayer CreateLayer(List <Polygon> polys, Mapsui.Styles.Color fillColor, Mapsui.Styles.Color outlineColor)
 {
     return(new Layer("Polygons")
     {
         DataSource = new MemoryProvider(polys)
         {
             CRS = "EPSG:4326"
         },
         Style = new VectorStyle
         {
             Fill = new Brush(fillColor),
             Outline = new Pen
             {
                 Color = outlineColor,
                 Width = 4,
                 PenStyle = PenStyle.Solid,
                 PenStrokeCap = PenStrokeCap.Round
             }
         }
     });
 }
Exemplo n.º 16
0
 private static CGColor ToCGColor(Mapsui.Styles.Color color)
 {
     return(new CoreGraphics.CGColor(color.R / 255f, color.G / 255f, color.B / 255f, color.A / 255f));
 }
Exemplo n.º 17
0
        public MemoryStream RenderToBitmapStream(IViewport viewport, IEnumerable <ILayer> layers, Color background = null)
        {
            MemoryStream bitmapStream = null;

            RunMethodOnStaThread(() => bitmapStream = RenderToBitmapStreamStatic(viewport, layers, background));
            return(bitmapStream);
        }
Exemplo n.º 18
0
 public void Render(object target, IViewport viewport, IEnumerable <ILayer> layers, Color background)
 {
     Render((Canvas)target, viewport, layers, background, false);
 }
Exemplo n.º 19
0
        public MemoryStream RenderToBitmapStream(IViewport viewport, IEnumerable <ILayer> layers, Color background = null)
        {
#if NETFX_CORE
            throw new NotImplementedException();
#else
            MemoryStream bitmapStream = null;
            RunMethodOnStaThread(() => bitmapStream = RenderToBitmapStreamStatic(viewport, layers, background));
            return(bitmapStream);
#endif
        }
Exemplo n.º 20
0
 public MapControl(BackgroundLayerSet backgroundLayerSet) : this()
 {
     _backgroundLayerSet = backgroundLayerSet;
     _defaultColor       = Mapsui.Styles.Color.Black;
     Clear();
 }
Exemplo n.º 21
0
 private static XamlMedia.SolidColorBrush ToBackground(Color background)
 {
     return(background == null ? null : new XamlMedia.SolidColorBrush {
         Color = background.ToXaml()
     });
 }
Exemplo n.º 22
0
        public MemoryStream RenderToBitmapStream(IReadOnlyViewport viewport, IEnumerable <ILayer> layers, Color background = null, float pixelDensity = 1)
        {
            MemoryStream bitmapStream = null;

            RunMethodOnStaThread(() => bitmapStream = RenderToBitmapStreamStatic(viewport, layers, _symbolCache));
            return(bitmapStream);
        }
Exemplo n.º 23
0
 public MemoryStream RenderToBitmapStream(IViewport viewport, IEnumerable<ILayer> layers, Color background = null)
 {
     MemoryStream bitmapStream = null;
     RunMethodOnStaThread(() => bitmapStream = RenderToBitmapStreamStatic(viewport, layers, background));
     return bitmapStream;
 }
Exemplo n.º 24
0
 public void Render(object target, IViewport viewport, IEnumerable<ILayer> layers, Color background)
 {
     Render((Canvas) target, viewport, layers, background, false);
 }
Exemplo n.º 25
0
 private static MemoryStream RenderToBitmapStreamStatic(IViewport viewport, IEnumerable<ILayer> layers, Color background)
 {
     var canvas = new Canvas();
     Render(canvas, viewport, layers, background, true);
     var bitmapStream = BitmapRendering.BitmapConverter.ToBitmapStream(canvas, (int)viewport.Width, (int)viewport.Height);
     canvas.Children.Clear();
     canvas.Dispatcher.InvokeShutdown();
     return bitmapStream;
 }
Exemplo n.º 26
0
 public static WinColor ToXaml(this Color color)
 {
     return(WinColor.FromArgb((byte)color.A, (byte)color.R, (byte)color.G, (byte)color.B));
 }
Exemplo n.º 27
0
 public static AndroidColor ToAndroid(this Color color)
 {
     return(new AndroidColor(color.R, color.G, color.B, color.A));
 }
Exemplo n.º 28
0
        private static void Render(Canvas target, IViewport viewport, IEnumerable<ILayer> layers,
            Color background, bool rasterizing)
        {
            target.BeginInit();

            target.Background = background == null ? null : new XamlMedia.SolidColorBrush {Color = background.ToXaml()};

            target.Visibility = Visibility.Collapsed;

            foreach (var child in target.Children)
            {
                (child as Canvas)?.Children.Clear();
            }

            target.Children.Clear();

            layers = layers.ToList();

            foreach (var layer in layers)
            {
                if (!layer.Enabled) continue;
                if (layer.MinVisible > viewport.Resolution) continue;
                if (layer.MaxVisible < viewport.Resolution) continue;

                RenderLayer(target, viewport, layer, rasterizing);
            }
            target.Arrange(new Rect(0, 0, viewport.Width, viewport.Height));
            target.Visibility = Visibility.Visible;

            if (DeveloperTools.DeveloperMode)
            {
                DrawDebugInfo(target, layers);
            }

            target.EndInit();
        }
Exemplo n.º 29
0
        protected override async void OnAppearing()
        {
            if (Navigator != null)
            {
                return;
            }

            await Application.Current.MainPage.Navigation.PushModalAsync(new LookingForGpsPage());

            Route route = null;

            try
            {
                route = await _routeTask;
            } catch (Exception e)
            {
                var properties = new Dictionary <string, string>
                {
                    { "Category", "Route parsing" }
                };
                Crashes.TrackError(e, properties);

                return;
            }

            try
            {
                MapView.Info += async(sender, args) =>
                {
                    args.Handled = true;
                    if (args.MapInfo.Feature is PointOfInterestFeature poif)
                    {
                        await poif.OnClick();
                    }
                };

                var routeLayer = new PathLayer(
                    route.GetEnumerable(route.Waypoints.First(), Direction.Forward),
                    Consts.MainPathLayerName
                    );
                routeLayer.Style = null;
                routeLayer.feature.Styles.Add(
                    new VectorStyle()
                {
                    Line = new Pen(Color.FromArgb(255, 48, 78, 130))
                    {
                        PenStyle = PenStyle.Solid,
                        Width    = 15d
                    }
                }
                    );
                routeLayer.feature.Styles.Add(
                    new VectorStyle()
                {
                    Line = new Pen(Color.FromArgb(255, 45, 115, 200))
                    {
                        PenStyle = PenStyle.Solid,
                        Width    = 12d
                    }
                }
                    );

                MapView.Map.Layers.Add(routeLayer);
            } catch (Exception e)
            {
                var properties = new Dictionary <string, string>
                {
                    { "Category", "Map styling" }
                };
                Crashes.TrackError(e, properties);

                return;
            }

            try
            {
                NavigationStats = new NavigationStats(route);
                Navigator       = new Navigator(MapView, route, CrossGeolocator.Current, NavigationStats);

                DistanceLabel.SetBinding(Label.TextProperty, new Binding("Progress", source: NavigationStats));

                if (await Navigator.StartNavigation())
                {
                    await Application.Current.MainPage.Navigation.PopModalAsync();
                }
            } catch (Exception e)
            {
                var properties = new Dictionary <string, string>
                {
                    { "Category", "Navigation" }
                };
                Crashes.TrackError(e, properties);

                return;
            }
        }