ThinkGeo.com    |     Documentation    |     Premium Support

CurrentExtent not updated for MapTools navigation


Hi, I have a simple app that displays a map and navigates it via the enabled MapTools. I also have a button to capture the current map to PDF. However I am not able to get the current viewport (what is currently displayed in the map control). I thought CurrentExtent might give me what I'm looking for, alas it doesn't; it does not reflect zooming and panning triggered by the MapTools. Am I even correct in assuming that CurrentExtent should give me that info, or am I barking up the wrong tree?


Thanx, Adrian




Adrian, 




Welcome to the community, hope you enjoy the learning and sharing here!


You guess right that CurrentExtent is the current viewport. So that doesn't work right in your app? Please make sure you are using the latest version (3.1.16) and if problem still exists, could you send us a sample? Here is a sample for you showing how to print current map on PDF using PDFExtention in WebEdition, I think that's what you want. 


gis.thinkgeo.com/Support/Dis...fault.aspx



Thanks,



Ben

 




Thank you Ben for the welcome and the help. Indeed your example works. And my application didn't. So what is different? I was able to track it to the fact that in Page_Load I store the Map into a static variable and then when I needed to fetch the current extent I am referring to this static variable. Now in C# (and VB) classes we're dealing with references, so I assumed that the static var I held on to was the same as the Map I have in the page in subsequent postbacks. They even have the same ID. But the CurrentExtent on the static var is unchanged, while it tracks the user viewport in the Map on the page. Why is that so? I am asking, because understanding the lifetime of these objects will help me prevent these kind of issues in my application in the future.


I am attaching Default.aspx.cs file that contains changes about this static issue.


Thank you,


Adrian




Adrian, 
  
 ASP.NET doesn’t keep status. It generates a web page and dispose it immediately. After a postback,  a brand new web page is generated which technically has no relationship with the previous one. For your case that means first the client side panning or zooming can not affect the Map1’s status at all, second, StaticMap only hooks up with the original Map1, in a postback, Map1 doesn’t share the same reference with staticMap any more as it’s a brand new object already. Add another button with the following codes you will see the Map1 and the staticMap are not the same. 
 
 protected void Button2_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("");
            System.Diagnostics.Debug.WriteLine(Map1.CurrentExtent.Width.ToString());
            System.Diagnostics.Debug.WriteLine(staticMap.CurrentExtent.Width.ToString());
        }
 
 Also according to my limited experience, we should try not using static variables in ASP.NET projects as sharing a variable across sessions can easily cause problems, also it might lead to some strange issues.   
  
 Hope that helps. 
  
 Thanks, 
  
 Ben