隐藏地图启动上的单个标记组

Hide single markergroup on mapstart

本文关键字:单个标 地图 启动 隐藏      更新时间:2023-09-26

我在切换时创建了一个地图,通过其类型隐藏/显示标记。现在我想在mapstart上隐藏一组(类型)标记,并且仅在单击按钮时才显示它。所以我希望地图启动后不显示组(buche)。
嗯,我不明白我做错了什么..有人有解决方案吗?

    markerGroups = { "buche": [], "birke": [], "erle": [], "haselnuss": [], "rotbuche": [], "weide": [], "tanne": [], "lärche": [], "eibe": [], "walnuss": []};

 function createMarker(latlng, name, address, tel, href, image, type) {
        var marker = new google.maps.Marker({
        position: latlng,
        map: map,
        icon: images[type],
        zIndex: Math.round(latlng.lat()*-100000)<<5
        });

      markerGroups[type].push(marker);
for (var i = 0; i < markerGroups[type].length; i++) {
        var marker = markerGroups["buche"];
            marker.setMap(null);
        }
}

只需在创建标记时将 map-property 设置为 null:

var marker = new google.maps.Marker({
    position: latlng,
    map: (type==='buche') ? null : map,
    icon: images[type],
    zIndex: Math.round(latlng.lat()*-100000)<<5
    });