如果标记值已在数据库中生成,如何在地图中隐藏标记值

How to hide marker value in map if the markers value has been generated in the database

获取name字段等于'VAWC'的位置等信息的代码:

<?php 
$db = new PDO('mysql:host=localhost;dbname=poi', 'root', ''); 
$sql = "SELECT name,user_date,user_time,address,lat,lng,icon_name FROM tblmarker where name = 'VAWC'"; 

$rs = $db->query($sql); 
if (!$rs) { 
    echo "An SQL error occured.\n"; 
    exit; 
} 

$rows = array(); 
while($r = $rs->fetch(PDO::FETCH_ASSOC)) { 
    $rows[] = $r; 
    $name[] = $r['name'];
    $user_date[] = $r['user_date'];
    $user_time[] = $r['user_time'];
    $address[] = $r['address'];
    $icon_name[] = $r['icon_name'];
} 
print json_encode($rows); 
$db = NULL; 
?> 

Ajax 获取数据并生成标记的请求:

var vawc = L.icon({
    iconUrl: '../legends/7.gif',
        iconSize:     [50, 50], // size of the icon
    iconAnchor:   [23, 50], // point of the icon which will correspond to marker's location
    popupAnchor:  [3, -50] // point from which the popup should open relative to the iconAnchor
});

function getInfo6() { 
    $.getJSON("datalegends/vawc.php", function (data) { 
      for (var e = 0; e < data.length; e++) { 
        var location6 = new L.LatLng(data[e].lat, data[e].lng); 
        var marker6 = new L.Marker(location6,{icon:vawc}); 
           marker6.bindPopup(
              data[e].name + "<br>" + 
               data[e].user_date + "<br>" + 
               data[e].user_time + "<br>" + 
               data[e].address + "<br>"
           ).addTo(map);
           marker6.on('click', function(e) { // HERE YOU GO
                var vawc = marker6.getLatLng();
document.querySelector('#userLat1').value = vawc.lat;
document.querySelector('#userLng1').value = vawc.lng;
           });
         } 
    }); 
  } 

在页面加载时生成标记的代码:

<body onload="javascript:start();">
<font face="century gothic" color="black" size="2px">
<script>
function start() {
    getInfo();
    getInfo1();
    getInfo2();
    getInfo3();
    getInfo4();
    getInfo5();
    getInfo6();
}
</script>

我的问题是如何使用此代码在地图中隐藏该标记

<li><input style="width:18px;height:18px;" type="checkbox" checked="True">&nbsp&nbsp Arson</li></br>

简单的问题 - 如果我选中它,标记将显示,如果我取消选中它,标记将隐藏。

我不知道怎么做,因为它来自数据库。

您可以将属于同一组的标记放在一组中:

// Create group and add to map
var group = new L.LayerGroup().addTo(map);

$.getJSON('markers.json', function (data) {
    for (var i = 0; i < data.length; i++) { 
        var location = new L.LatLng(data[i].lat, data[i].lng); 
        var marker = new L.Marker(location);
        // Add marker to group
        group.addLayer(marker);
    }
});

在您的输入上放置一个 onchange 处理程序:

<input type="checkbox" onchange="toggleGroup(this)" checked>Toggle group</li>

然后添加一个函数来处理onchange事件:

function toggleGroup (e) {
    // Is checked
    if (e.checked) {
        // Add group to map
        map.addLayer(group);
    // Isn't checked
    } else {
        // Remove group from map
        map.removeLayer(group);
    }
}

这是一个关于 Plunker 的工作示例:http://plnkr.co/edit/cSUVCW?p=preview