Zoom and Center'ing with Map Markers Questions

172 views
Skip to first unread message

Maio

unread,
Jan 17, 2011, 12:00:22 PM1/17/11
to google-map...@googlegroups.com
Hi,

I just have a couple of queries regarding centering after zooming. I have used Team Maps in the past (Map Channels) and liked some of the extra functionality:
1, When you click a map marker and the infoWindow appears, if you click to the maximum zoom level, the map marker location becomes the center of the map, can this be done in API v3?
2, The map I have created toggles between KML layers, e.g. hotels, bars, shops etc, so when the new KML is loaded, if only map marker exists, the map recenters and zooms to the location, again is this possible please?

Link

Thanks for any help,

Mark.

geoco...@gmail.com

unread,
Jan 17, 2011, 1:23:24 PM1/17/11
to Google Maps JavaScript API v3
On Jan 17, 9:00 am, Maio <mai...@gmail.com> wrote:
> Hi,
>
> I just have a couple of queries regarding centering after zooming. I have
> used Team Maps in the past (Map Channels) and liked some of the extra
> functionality:
> 1, When you click a map marker and the infoWindow appears, if you click to
> the maximum zoom level, the map marker location becomes the center of the
> map, can this be done in API v3?

Yes. How depends on what you mean by "if you click to the maximum
zoom level"

I think what you want is to center the map on a KmlMouseEvent
http://code.google.com/apis/maps/documentation/javascript/reference.html#KmlMouseEvent

then clicking on the zoom control would keep the marker centered.

> 2, The map I have created toggles between KML layers, e.g. hotels, bars,
> shops etc, so when the new KML is loaded, if only map marker exists, the map
> recenters and zooms to the location, again is this possible please?

KmlLayer does what KmlLayer does (which I believe is zoom to show the
bounds, unless you tell it not to), what it does for a single marker,
I don't know. If you know that there is only one marker in the kml,
you could set the viewport appropriately.

-- Larry

>
> Link <http://www.maiocv.com/test/MapV3API.html>

Maio

unread,
Jan 17, 2011, 2:31:27 PM1/17/11
to google-map...@googlegroups.com
Larry,

thanks for the reply...

1, I assume that I need an addListener() to capture for the kmlMouseEvent, then re-center and zoom? I'll have to read up up on that aspect GM's.

2, At the moment the current GM doesn't show the bounds, is there something I need to check?

Thank you again, and much appreciated,

Mark.

geoco...@gmail.com

unread,
Jan 17, 2011, 2:40:08 PM1/17/11
to Google Maps JavaScript API v3
On Jan 17, 11:31 am, Maio <mai...@gmail.com> wrote:
> Larry,
>
> thanks for the reply...
>
> 1, I assume that I need an addListener() to capture for the kmlMouseEvent,
> then re-center and zoom? I'll have to read up up on that aspect GM's.

Yes.

>
> 2, At the moment the current GM doesn't show the bounds, is there something
> I need to check?

I don't know what you mean by "show the bounds". If you want it to
automatically center and zoom on the kml, you need to change the
preserveViewport option of the KmlLayer to false (or not specify it).

-- Larry

Maio

unread,
Jan 18, 2011, 8:23:08 AM1/18/11
to google-map...@googlegroups.com
Hi Larry,

1, Managed to use addListener in the toggleKML().

        google.maps.event.addListener(kmlArray[i], 'click', function(kmlEvent){
                  objMap.setCenter(kmlEvent.latLng);});


Am I correct in thinking that the listener must be added and removed per toggle of the KML layer?

    google.maps.event.clearListeners(kmlArray[iLastID], 'click');


2, I removed "preserveViewport" option and all worked as expected ;-)

Link

Best wishes,

Mark,

Reply all
Reply to author
Forward
0 new messages