I want to store the current extent of the map to restore it the next time the user starts a new session. I am just storing them in an ASCII text file. CenterX, CenterY and CenterScale all have values, but all I am able to get is a blank map. Map.CurrentExtent = queryLayer.GetBoundingBox() works fine. So clearly I am not even close. Also how do I remove the double spacing from the code I posted below? I will get the hang of this eventually.
This is what the INI file looks like when I open it with Notepad. -96.7581572906396=CenterX 32.6156794078906=CenterY 288374.897460938=CenterScale This is what I am using to get the values to save to the INI file. CenterScale = Map.CurrentScale.ToString CenterX = Map.CurrentExtent.GetCenterPoint().X.ToString CenterY = Map.CurrentExtent.GetCenterPoint().Y.ToString Then I stop and restart the application and pass those values back to the app. Oh, this is Desktop Edition 6.0. I think my scale is way off. Did this make it any clearer?
The following code works properly on my side, please get it and follow the steps below,
Public Class DisplayShapeMap Inherits UserControl Public Sub New() InitializeComponent() End Sub
Private Sub DisplayMap_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load winformsMap1.MapUnit = GeographyUnit.DecimalDegree winformsMap1.BackgroundOverlay.BackgroundBrush = New GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean)
Dim shapefileLayer As New ShapeFileFeatureLayer("../../sampledata/data/countries02.shp") shapefileLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1 shapefileLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
Dim overlay As New LayerOverlay overlay.Layers.Add(shapefileLayer) winformsMap1.Overlays.Add(overlay)
winformsMap1.CurrentExtent = New RectangleShape(-139.2, 92.4, 120.9, -93.2)
'comment this line when load the program for the second time winformsMap1.Refresh() End Sub
Private Sub save_Click(sender As System.Object, e As System.EventArgs) Handles save.Click Dim centerX = winformsMap1.CurrentExtent.GetCenterPoint().X Dim centerY = winformsMap1.CurrentExtent.GetCenterPoint().Y
Dim scale = winformsMap1.CurrentScale
File.WriteAllText("a.txt", centerX.ToString + "," + centerY.ToString + "," + scale.ToString) End Sub
Private Sub load_Click(sender As System.Object, e As System.EventArgs) Handles load.Click Dim result = File.ReadAllText("a.txt") Dim results = result.Split(",")
winformsMap1.CenterAt(New PointShape(Convert.ToDouble(results(0)), Convert.ToDouble(results(1)))) winformsMap1.ZoomToScale(Convert.ToDouble(results(2))) winformsMap1.Refresh() End Sub End Class
1. Load the program, click save button and exit.
2. Comment the line: winformMap1.Refresh() and rerun it.
I replaced the two lines in my else statement with the two from your post… Map.CenterAt(New PointShape(Convert.ToDouble(CenterX), Convert.ToDouble(CenterY))) Map.ZoomToScale(Convert.ToDouble(CenterScale)) All preliminary tests are showing favorable results, BRAVO Edgar! You do not know how much this has helped.