Exemplo n.º 1
0
        private void MapControlOnMouseRightButtonDown(object sender, MouseButtonEventArgs args)
        {
            var mapsPos = args.GetPosition(MapControl).ToMapsui();
            var info    = MapControl.GetMapInfo(mapsPos, 12);


            polyDraw = new ActiveMarker
            {
                id      = GameState.Instance.marker.GenerateMarkerName(MarkerChannel.Global),
                channel = 0,
                color   = "ColorBlack",
                type    = "hd_dot",
                shape   = "POLYLINE",
                text    = "",
                size    = "1,1",
                alpha   = 1,
                dir     = 0,
                brush   = "Solid"
            };


            polyDraw.pos.Clear();
            polyDraw.pos.Add((float)info.WorldPosition.X);
            polyDraw.pos.Add((float)info.WorldPosition.Y);

            polyDraw.polyline.Add(new float[] { (float)info.WorldPosition.X, (float)info.WorldPosition.Y });

            var markerProvider = MapMarkersLayer.DataSource as MapMarkerProvider;

            markerProvider?.AddMarker(polyDraw, false);
            MapMarkersLayer.DataHasChanged();
            //MapControl.Refresh(ChangeType.Discrete);
            args.Handled = true;
        }
Exemplo n.º 2
0
        private void UpdateLayer_LoadedGpxFiles()
        {
            var newFeatures = new List <IFeature>();

            foreach (var actTour in _loadedTours)
            {
                foreach (var actTourSegment in actTour.Segments)
                {
                    var actGeometry = actTourSegment.Points.GpxWaypointsToMapsuiGeometry(actTour, actTourSegment);
                    if (actGeometry == null)
                    {
                        continue;
                    }

                    newFeatures.Add(new Feature()
                    {
                        Geometry = actGeometry,
                        Styles   =
                        {
                            this.GetLineStyle(actTour.RawTourExtensionData.State)
                        }
                    });
                }
            }
            _layerLoadedGpxFilesProvider.ReplaceFeatures(newFeatures);
            _layerLoadedGpxFiles.DataHasChanged();
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
0
        private static ILayer CreateMutatingTriangleLayer(BoundingBox envelope)
        {
            var layer = new MemoryLayer();

            var polygon = new Polygon(new LinearRing(GenerateRandomPoints(envelope, 3)));
            var feature = new Feature()
            {
                Geometry = polygon
            };
            var features = new Features();

            features.Add(feature);

            layer.DataSource = new MemoryProvider(features);

            PeriodicTask.Run(() =>
            {
                polygon.ExteriorRing = new LinearRing(GenerateRandomPoints(envelope, 3));
                // Clear cache for change to show
                feature.RenderedGeometry.Clear();
                // Trigger DataChanged notification
                layer.DataHasChanged();
            },
                             TimeSpan.FromMilliseconds(1000));

            return(layer);
        }
Exemplo n.º 5
0
        private void MapControlOnMouseLeftButtonDown(object sender, TouchedEventArgs e)
        {
            var info = MapControl.GetMapInfo(e.ScreenPoints.First(), 12);

            //GPSEditPopup.IsOpen = false;
            if (info.Feature is GPSTrackerFeature gpsTrackerFeature)
            {
                //GPSEdit.Tracker = gpsTrackerFeature.Tracker;
                //GPSEditPopup.Placement = PlacementMode.Mouse;
                //GPSEditPopup.StaysOpen = false;
                //GPSEditPopup.AllowsTransparency = true;
                //GPSEditPopup.IsOpen = true;
                //e.Handled = true;
            }

            if (polyDraw == null && CanDraw)
            {
                polyDraw = new ActiveMarker
                {
                    id      = GameState.Instance.marker.GenerateMarkerName(MarkerChannel.Global),
                    channel = 0,
                    color   = "ColorBlack",
                    type    = "hd_dot",
                    shape   = "POLYLINE",
                    text    = "",
                    size    = "1,1",
                    alpha   = 1,
                    dir     = 0,
                    brush   = "Solid"
                };

                polyDraw.pos.Clear();
                polyDraw.pos.Add((float)info.WorldPosition.X);
                polyDraw.pos.Add((float)info.WorldPosition.Y);

                polyDraw.polyline.Add(new float[] { (float)info.WorldPosition.X, (float)info.WorldPosition.Y });

                var markerProvider = MapMarkersLayer.DataSource as MapMarkerProvider;
                markerProvider?.AddMarker(polyDraw, false);
                MapMarkersLayer.DataHasChanged();
            }
        }
Exemplo n.º 6
0
        private void UpdateLayer_SelectedGpxFiles()
        {
            var boxBuilder = new NavigationBoundingBoxBuilder();

            var newFeatures = new List <IFeature>();

            foreach (var actTour in _selectedTours)
            {
                foreach (var actTourSegment in actTour.Segments)
                {
                    var actGeometry = actTourSegment.Points.GpxWaypointsToMapsuiGeometry(actTour, actTourSegment);
                    if (actGeometry == null)
                    {
                        continue;
                    }

                    boxBuilder.AddGeometry(actGeometry);

                    newFeatures.Add(new Feature()
                    {
                        Geometry = actGeometry,
                        Styles   = { _lineStyleSelected }
                    });
                }
            }
            _layerSelectedGpxFilesProvider.ReplaceFeatures(newFeatures);
            _layerSelectedGpxFiles.DataHasChanged();

            var currentViewPort  = this.TryGetCurrentViewport();
            var selectedRouteBox = boxBuilder.TryBuild();

            if ((selectedRouteBox != null) &&
                (currentViewPort != null) &&
                (!currentViewPort.Contains(selectedRouteBox)))
            {
                this.ResetCamera(_selectedTours);
            }
        }
Exemplo n.º 7
0
        private static ILayer CreateMutatingTriangleLayer(MRect?envelope)
        {
            var layer = new MemoryLayer();

            var polygon = new Polygon(new LinearRing(GenerateRandomPoints(envelope, 3).ToArray()));
            var feature = new GeometryFeature(polygon);

            layer.Features = new List <IFeature> {
                feature
            };

            PeriodicTask.RunAsync(() =>
            {
                feature.Geometry = new Polygon(new LinearRing(GenerateRandomPoints(envelope, 3).ToArray()));
                // Clear cache for change to show
                feature.RenderedGeometry.Clear();
                // Trigger DataChanged notification
                layer.DataHasChanged();
            },
                                  TimeSpan.FromMilliseconds(1000));

            return(layer);
        }
Exemplo n.º 8
0
        private void GenerateLayers(List <Helper.SvgLayer> layers)
        {
            List <(MemoryLayer, Task)> layerLoadTasks = new List <(MemoryLayer, Task)>();
            int terrainWidth = 0;
            int index        = 0;

            foreach (var svgLayer in layers)
            {
                if (svgLayer.content.GetSize() > 5e7) //> 50MB
                {
                    //#TODO tell the user, this layer is too big and is skipped for safety. TacControl would use TONS of ram, very bad, usually an issue with Forest layer

                    continue;
                }



                var layer = new MemoryLayer(svgLayer.name);

                if (svgLayer.name == "forests" || svgLayer.name == "countLines" || svgLayer.name == "rocks" ||
                    svgLayer.name == "grid")
                {
                    layer.Enabled = false;
                }

                terrainWidth = svgLayer.width;

                currentBounds = new Mapsui.Geometries.BoundingBox(0, 0, terrainWidth, terrainWidth);

                var features = new Features();
                var feature  = new Feature {
                    Geometry = new BoundBox(currentBounds), ["Label"] = svgLayer.name
                };


                if (layer.Enabled)
                {
                    var x = new SvgStyle {
                        image = new Svg.Skia.SKSvg()
                    };
                    layer.Enabled = false;
                    layerLoadTasks.Add((layer,
                                        Task.Run(() =>
                    {
                        using (var stream = svgLayer.content.GetStream())
                        {
                            //var file = File.Create($"P:/{layer.Name}.svg");
                            //stream.CopyTo(file);
                            //file.Dispose();

                            x.image.Load(stream);
                        }
                    })));

                    feature.Styles.Add(x);
                }
                else
                {
                    var x = new SvgStyleLazy {
                        data = svgLayer.content
                    };
                    x.DoLoad = () =>
                    {
                        using (var stream = svgLayer.content.GetStream())
                        {
                            var image = new Svg.Skia.SKSvg();
                            image.Load(stream);
                            x.image = image;
                        }

                        layer.DataHasChanged();
                    };

                    feature.Styles.Add(x);
                }

                features.Add(feature);


                layer.DataSource = new MemoryProvider(features);
                layer.MinVisible = 0;
                layer.MaxVisible = double.MaxValue;
                MapControl.Map.Layers.Insert(index++, layer);
            }

            MapControl.Map.Limiter.PanLimits = new Mapsui.Geometries.BoundingBox(0, 0, terrainWidth, terrainWidth);


            Task.WhenAll(layerLoadTasks.Select(x => x.Item2).ToArray()).ContinueWith(x =>
            {
                Networking.Instance.MainThreadInvoke(() =>
                {
                    foreach (var(memoryLayer, item2) in layerLoadTasks)
                    {
                        memoryLayer.Enabled = true;
                    }

                    LayerList.Initialize(MapControl.Map.Layers);
                });
            });



            foreach (var markerMarkerType in GameState.Instance.marker.markerTypes)
            {
                markNum++;
                MarkerCache.Instance.GetImage(markerMarkerType.Value, (MarkerColor)null).ContinueWith((x) =>
                {
                    markerMarkerType.Value.iconImage = x.Result; //#TODO use this for markerCache caching in general, store cached images in there
                    markNum--;
                });
            }
        }
Exemplo n.º 9
0
        private void GenerateLayers(List <Helper.SvgLayer> layers)
        {
            Console.WriteLine($"MapView Layerdata arrived, creating layers...");
            List <(BaseLayer, Task)> layerLoadTasks = new List <(BaseLayer, Task)>();
            int terrainWidth = 0;
            int index        = 0;

            foreach (var svgLayer in layers)
            {
                if (svgLayer.content.GetSize() > 5e7) //> 50MB
                {
                    Console.WriteLine($"MapView !! Layer is too big, skipping layer {svgLayer.name}");
                    //#TODO tell the user, this layer is too big and is skipped for safety. TacControl would use TONS of ram, very bad, usually an issue with Forest layer

                    continue;
                }



                var layer       = new MemoryLayer(svgLayer.name);
                var renderLayer = new RasterizingLayer(layer, 100, 1D, MapControl.Renderer);

                if (svgLayer.name == "forests" || svgLayer.name == "countLines" || svgLayer.name == "rocks" ||
                    svgLayer.name == "grid")
                {
                    renderLayer.Enabled = false;
                }

                terrainWidth = svgLayer.width;

                currentBounds = new Mapsui.Geometries.BoundingBox(0, 0, terrainWidth, terrainWidth);

                var features = new Features();
                var feature  = new Feature {
                    Geometry = new BoundBox(currentBounds), ["Label"] = svgLayer.name
                };


                if (renderLayer.Enabled)
                {
                    var x = new SvgStyle {
                        image = new Svg.Skia.SKSvg()
                    };
                    renderLayer.Enabled = false;
                    layerLoadTasks.Add((renderLayer,
                                        Task.Run(() =>
                    {
                        using (var stream = svgLayer.content.GetStream())
                        {
                            //var file = File.Create($"P:/{layer.Name}.svg");
                            //stream.CopyTo(file);
                            //file.Dispose();

                            x.image.Load(stream);
                        }
                    })));

                    feature.Styles.Add(x);
                }
                else
                {
                    var x = new SvgStyleLazy {
                        data = svgLayer.content
                    };
                    x.DoLoad = () =>
                    {
                        using (var stream = svgLayer.content.GetStream())
                        {
                            var image = new Svg.Skia.SKSvg();
                            image.Load(stream);
                            x.image = image;
                        }

                        layer.DataHasChanged();
                    };

                    feature.Styles.Add(x);
                }

                features.Add(feature);


                layer.DataSource = new MemoryProvider(features);
                layer.MinVisible = 0;
                layer.MaxVisible = double.MaxValue;
                MapControl.Map.Layers.Insert(index++, renderLayer);
            }

            MapControl.Map.Limiter.PanLimits = new Mapsui.Geometries.BoundingBox(0, 0, terrainWidth, terrainWidth);


            Task.WhenAll(layerLoadTasks.Select(x => x.Item2).ToArray()).ContinueWith(x =>
            {
                Networking.Instance.MainThreadInvoke(() =>
                {
                    foreach (var(memoryLayer, item2) in layerLoadTasks)
                    {
                        memoryLayer.Enabled = true;

                        memoryLayer.DataHasChanged();
                    }

                    LayerList.Initialize(MapControl.Map.Layers);

                    MapControl.Navigator.NavigateTo(new BoundingBox(new Point(0, 0), new Point(terrainWidth, terrainWidth)));
                    MapControl.RefreshGraphics();
                });
            });

            Console.WriteLine($"MapView Layers loaded, preloading marker images from Arma...");

            foreach (var markerMarkerType in GameState.Instance.marker.markerTypes)
            {
                markNum++;
                MarkerCache.Instance.GetImage(markerMarkerType.Value, (MarkerColor)null).ContinueWith((x) =>
                {
                    markerMarkerType.Value.iconImage = x.Result; //#TODO use this for markerCache caching in general, store cached images in there
                    markNum--;
                    //if (markNum == 3) // && !ImageDirectory.Instance.HasPendingRequests()
                    //{
                    //    // all markers loaded
                    //    ImageDirectory.Instance.ExportImagesToZip("P:/markers.zip");
                    //}
                });
            }

            // hacky, we might not have markerColors available before this method.
            cmbColors.ItemsSource = GameState.Instance.marker.markerColors.Values;
            DefaultMarkerColor    = "Default";

            cmbColors.DropDownClosed += (x, y) =>
            {
                var conv = new MarkerColorStringConverter();
                DefaultMarkerColor = conv.Convert(cmbColors.SelectedItem as MarkerColor, typeof(string), null, null) as string;
            };
        }