我一直在阅读许多类似的帖子,看不出如何在我的代码中做到这一点……任何建议都将不胜感激。
我通过AJAX设置了许多标记,并根据JSON结果中返回的数据在地图下面创建了一个表。我想让我的数据表中的链接可点击,它将模拟点击地图上相应的标记,并打开已经为实际点击标记定义的信息窗口……
function display( json_results ) {
$("#map").gmap3({action:'clear'});
$("#map").gmap3(
{action: 'init',
options:{
center:true,
zoom:13,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
},
navigationControl: true,
scrollwheel: true,
streetViewControl: true
}
},
{action: 'addMarkers',
radius:100,
markers: json_results,
clusters:{
maxZoom: 10,
// This style will be used for clusters with more than 0 markers
20: {
content: '<div class="cluster cluster-1">CLUSTER_COUNT</div>',
width: 53,
height: 52
},
// This style will be used for clusters with more than 20 markers
50: {
content: '<div class="cluster cluster-2">CLUSTER_COUNT</div>',
width: 56,
height: 55
},
// This style will be used for clusters with more than 50 markers
100: {
content: '<div class="cluster cluster-3">CLUSTER_COUNT</div>',
width: 66,
height: 65
}
},
marker: {
options: {
//icon: new google.maps.MarkerImage('http://maps.gstatic.com/mapfiles/icon_green.png'),
clickable: true
},
events:{
click: function(marker,event,data) {
$(this).gmap3({action: 'clear', name : 'infowindow'});
$(this).gmap3({action: 'addinfowindow', anchor: marker, options: { content:
'<div class="text"><strong><div style="color:navy;">' + data.itype + '</strong><br/><div id="address" snum="' + data.streetnum + '" snam="' + data.streetnam + '" styp="' + data.streettyp + '">'+ data.iaddress +'</div><br/>' + data.inum + '<br/>'+ data.datetime +'</div><hr>'+data.notes+'</div>'} })
},
mouseover: function(marker, event, data){
$(this).gmap3(
{ action:'clear', name:'overlay'},
{ action:'addOverlay',
latLng: marker.getPosition(),
content: '<div class="infobulle">' +
'<div class="bg"></div>' +
'<div class="text">' + data.itype +'</div>' +
'</div>' +
'<div class="arrow"></div>',
offset: {
x:-46,
y:-73
}
});
},
mouseout: function(){
$(this).gmap3({action:'clear', name:'overlay'});
}
} //end events
} // end marker
}
,{action:"autofit"} //end action
);
};在加载页面和提交包含搜索结果的表单时,我从一些JQUERY调用此函数。一切都运行得很完美。现在我想在地图之外添加一个链接,它将触发点击相应的标记……
例如:<a href="javascript:google.maps.event.trigger(markers[i], "click")">See This Infowindow</a>,其中I是一个值,在传递给上面的函数时,我会同时传递lat/long和infowindow数据。我假设要发送映射的第一个数据数组为0,第二个数组为1,依此类推,因此我将第一个链接设为i=0,第二个设为i=1,依此类推…
不确定这种逻辑是否有意义,也许有更好的方法将引用传递给标记……
有人能帮我解决这个问题吗?也许是一个简单的函数,我可以将标记的值传递到我现有的代码中?或者任何你认为最好的方式...
谢谢大师!
发布于 2012-08-14 17:44:03
你有没有试着定义一个自己的函数来处理点击?
function myclick(i) {
google.maps.event.trigger(markers[i],"click");
}和
function setHTML() {
var html = "";
for (var i=0; i<markers.length; i++) {
html += '<a href="javascript:myclick(' + i + ')">' + marker[i].id + '<\/a>';
}
document.getElementById("table").innerHTML = html;
}https://stackoverflow.com/questions/11946255
复制相似问题