access the map control from client side javascript?

Feb 19, 2008 at 9:40 PM
Hi there,

maybe the more general question to my last post is:

How can I access the GoogleMap control on the client side to call some of the yet unimplemented API functions on it?

Already tried a few options, but haven't found the right thing.

Would be glad to hear from you :-)

Cheers, Oliver
Coordinator
Feb 20, 2008 at 6:36 AM
Edited Feb 20, 2008 at 6:38 AM
I had that question about bounds some time ago.
Unfortunatelly, I have not much time I can spend on this control lately.
I'm busy on my work and try keeping my work on some other projects (some of them open source as well) I'm working on my spare time.
However, I'll consider implementing that soon (in the near future :)).

By then, you have to remember that GoogleMap control creates a client-side variable with same name which you can find in the control property ClientMapID and then you can access googlem map instance of GMap2 in member _gmap.

So, for example if you add you GoogleMap control to your page directly and its ID is GoogleMap1 then the name of the client-side instanse should be something like:
ctl00_GoogleMap1_Map
And if you need GMap2 object, you can get it like:
ctl00_GoogleMap1_Map._gmap

In your case, when you want to get bounds of the google map you can do it like:
var bounds = ctl00_GoogleMap1_Map._gmap.getBounds();
, where bounds returned is of type GLatLngBounds

Hope this helps and hope to be able to continue my work on this project in next days :).
My plan is to continue with release 3.0 - data binding, and next release after that should be for adding overlays (controls) to the map.
Please, do not hesitate to propose features and give feedback.

Regards
Feb 20, 2008 at 10:41 AM
Edited Feb 20, 2008 at 10:46 AM
Hi Velio,

thanks a bunch for your answer. I should have asked 24 hours earlier, because I already started using Google's Map API directly, because I didn't see how to do it. Well, anyway, thanks a lot.

For anybody else looking into here, I'm using Velio's hint now like this:

Inside an <asp:Content> tag I defined a map like this:
<artem:GoogleMap ID="artemGoogleMap" runat="server" Width="351px" Height="351px" [more options...]></artem:GoogleMap>
In my JavaScript block I now access the GoogleMap control like this:
var bounds = <%= artemGoogleMap.ClientID %>_Map._gmap.getBounds();
@Velio: Since this is kind of a hack, maybe you want to consider making the "ClientMapID" in GoogleMap.cs public ;-) Then we could just call
<%= artemGoogleMap.ClientMapID %>
and wouldn't have to worry about future adaptations to that string.

Well, take good care and good luck with your other projects, Velio! Hope to "see" you around :-)

Oliver

P.S. Now, thinking about it again, I'm wondering if there is a way to access further information of the GMap2 object (like the bounds) on the server side...
Coordinator
Feb 20, 2008 at 3:28 PM
Hi,
I'll do make that property public and will update files tonight.
Yes, it will be possible to send that data back to server-side code, like now work geolocations,
If you set Address property to GoogleMap control on the next postback you will find that locations found by that address it persisted in control's Latitude and Longitude.
Same is the case for markers.
Further more, you can attach a server-side code to the control's server-side event GeoLocationLoaded and when first time map is loaded and address is solved it is automatically do a post back to the server and in that event you can get location of the address.
For details you can look here for discussions we did with magnetica and after last release (and after I have fixed some bugs) he is able to use GoogleMap controls like this:
He has text box where adress can be entered, then that address is set to the control on wich he handles GeoLocationLoaded. In the handler he gets the location (Latitude and Longitude) and pulls up from Db a locations of object can be shown and adds markers for them on the map.

However, I hope to find time soon to finish some more demos and quick start videos.

... And you will definetely "see" me around :-).
I'm not leaving this project, as you can see I did a lot of work recently and issued many releases.
Just haven't so much free time to keep it running so fast as I want too, because I have a lot of ideas for new features as well.

Regards