我想在传单中使用 markercluster ,所以我在代码中添加了此代码:
<script src='https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v0.4.0/leaflet.markercluster.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v0.4.0/MarkerCluster.css' rel='stylesheet' />
<link href='https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v0.4.0/MarkerCluster.Default.css' rel='stylesheet' />
但是,当我尝试将标记存储在markercluster上,然后将其显示在地图上时,我得到一个空地图:
<script type="text/javascript"'>
var mymap = L.map('mapid').setView([40.7128, -74.0060], 13);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
maxZoom: 18,
id: 'mapbox.streets',
accessToken: 'pk.eyJ1IjoiYWhtZWQ5NCIsImEiOiJjaml3OWx4YnYyaDRsM3FxbWFya3dxdHI4In0.Z7ODiHmNEFY2wAPFD6mX1w'
}).addTo(mymap);
var marker = L.marker([40.7128,-74.0060]);
var markerClusters = L.markerClusterGroup();
markerClusters.addLayer(marker)
mymap.addLayer(markerClusters)
</script>
答案 0 :(得分:0)
我通过在计算机中安装它们( css 和 js )解决了我的问题:
npm install leaflet.markercluster