点击按钮打开信息框“OUTSIDE”地图(谷歌地图v3) [英] Open infobox on button clicked "OUTSIDE" map ( google map v3 )

查看:104
本文介绍了点击按钮打开信息框“OUTSIDE”地图(谷歌地图v3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个标记。

使用此代码点击每个标记时,我能够成功打开信息框(是的,它在设置标记的循环内)

  for(var i = 0; i< markers.length; i ++){
....
...
....
google.maps.event.addListener(marker,click,function(){
//alert(this.html);
infowindow.setContent(this.html);
infowindow.open(map,this);
});
}

上面的代码工作得很好。

但是现在我希望每个标记的信息框在地图上点击的按钮上打开。

  for(var i = 0; i< markers.length; i ++){ 
....
....
....
var chandu = document.getElementById(i);
google.maps.event.addDomListener(chandu,click,function(){
infowindow.setContent(this.html);
infowindow.open(map,this);
// alert(Yo);
});
}

我有html按钮可以像这样点击

 < a href =#id =0> 0< / a> 
< a href =#id =1> 1< / a>
< a href =#id =2> 2< / a>
< a href =#id =3> 3< / a>
< a href =#id =4> 4< / a>
< a href =#id =5> 5< / a>

但是,这个html链接部分的点击并不存在。

  var chandu = document.getElementById(i); 
chandu.onclick = generateTriggerCallback(marker,click);

另外还有一个for循环函数

  function generateTriggerCallback(object,eventType){
return function(){
google.maps.event.trigger(object,eventType);
};
}

点击查看此源代码后,我想出了这个答案样本 http://gmaps-samples-v3.googlecode。 com / svn / trunk / sidebar / random-markers.html


I have multiple marker.

I successfully able to openinfo box when clicked on each marker using this code ( yes its inside a loop of setting marker )

for (var i = 0; i < markers.length; i++) {
....
....
....
 google.maps.event.addListener(marker, "click", function () {
            //alert(this.html);
            infowindow.setContent(this.html);
            infowindow.open(map, this);
        });
}

The above code work very well.

But now i want each marker's infobox to open on button clicked outside the map. I tried something this in the same loop.

for (var i = 0; i < markers.length; i++) {
....
....
....
 var chandu = document.getElementById(i);
         google.maps.event.addDomListener(chandu, "click", function(){
            infowindow.setContent(this.html);
            infowindow.open(map, this);
            //alert("Yo");
         });
}

and i have the html button to click like this

    <a href="#" id="0">0</a>
    <a href="#" id="1">1</a>
    <a href="#" id="2">2</a>
    <a href="#" id="3">3</a>
    <a href="#" id="4">4</a>
    <a href="#" id="5">5</a>

But this clicking of html link part doesn't woork

解决方案

The working solution I have now looks something like this

var chandu = document.getElementById(i);
chandu.onclick = generateTriggerCallback(marker,"click");

And there is a function out of the for loop

function generateTriggerCallback(object, eventType) {
            return function() {
                google.maps.event.trigger(object, eventType);
            };
        }

Credit: I come up with this answer after looking into the source code of this sample http://gmaps-samples-v3.googlecode.com/svn/trunk/sidebar/random-markers.html

这篇关于点击按钮打开信息框“OUTSIDE”地图(谷歌地图v3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆