如何在没有任何鼠标事件的情况下默认显示标记内容
How to show marker content by default without any mouse event?
我写了以下代码:
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();
}
}
相关文章:
- jquery-select2显示默认选择的第一个值
- 在 HTML 中选择中使用 Vue.js 和 Minimalect 显示默认值
- PHP、MySQL 和 Ajax:动态显示默认数据、选择现有数据或添加新数据
- 显示默认推文的推特按钮
- 如何声明,以便在 jquery 移动 UI 中突出显示默认选项卡
- 在高图表中显示默认的明细
- 如果数据字段为空,如何在视图中显示默认值,以角度.js表示
- 单击后响应重定向到路由器 URL 并显示默认页面
- 当挖空可观察未定义或禁用 JS 时显示默认值
- 拖放区.js删除在页面加载时创建的模拟文件时,会显示默认的添加文件消息
- 使用checkValidity进行HTML5表单验证;t显示默认的红色/橙色边框
- jQuery-如何突出显示默认菜单链接
- 如何在Meteor Iron路由器中的一条路由中不显示默认模板
- 显示默认行KnockOut.js
- 隐藏和显示默认的javascript警报
- 在CakePHP中避免在AJAX请求中显示默认布局
- 操作textarea值,以便在各种情况下显示默认消息
- 为什么引导程序日期选择器显示默认日期为2014年14月00日
- 显示默认图像,直到图像上传到图像持有人
- HTML选项-当可观察对象为null时显示默认值