我有一个功能性 gmap,当我单击标记时,它会显示标记并显示信息窗口。现在,当我悬停与该标记相关的列表项时,我想显示一个信息窗口。我已经测试了很多东西,但信息窗口从不显示。
我的物品是这样的<li class="shop" data-shop="markerId">
还有我的js:
function initShopsMap(shops, myLatlng) {
createMap('map-canvas', myLatlng);
var infoWindow = new google.maps.InfoWindow();
for (var i = 0, length = shops.length; i < length; i++) {
var data = shops[i],
latLng = new google.maps.LatLng(data.latitude, data.longitude);
// Creating a marker and putting it on the map
var marker = new google.maps.Marker({
position: latLng,
map: map,
id: data.id,
name: data.name,
slug: data.slug,
infoWindow: infoWindow
});
(function(marker) {
// Attaching a click event to the current marker
google.maps.event.addListener(marker, 'click', function(e) {
infoWindow.setContent(marker.name + ' ' + marker.slug);
infoWindow.open(map, marker);
});
//hover list item when hover a marker
google.maps.event.addListener(marker, 'mouseover', function(e) {
//todo scroll to
$('.shop[data-shop="'+marker.id+'"]').addClass('active');
});
google.maps.event.addListener(marker, 'mouseout', function(e) {
$('.shop[data-shop="'+marker.id+'"]').removeClass('active');
});
})(marker, data);
}
}
如何添加$('.shop[data-shop="'+marker.id+'"]')
显示相关信息窗口的事件?
编辑:解决的问题google.maps.event.trigger(markers[myPoint-1], "click");
与 IIFE 配合得很好