다음 코드를 작성했습니다.
for (var i=1; i < latitude.length; i++) {
var markerCenter = new google.maps.LatLng(latitude[i],longitude[i]);
var marker = new google.maps.Marker({
position: markerCenter,
animation: google.maps.Animation.BOUNCE
});
marker.setMap(map);
marker.setVisible(visible)
markers.push(marker);
addInfoWindow(marker,Location[i]);
}
function addInfoWindow(marker, message) {
var infoWindow = new google.maps.InfoWindow({
content: message
});
google.maps.event.addListener(marker, 'click', function () {
infoWindow.open(map, marker);
});
}
사용자가 확인란을 선택하거나 선택 취소하면 해당 마커가 작업에 따라 표시되도록 설정됩니다.
function markerVisibility(check_box,lat,lon) {
var index;
for (var i = 1; i < latitude.length; i++) {
if (latitude[i] == lat && longitude[i] == lon) {
index=i-1;
break;
}
}
//User selects the check box to see the marker in Google Map
if (check_box.checked) {
markers[index].setVisible(true)
markers[index].setAnimation(google.maps.Animation.BOUNCE);
}
//User unselects the checkbox not to see the marker
else {
markers[index].setVisible(false)
}
}
코드가 잘 작동합니다. 이 코드를 사용하여 내용을 보려면 마커를 클릭해야합니다. 하지만지도를로드하고 마커를 가리킬 때 기본적으로 마커 콘텐츠를로드해야합니다 (클릭 또는 호버링없이).
또 다른 한가지, 마커가 여전히 가시성 "false"로 설정되어 있으면 마커 내용이 표시됩니다. 가시성을 끄는 방법은 무엇입니까? 에서 제안 해주세요 JavaScript
.
정보창에 대한 이벤트 리스너를 제거하고 생성하는 즉시 엽니 다.
function addInfoWindow(marker, message) {
var infoWindow = new google.maps.InfoWindow({
content: message
});
infoWindow.open(map, marker);
}
또한 마커의 가시성이 토글 될 때 해당 정보창을 표시하거나 숨기려면 다음과 같이 할 수 있습니다.
function addInfoWindow(marker, message) {
var infoWindow = new google.maps.InfoWindow({
content: message
});
infoWindow.open(map, marker);
marker.infowindow = infoWindow;
}
function markerVisibility(check_box,lat,lon) {
...
if (check_box.checked) {
markers[index].setVisible(true);
marker.infowindow.open(map, marker);
}
else {
markers[index].setVisible(false);
marker.infowindow.close();
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다