leaflet - 为什么 MarkerCluster 不起作用
问题描述
我想让你在传单中使用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>
解决方案
我通过在我的计算机中安装它们( css和js )解决了我的问题:
npm install leaflet.markercluster
推荐阅读
- node.js - 在网络浏览器中保持双重登录策略?
- java - 调用子类方法?
- python - 当进程数和工人数增加时,Python 多处理池 API 无法有效工作
- ffmpeg - 如何使用 libsrt(安全可靠传输)协议配置 ffmpeg?
- java - 循环调度程序没有产生正确的结果
- node.js - create-react-app 中的问题:术语“create-react-app”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称
- c++11 - 'shared_ptr 没有可行的转换
' 到 'shared_ptr ' - vue.js - 如何总结表格中的行跨度(element-ui)
- python - 矩阵的 xy 坐标列表
- c# - if else 语句中的时间跨度