Esempio n. 1
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--;
                });
            }
        }
Esempio n. 2
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;
            };
        }