gpt4 book ai didi

javascript - 如何将标记悬停在 MarkerWithLabel Google map 上

转载 作者:行者123 更新时间:2023-12-03 04:32:07 25 4
gpt4 key购买 nike

我在 Google map 上使用 MarkerWithLabel,当我将鼠标悬停在标记上时,它不显示对话框信息。它仅在单击标记时显示。我有一些CSS如下:

<style>     
.labels {
margin-top:-3px;
padding: 5px;
position: absolute;
visibility: visible;
z-index: 1030;
}
.labels.active .inner {
background: cyan;
}
.labels.hover .inner {
background-color: yellow;
}
.labels .arrow{
border-top-color: #ff5a5f;
border-right-color: rgba(0,0,0,0);
border-bottom-color: rgba(0,0,0,0);
border-left-color: rgba(0,0,0,0);
border-width: 5px 5px 0;
bottom: 0;
left: 50%;
margin-left: -5px;
border-style: solid;
height: 0;
position: absolute;
width: 0;
}
.labels .inner{
background-color: #ff5a5f;
border-radius: 4px;
color: #FFFFFF;
max-width: 200px;
padding: 3px 8px;
text-align: center;
text-decoration: none;
}
.labels.active .arrow {
border-top-color: #00ffff;
border-right-color: rgba(0,255,255,0);
border-bottom-color: rgba(0,255,255,0);
border-left-color: rgba(0,255,255,0);
}
.labels.hover .arrow {
border-top-color: #ffff00;
border-right-color: rgba(255,255,0,0);
border-bottom-color: rgba(255,255,0,0);
border-left-color: rgba(255,255,0,0);
}

和 JavaScript:

    function initMap() {
var latlng = new google.maps.LatLng(21.0241852,105.8292388);
var map = new google.maps.Map(document.getElementById('map_canvas'), {
zoom: 16, /*16*/
center: latLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
});

var cityHightlight;
//DRAW THE POLYGON OR POLYLINE
cityHightlight = new google.maps.Polygon({
paths: hanois,
strokeColor: "#F85555",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#FFFFFF",
fillOpacity: 0.35
});
cityHightlight.setMap(map);

// create a bounds object
var bounds = new google.maps.LatLngBounds();
var latLng = new google.maps.LatLng(23.23333, 105.2325512);

bounds.extend(latLng);
var markerMap = new MarkerWithLabel({
position: latLng,
draggable: true,
raiseOnDrag: true,
map: map,
labelContent: "<div class='arrow'></div><div class='inner'>998888</div>",
labelAnchor: new google.maps.Point(30, 30),
labelClass: "labels", // the CSS class for the label
isClicked: false
});

var windowDialog = new google.maps.InfoWindow({
content: "<img height='180px' width='300px' src='images.car.jpg' />"
+"<h5>855555</h5>"
+"Infor of dialog marker"
+ "<br>"
});
google.maps.event.addListener(markerMap, "click", function (e) { windowDialog.open(map, this); });
map.fitBounds(bounds);
}
initMap();

当鼠标悬停在标记上并显示对话框突出显示时如何解决此问题,非常感谢!!

最佳答案

您的代码中有一个点击监听器

google.maps.event.addListener(markerMap, "click", function (e) { 
windowDialog.open(map, this);
});

但是对于悬停,您应该使用 mouseover 和 mouseout,例如使用 infowindow

markerMap.addListener('mouseover', function() {
infowindow.open(map, this);
});

// assuming you also want to hide the infowindow when user mouses-out
markerMap.addListener('mouseout', function() {
infowindow.close();
});

关于javascript - 如何将标记悬停在 MarkerWithLabel Google map 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43445865/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com