예제 #1
0
        public static MapWindowForm OpenMapWindow(MainWindow ownerWindow, bool showCoastline = false)
        {
            MapWindowForm mwf = MapWindowForm.GetInstance();

            if (mwf.Visibility == Visibility.Visible)
            {
                MapWindowForm.BringIntoView();
            }
            else
            {
                MapWindowForm = mwf;
                MapWindowForm.LocationChanged += MapWindowForm_LocationChanged;
                MapWindowForm.Closing         += MapWindowForm_Closing;
                MapWindowForm.Owner            = ownerWindow;
                MapWindowForm.ParentWindow     = ownerWindow;
                MapWindowForm.Show();

                MapLayersHandler      = MapWindowForm.MapLayersHandler;
                MapInterActionHandler = MapWindowForm.MapInterActionHandler;
                ShapefileAttributeTableManager.MapInterActionHandler = MapInterActionHandler;
                AOIManager.Setup();
                MapControl = MapWindowForm.MapControl;
                if (!MapStateFileExists)
                {
                    LoadCoastline(CoastLineFile);
                    MapControl.TileProvider = tkTileProvider.ProviderNone;
                }
                else if (Coastline == null && showCoastline)
                {
                    LoadCoastline(CoastLineFile);
                }
            }


            if (MapLayersWindow != null)
            {
                MapLayersWindow.Visibility = Visibility.Visible;
                MapLayersWindow.BringIntoView();
            }

            if (ShapeFileAttributesWindow != null)
            {
                ShapeFileAttributesWindow.Visibility = Visibility.Visible;
                ShapeFileAttributesWindow.BringIntoView();
            }
            MapLayersViewModel = new MapLayersViewModel(MapLayersHandler);

            return(mwf);
        }
예제 #2
0
        public static void RestoreMapState(MapWindowForm mwf)
        {
            string path = $"{AppDomain.CurrentDomain.BaseDirectory}/mapstate.txt";

            if (File.Exists(path))
            {
                double extentsLeft        = 0;
                double extentsRight       = 0;
                double extentsTop         = 0;
                double extentsBottom      = 0;
                bool   hasCoastline       = false;
                bool   isCoastlineVisible = false;

                if (MapControl == null || MapLayersHandler == null || MapInterActionHandler == null)
                {
                    MapControl            = mwf.MapControl;
                    MapLayersHandler      = mwf.MapLayersHandler;
                    MapInterActionHandler = mwf.MapInterActionHandler;
                }


                using (XmlReader reader = XmlReader.Create(path))
                {
                    while (reader.Read())
                    {
                        if (reader.IsStartElement())
                        {
                            switch (reader.Name)
                            {
                            case "MapState":
                                extentsLeft   = double.Parse(reader.GetAttribute("ExtentsLeft"));
                                extentsRight  = double.Parse(reader.GetAttribute("ExtentsRight"));
                                extentsTop    = double.Parse(reader.GetAttribute("ExtentsTop"));
                                extentsBottom = double.Parse(reader.GetAttribute("ExtentsBottom"));
                                hasCoastline  = reader.GetAttribute("HasCoastline") == "1";

                                if (hasCoastline)
                                {
                                    isCoastlineVisible = reader.GetAttribute("CoastlineVisible") == "1";
                                }
                                break;

                            case "Layers":
                                break;

                            case "Tiles":
                                if (reader.GetAttribute("Visible") == "0")
                                {
                                    MapControl.TileProvider = tkTileProvider.ProviderNone;
                                }
                                else
                                {
                                    string tileProvider = reader.GetAttribute("Provider");
                                    if (tileProvider != null && tileProvider.Length > 0)
                                    {
                                        MapControl.TileProvider = (tkTileProvider)Enum.Parse(typeof(tkTileProvider), tileProvider);
                                    }
                                }
                                break;

                            case "Layer":
                                switch (reader.GetAttribute("LayerKey"))
                                {
                                case "coastline":
                                    if (hasCoastline)
                                    {
                                        var coastlineFile = reader.GetAttribute("Filename");
                                        if (File.Exists(coastlineFile))
                                        {
                                            MapWindowManager.LoadCoastline(coastlineFile, isCoastlineVisible);
                                        }
                                    }
                                    break;

                                case "aoi_boundary":
                                    var layerName = reader.GetAttribute("LayerName");
                                    if (Entities.AOIViewModel.Count > 0)
                                    {
                                        var aoi = Entities.AOIViewModel.GetAOI(layerName);
                                        if (aoi != null)
                                        {
                                            aoi.MapLayerHandle = MapWindowManager.MapLayersHandler.AddLayer(aoi.ShapeFile, aoi.Name, uniqueLayer: true, layerKey: "aoi_boundary");
                                            AOIManager.UpdateAOIName(aoi.MapLayerHandle, aoi.Name);
                                        }
                                    }
                                    break;
                                }
                                break;
                            }
                        }
                    }
                }

                var ext = new Extents();
                ext.SetBounds(extentsLeft, extentsBottom, 0, extentsRight, extentsTop, 0);
                MapControl.Extents = ext;

                // MapControl.Redraw();
            }
        }