[英]Trigger Google map click event with zoom javascript
Is there any way to add an click event with zoom? 有什么方法可以添加带有缩放的点击事件? I am able to perform both individually, but when I use zoom together with a click event it is not working properly. 我可以单独执行这两项操作,但是当我将zoom和click事件一起使用时,它不能正常工作。
google.maps.event.trigger(gmarkers[count], "click");
map.setZoom(parseInt(k));
Please refer this jsfiddle: http://jsfiddle.net/Uw9Qy/ 请参考以下jsfiddle: http : //jsfiddle.net/Uw9Qy/
An example found here: http://www.geocodezip.com/v3_MW_example_map3_clustered.html 在此处找到示例: http : //www.geocodezip.com/v3_MW_example_map3_clustered.html
In your fiddle, you have defined the myClick function (which gets triggered as you click one of the text links), but that function doesn't contain any zoom code. 在您的小提琴中,您定义了myClick函数(单击文本链接之一时触发该函数),但是该函数不包含任何缩放代码。
Try this: 尝试这个:
Change the onclick on your <b>
tags, add a zoomlevel to it 更改您的<b>
标记的onclick,为其添加一个缩放级别
<b onclick="myclick(0, 11)">Berlin</b>-<b onclick="myclick(1, 8)">Paris</b>-<b onclick="myclick(2, 9)">Rome</b>
Then, add a paramter to your myclick function so you can zoom in: 然后,将参数添加到myclick函数中,以便您可以放大:
this.myclick = function (i, zoomlevel) {
google.maps.event.trigger(gmarkers[i], 'click');
map.setZoom(zoomlevel);
};
function createMarker() {
var marker = new google.maps.Marker({
position: z,
map: map,
title: title,
html: contentstring
});
google.maps.event.addListener(marker, 'click', function () {
map.setCenter(marker.getPosition());
map.setZoom(10);
infowindow.setContent(this.html);
infowindow.open(map, marker);
});
//google.maps.event.addListener(marker,'click',function(){
//window.location.href = marker.url;
//});
gmarkers[ids] = marker;
};
Specify your desired zoom level in setZoom() :) 在setZoom()中指定所需的缩放级别:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.