I need to open info window on map, when I click a link on the map page( not marker it self). Here is my code so far,
我需要在地图上打开信息窗口,当我点击地图页面上的链接时(不是自己标记)。这是我到目前为止的代码,
var marker = new MarkerWithLabel({
map: resultsMap,
id: label,
position: latlng,
title: "Address",
// radius: int_radius ,
draggable: false,
labelAnchor: new google.maps.Point(10, 35),
labelContent: label,
labelClass: "labels",
labelInBackground: false,
mapTypeId: google.maps.MapTypeId.ROADMAP,
icon: image,
customInfo: "dynamic data for each marker"
});
And calling function
并调用功能
function bindInfoWindow(resultsMap, marker, infoWindow) {
google.maps.event.addListener(marker, 'click',
function(){
infoWindow.setContent(marker.customInfo);
infoWindow.open(resultsMap,marker);
});
$(document).on('click','.store-title', function(){
var linkId = $(this).attr('id');
infoWindow.setContent(marker.customInfo);
infoWindow.open(resultsMap,marker);
});
}
In my situation I can't use an array to store markers. Is there way to get marker.customInfo by using condition like below? Please Note When I click on marker it works. I need it for latter onclick function.
在我的情况下,我不能使用数组来存储标记。有没有办法通过使用下面的条件获得marker.customInfo?请注意当我点击标记时它会起作用。我需要它用于后面的onclick功能。
infoWindow.setContent(marker.customInfo where marker.id==linkId);
1 个解决方案
#1
0
This might work, keeping it inside your bindInfoWindow
as you currently have it:
这可能有效,将其保存在您当前拥有的bindInfoWindow中:
$(document).on('click','.store-title', function() {
var linkId = $(this).attr('id');
if (linkId == marker.id) {
google.maps.event.trigger(marker, 'click');
}
});
Notice I'm passing the - not needed it seems.marker
as a data parameter to the click event handle, but you maybe don't need to do that.
请注意,我将标记作为数据参数传递给click事件句柄,但您可能不需要这样做。 - 似乎不需要。
And then I just trigger the click on that marker, rather than repeat the code that you've already got in the marker's click handler.
然后我只是触发该标记的点击,而不是重复你已经在标记的点击处理程序中获得的代码。
I'm assuming the id
property you're adding to each marker is the same as the 'id' attribute you're reading on your links. If not, can you have some identical property on the markers and links that you can check.
我假设您添加到每个标记的ID属性与您在链接上读取的“id”属性相同。如果没有,您可以在标记和链接上找到相同的属性。
#1
0
This might work, keeping it inside your bindInfoWindow
as you currently have it:
这可能有效,将其保存在您当前拥有的bindInfoWindow中:
$(document).on('click','.store-title', function() {
var linkId = $(this).attr('id');
if (linkId == marker.id) {
google.maps.event.trigger(marker, 'click');
}
});
Notice I'm passing the - not needed it seems.marker
as a data parameter to the click event handle, but you maybe don't need to do that.
请注意,我将标记作为数据参数传递给click事件句柄,但您可能不需要这样做。 - 似乎不需要。
And then I just trigger the click on that marker, rather than repeat the code that you've already got in the marker's click handler.
然后我只是触发该标记的点击,而不是重复你已经在标记的点击处理程序中获得的代码。
I'm assuming the id
property you're adding to each marker is the same as the 'id' attribute you're reading on your links. If not, can you have some identical property on the markers and links that you can check.
我假设您添加到每个标记的ID属性与您在链接上读取的“id”属性相同。如果没有,您可以在标记和链接上找到相同的属性。