예제 #1
0
 public static AOI  SaveAOI(string name, bool isEdited = false)
 {
     if (_hAOI >= 0)
     {
         var aoi = new AOI
         {
             Name           = name,
             UpperLeftX     = _sfAOI.Extents.xMin,
             UpperLeftY     = _sfAOI.Extents.yMax,
             LowerRightX    = _sfAOI.Extents.xMax,
             LowerRightY    = _sfAOI.Extents.yMin,
             Visibility     = true,
             MapLayerHandle = _hAOI
         };
         if (!isEdited)
         {
             aoi.ID = Entities.AOIViewModel.NextRecordNumber;
             Entities.AOIViewModel.AddRecordToRepo(aoi);
         }
         else
         {
             aoi.ID = _editedAOI_ID;
             Entities.AOIViewModel.UpdateRecordInRepo(aoi);
         }
         UpdateAOIName(name);
         MapWindowManager.ResetCursor();
         return(aoi);
     }
     return(null);
 }
예제 #2
0
        public static void FormatAOI(Shapefile aoiShapeFile)
        {
            aoiShapeFile.DefaultDrawingOptions.FillTransparency = 0.25F;

            LinePattern lp = new LinePattern();


            MapWindowManager.MapLayersHandler.ClearAllSelections();
            MapWindowManager.RedrawMap();
        }
예제 #3
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();
            }
        }