Ejemplo n.º 1
0
 private void AddCircleLayer()
 {
     if (CircleLayer == null)
     {
         Mapsui.Layers.MemoryLayer      _pointlayer = new Mapsui.Layers.MemoryLayer();
         List <Mapsui.Geometries.Point> _points     = new List <Mapsui.Geometries.Point>();
         _pointlayer.DataSource = new Mapsui.Providers.MemoryProvider(_points);
         _pointlayer.Name       = "Circle";
         SymbolStyle _style = new SymbolStyle();
         string      path   = Path.Combine(appdir, largeiconpath, Path.Combine(appdir, @"MarkerImages\Circle.png"));
         if (!IconCache.ContainsKey(path))
         {
             using (FileStream fs = new FileStream(path, FileMode.Open))
             {
                 MemoryStream ms = new MemoryStream();
                 fs.CopyTo(ms);
                 int id = BitmapRegistry.Instance.Register(ms);
                 IconCache[path] = id;
             }
         }
         _style.BitmapId   = IconCache[path];
         _pointlayer.Style = _style;
         CircleLayer       = _pointlayer;
     }
     MyMapControl.Map.Layers.Add(CircleLayer);
 }
Ejemplo n.º 2
0
        public static Mapsui.Map CreateMap()
        {
            var map = new Mapsui.Map
            {
                BackColor = Mapsui.Styles.Color.Transparent,
                Home      = n => n.NavigateTo(new Mapsui.Geometries.Point(0, 0), 63000)
            };

            // OsmStreamSource source = null;
            // OsmSharp.Geo.Streams.IFeatureStreamSource features = null;
            // System.Collections.Generic.List<IFeature> features = null; ;
            NetTopologySuite.Features.FeatureCollection features = new NetTopologySuite.Features.FeatureCollection();


            // new Mapsui.Providers.MemoryProvider()
            Mapsui.Providers.IProvider source = null; // new Mapsui.Providers.MemoryProvider(features);

            Mapsui.Layers.ILayer layer = new Mapsui.Layers.MemoryLayer
            {
                Style      = null,
                DataSource = source,
                Name       = "Line"
            };

            map.Layers.Add(layer);
            return(map);
        }
Ejemplo n.º 3
0
        private Mapsui.Layers.MemoryLayer GetLabelLayer(Dictionary <MapPinType, MapPinCollection> worldpindata)
        {
            Mapsui.Layers.MemoryLayer _pointlayer = new Mapsui.Layers.MemoryLayer {
                Style = null
            };
            List <Mapsui.Geometries.Point> _points = new List <Mapsui.Geometries.Point>();
            MapPinType pintype        = worldpindata.Keys.ToList().Where(item => item.InternalName == "RoadSign").FirstOrDefault();
            string     path           = Path.Combine(appdir, largeiconpath, pintype.IconFile);
            var        memoryProvider = new Mapsui.Providers.MemoryProvider();

            //Load the image if needed
            if (!IconCache.ContainsKey(path))
            {
                using (FileStream fs = new FileStream(path, FileMode.Open))
                {
                    MemoryStream ms = new MemoryStream();
                    fs.CopyTo(ms);
                    int id = BitmapRegistry.Instance.Register(ms);
                    IconCache[path] = id;
                }
            }

            foreach (MapPin c in worldpindata[pintype].Locations)
            {
                var feature = new Mapsui.Providers.Feature
                {
                    Geometry = CurrentConvertor.ToWorldSpace(c.Location),
                };
                feature.Styles.Add(new LabelStyle
                {
                    Text               = BreakLines(c.Name, 17),
                    ForeColor          = Color.White,
                    BackColor          = new Brush(Color.Gray),
                    Halo               = new Pen(Color.Black, 2),
                    VerticalAlignment  = LabelStyle.VerticalAlignmentEnum.Bottom,
                    Offset             = new Offset(0, 14),
                    CollisionDetection = false
                });
                feature.Styles.Add(new SymbolStyle {
                    BitmapId = IconCache[path]
                });
                memoryProvider.Features.Add(feature);
            }
            _pointlayer.DataSource = memoryProvider;
            return(_pointlayer);
        }
Ejemplo n.º 4
0
 public MarkerViewModel(MapPinType pintype, Mapsui.Layers.MemoryLayer layer)
 {
     Name           = pintype.InternalName;
     Text           = pintype.Name;
     _layer         = layer;
     Children       = new List <MarkerViewModel>();
     _isChecked     = _layer.Enabled;
     _smallIconName = pintype.IconFile;
     if (Properties.Settings.Default.MarkersState.ContainsKey(Name))
     {
         _isChecked = _layer.Enabled = bool.Parse(Properties.Settings.Default.MarkersState[Name]);
     }
     else
     {
         Properties.Settings.Default.MarkersState.Add(Name, _isChecked.ToString());
     }
     Properties.Settings.Default.Save();
 }
Ejemplo n.º 5
0
        private void LoadMap(string location)
        {
            ObservableCollection <MarkerViewModel> tempmarkers = new ObservableCollection <MarkerViewModel>();

            MarkerViewModel root;
            bool            worldWasAlreadyLoaded = MarkersPerWorld.ContainsKey(location);

            if (worldWasAlreadyLoaded)
            {
                root = MarkersPerWorld[location];
            }
            else
            {
                root = MarkerViewModel.CreateRoot(Path.Combine(appdir, smalliconpath));
                MarkersPerWorld.Add(location, root);
            }

            currentLocation  = location;
            CurrentConvertor = ConversionLibrary[location];
            if (tileLayer != null)
            {
                //fixes memory leak in Mapsui
                tileLayer.AbortFetch();
                MyMapControl.Map.Layers.Clear();
            }

            MbTilesTileSource _source = new MbTilesTileSource(new SQLiteConnectionString(PathLibrary[location], false));

            tileLayer = new Mapsui.Layers.TileLayerAbort(_source);
            MyMapControl.Map.Layers.Add(tileLayer);
            Dictionary <MapPinType, MapPinCollection> worldpindata = mappindata.GetPins(ShortNameLookup[location]);

            foreach (MapPinType pintype in worldpindata.Keys)
            {
                //I want to do this last
                if (pintype.InternalName == "RoadSign")
                {
                    continue;
                }

                if (worldWasAlreadyLoaded)
                {
                    MyMapControl.Map.Layers.Add(root.FindChild(pintype.InternalName).AssociatedLayer);
                    continue;
                }

                Mapsui.Layers.MemoryLayer _pointlayer = new Mapsui.Layers.MemoryLayer {
                    Style = null
                };
                List <Mapsui.Geometries.Point> _points = new List <Mapsui.Geometries.Point>();
                string path = Path.Combine(appdir, largeiconpath, pintype.IconFile);

                //Load the image if needed
                if (!IconCache.ContainsKey(path))
                {
                    using (FileStream fs = new FileStream(path, FileMode.Open))
                    {
                        MemoryStream ms = new MemoryStream();
                        fs.CopyTo(ms);
                        int id = BitmapRegistry.Instance.Register(ms);
                        IconCache[path] = id;
                    }
                }

                if (pintype.InternalName.Contains("Quest"))
                {
                    foreach (MapPin c in worldpindata[pintype].Locations)
                    {
                        //Try to match Pin coords and Quest coords
                        Quest q = progressStatus.getQuestByCoordinates(Convert.ToInt32(c.Location.X), Convert.ToInt32(c.Location.Y));
                        //If no matching quest found then still display the Pin
                        bool questNotDoneOrNotFound = q == null || !q.Done;
                        if (questNotDoneOrNotFound)
                        {
                            _points.Add(CurrentConvertor.ToWorldSpace(c.Location));
                        }
                    }
                }
                else
                {
                    foreach (MapPin c in worldpindata[pintype].Locations)
                    {
                        _points.Add(CurrentConvertor.ToWorldSpace(c.Location));
                    }
                }

                _pointlayer.DataSource = new Mapsui.Providers.MemoryProvider(_points);

                SymbolStyle _style = new SymbolStyle();


                _style.BitmapId   = IconCache[path];
                _pointlayer.Style = _style;

                _pointlayer.Name = pintype.Name;
                MyMapControl.Map.Layers.Add(_pointlayer);
                root.AddChild(new MarkerViewModel(pintype, _pointlayer));
            }
            root.VerifyCheckState();
            AddCircleLayer();
            //Add label layer last so that it's on top
            MyMapControl.Map.Layers.Add(GetLabelLayer(worldpindata));
            MyMapControl.Map.BackColor = new Color(184, 222, 230);
            tempmarkers.Add(root);
            _markers = tempmarkers;
            RaisePropertyChanged("Markers");
            if (RandomPlayersOnMap)
            {
                ToggleGwentPlayers(true);
            }
            else
            {
                MarkerViewModel gw = Markers[0].FindChild("GwentPlayer");
                if (gw != null)
                {
                    gw.IsChecked = false;
                }
            }

            MyMapControl.Refresh();
        }