【发布时间】:2021-10-29 15:43:41
【问题描述】:
我是 Leaflet 的新手,我正在尝试显示带有标记的地图。
我使用 CircleMarkers 来设置每个标记的颜色,这样无论缩放级别如何,标记都保持其大小。我使用 markercluster 添加标记,因为我希望能够轻松删除它们。
<script src="https://unpkg.com/leaflet.markercluster@1.3.0/dist/leaflet.markercluster.js"></script>
function addMarkers(data){
// setup a marker group
markerList = L.markerClusterGroup();
for (var i = 0; i < data.length; i++){
var circleColor = getcolor(data[i].roundScore);
var circle = L.circleMarker([data[i].solutionLat, data[i].solutionLng], {
color: circleColor,
fillColor: circleColor,
fillOpacity: 0.5,
radius: 5
});
circle.bindPopup("Score : " + data[i].roundScore + "\n Address :" + data[i].address);
markerList.addLayer(circle);
}
window.mapMark.addLayer(markerList);
}
function deleteMarkers(){
if(markerList) {
markerList.clearLayers();
}
}
我不知道如何改变这种行为,以及它是链接到标记本身还是链接到我使用的图块,即 openstreetmap:
const attribution =
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors';
const tileUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
const tiles = L.tileLayer(tileUrl, { attribution });
tiles.addTo(mapMark);
}
任何帮助或提示将不胜感激。 非常感谢:)
【问题讨论】:
标签: javascript leaflet openstreetmap leaflet.markercluster