简体   繁体   English

谷歌地图缩放控制事件

[英]google maps zoom control event

On this website: 在此网站上:

http://www.crunchpanorama.com/ http://www.crunchpanorama.com/

you use the google maps zoom control slider to zoom and recluster markers. 您可以使用Google地图缩放控制滑块来缩放和隐藏标记。 I want to capture this event as well and perform actions accordingly. 我也想捕获此事件并相应地执行操作。

Problem is when reading google docs, all I could find is the zoom_changed event of map. 问题是在阅读Google文档时,我只能找到map的zoom_changed事件。 However, this event is not only called when changing zoom using slider, but also when clicking marker (which zooms into marker). 但是,此事件不仅在使用滑块更改缩放时被调用,而且在单击标记(放大到标记)时也会被调用。 So zoom_changed will not help me: 所以zoom_changed对我没有帮助:

google.maps.event.addListener(map, 'zoom_changed', function () {
...

I want to be able to target the zoom change on the control slider specifically. 我希望能够专门针对控制滑块上的缩放更改。 How can I go about this? 我该怎么办?

Maybe there's a workaround similar to this: 也许有类似的解决方法:

var self = this;
google.maps.event.addListener(marker, 'click', function() {
    // Set a boolean variable to true to indicate a marker/cluster has been clicked
    self._markerClicked = true;
});

google.maps.event.addListener(map, 'zoom_changed', function() {
    // Check the boolean variable and run your code if it's false
    if ( !self._markerClicked ) {
        // Take action here
    } else {
        // Reset variable back to false
        self._markerClicked = false;
    }
});

Ran into this recently. 最近碰到这个。 This is the best solution I have found if you want to capture when the map default zoom buttons are clicked. 如果要在单击地图默认缩放按钮时捕获,这是我找到的最佳解决方案。 This assumes that the zoom buttons are the only ones in the div map container. 这假定在div映射容器中只有缩放按钮。

$("#id-container-name").on("click", "button", whateverfunction());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM