【发布时间】:2014-12-01 04:16:04
【问题描述】:
我正在开发一个有地图的网站,我正在使用传单。现在我将隐藏/显示我制作的标记。
下面是我的代码找到我想要的图像并将其用作标记
var Icon1 = L.icon({
iconUrl: 'legends/fire.GIF',
iconSize: [170, 120], // size of the icon
iconAnchor: [100, 120], // point of the icon which will correspond to marker's location
popupAnchor: [-7, -80] // point from which the popup should open relative to the iconAnchor
下面的另一个是我在地图上标记时的代码。
function mark()
{
if (select1.value === "Fire"){
var note = document.getElementById('note');
var datepick = document.getElementById('demo1');
var timepick = document.getElementById('timepick');
map.on('click', function(e){
var marker = new L.Marker(e.latlng,{icon: Icon1});
marker.bindPopup("</a><br><strong>FIRE</strong></br><strong>Date:</strong>"+datepick.value+"</br><strong>Time:</strong>"+timepick.value+"</br><strong>Address:</strong>"+note.value+"<strong><br><strong>Suspect Sketch</strong><br><a href=legends/suspect.jpg rel=lightbox><img src = legends/suspect.jpg height=100 width = 100/>").addTo(map);
marker.on('dragend');
});
这是我隐藏标记的代码。
script type="text/javascript">
function closure(marker){
var checkbox = document.getElementById("chbx")
$(chbx).click(function(){
if(map.hasLayer(marker)){
window.alert("I want to hide the marker");
}
window.alert("I want to show the marker");
})
}
</script>
这正是我想要的。 1.在地图上添加一个标记 2.隐藏/显示地图中的标记 3.在运行时或尝试时实现。
我尝试了一切,但仍然没有任何反应。 在复选框中调用我的隐藏/显示功能的正确做法是什么?
【问题讨论】:
-
对不起,由于使用不当我已经更改了它,我希望有人能帮助我,因为我仍然对这部分有疑问。
标签: javascript html hide show leaflet