开发者

Freeze Google Map until user clicks

I'm fairly new to Google Maps API, so spare the flame :)

How do I disable the controls of a google开发者_运维百科 map(i.e. scroll, drag etc.) untill a user clicks on the map itself? I want the user to be able to scroll down on a page without ending up scrolling on the map. Due to design decisions the map appears in a position often hit by a scrolling user.

I don't want to use a static map, since I still want the user to be able to use the map, when he feels the need to do so.

Any ideas?


The map has methods to enable and disable dragging. You could just create the map with dragging disabled, and call enableDragging() whenever you want.


Add a mouse click listener to the map div, which calls enableScrollWheelZoom. You could also destroy the listener after it's called the first time.

jQuery example:

$("#mapDiv").click(function() {
    map.enableScrollWheelZoom();
});

The API reference indicates that scroll wheel zoom is disabled by default - if it's enabled because of any other calls you've made (such as setUIToDefault), just disable it first.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜