I need to be able to change the GoogleMap type (Normal, Satellite, Hybrid, etc) once the map is drawn after a postback, as the type doesn't seem to be retained. Based on a guess, I have implemented a JavaScript function, onMapCreated(map){} and this function is called after the map is drawn. In the function, I use the command "Map1.SetCurrentBackgroundMapType(G_SATELLITE_MAP);" however, after a postback, it seems that onMapCreated(map) gets called before the map is actually drawn because at that point, the DOM doesn't know anything about Map1 and I am getting an error ('Map1' is null or not an object). What other JavaScript functions are available for us to use, and is this documentation listed on your site anywhere (I haven't found it).
Thanks,
Tom
What other JavaScript functions are available?
Tom,
I recreated the issue but not very sure about your scenario. Here are some scenarios as following.
1, if you want to keep the GoogleMap type be Satellite all the time, even after a postback, the code is like following.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Map1.BackgroundMap.GoogleMap.Name = "Google Map";
Map1.BackgroundMap.GoogleMap.GoogleMapType = GoogleMapType.Satellite;
Map1.BackgroundMap.GoogleMap.LibraryUri = new Uri("maps.google.com/maps?file=api&v=2&key=ABQIAAAAu6q_1FGrswj3A6sHtn7tshQwDYsTE1Tx03TJFyCqrcvRGAWYkBT1Y4BceXxzPDZv1EZHNn1vW4in1Q");
}
}
2, if you want to change the GoogleMap type after a PostBack, you can code as following:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Map1.CurrentExtent = new RectangleShape(-131.22, 55.05, -54.03, 16.91);
Map1.BackgroundMap.GoogleMap.Name = "Google Map";
Map1.BackgroundMap.GoogleMap.GoogleMapType = GoogleMapType.Satellite;
Map1.BackgroundMap.GoogleMap.LibraryUri = new Uri("maps.google.com/maps?file=api&v=2&key=ABQIAAAAu6q_1FGrswj3A6sHtn7tshQwDYsTE1Tx03TJFyCqrcvRGAWYkBT1Y4BceXxzPDZv1EZHNn1vW4in1Q");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Map1.BackgroundMap.GoogleMap.GoogleMapType = GoogleMapType.Normal;
}
}
3, If you changed the GoogleMap type in Client part let’s say using client method “Map1.SetCurrentBackgroundMapType(G_SATELLITE_MAP);" and want to keep that type after a postback, that’s a bit difficult. You need to save the info to the html hidden text and in server part, you need to retrieve it back yourself. Can you let me know what scenario you want first and if the problem still exists, we can have a further look.
Ben
Ben,
Thanks for your extensive reply…I feel kind of silly as I made this issue too hard. I actually forgot about the GoogleMapType…which I set initially iin the Page_Load method. In my interface on the web page, I have a RadioButtonList which lists the 4 different map types (Satellite, Hybrid, etc…). When it gets changed via JavaScript/Ajax, there is no postback, but when I do something else, I do have a postback. So, in the server-side code, I check which radio button was set and then use a switch() statement to set Map1.BackgroundMap.GoogleMap.GoogleMapType to the appropriate value. Since I forgot about that, I thought I had to do it on the client side.
Thanks again,
Tom
Tom,
Based on a lot of feedback we have gotten in the next Beta release of the web we plan to have a new system in place to work with the client side layers (1-2 weeks away). Instead of hiding them with server side code we are going to directly expose them more on the server. In this way there will be more transparency on what is happening and you will have access to more option that are currently now only available using client side code. I have said too much already but just to let you know it is coming. There will be some code changes needed on your end but in the end it will be a good move forward.
David