admin管理员组文章数量:1325079
I'm trying to make a map with leafletjs, but I can't get marker clusters to work properly. I'd like it to show the default icons for marker clustering, but instead it shows no marker cluster icons at all. Here's a demonstration:
var map = L.map('mapid').setView([51.505, -0.09], 13);
L.tileLayer('/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
maxZoom: 18,
attribution: 'Map data © <a href="">OpenStreetMap</a> contributors, ' +
'<a href=".0/">CC-BY-SA</a>, ' +
'Imagery © <a href="">Mapbox</a>',
id: 'mapbox.streets'
}).addTo(map);
var markers = L.markerClusterGroup();
markers.addLayer(L.marker([51.505, -0.09]));
markers.addLayer(L.marker([51.506, -0.09]));
map.addLayer(markers);
<link rel="stylesheet" href="/[email protected]/dist/leaflet.css" integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" crossorigin="" />
<script src="/[email protected]/dist/leaflet.js" integrity="sha512-mNqn2Wg7tSToJhvHcqfzLMU6J4mkOImSPTxVZAdo+lcPlk+GhZmYgACEe0x35K7YzW1zJ7XyJV/TT1MrdXvMcA==" crossorigin=""></script>
<script src=".markercluster/dist/leaflet.markercluster-src.js"></script>
<div id="mapid" style="height:380px;"></div>
I'm trying to make a map with leafletjs, but I can't get marker clusters to work properly. I'd like it to show the default icons for marker clustering, but instead it shows no marker cluster icons at all. Here's a demonstration:
var map = L.map('mapid').setView([51.505, -0.09], 13);
L.tileLayer('https://api.tiles.mapbox./v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
maxZoom: 18,
attribution: 'Map data © <a href="http://openstreetmap">OpenStreetMap</a> contributors, ' +
'<a href="http://creativemons/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Imagery © <a href="http://mapbox.">Mapbox</a>',
id: 'mapbox.streets'
}).addTo(map);
var markers = L.markerClusterGroup();
markers.addLayer(L.marker([51.505, -0.09]));
markers.addLayer(L.marker([51.506, -0.09]));
map.addLayer(markers);
<link rel="stylesheet" href="https://unpkg./[email protected]/dist/leaflet.css" integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" crossorigin="" />
<script src="https://unpkg./[email protected]/dist/leaflet.js" integrity="sha512-mNqn2Wg7tSToJhvHcqfzLMU6J4mkOImSPTxVZAdo+lcPlk+GhZmYgACEe0x35K7YzW1zJ7XyJV/TT1MrdXvMcA==" crossorigin=""></script>
<script src="https://leaflet.github.io/Leaflet.markercluster/dist/leaflet.markercluster-src.js"></script>
<div id="mapid" style="height:380px;"></div>
This code is pletely based on the examples on http://leafletjs./examples/quick-start/ and https://github./Leaflet/Leaflet.markercluster#usage so I'd imagine it would work given those examples, but it doesn't seem like this actually shows the icons behind the clusters.
I have found that a markerClusterGroup
has a method called _defaultIconCreateFunction
, but it doesn't seem to get called (or if it does get called, it doesn't do anything).
So what am I doing wrong here?
Share asked Aug 2, 2017 at 11:34 Joeytje50Joeytje50 19.1k15 gold badges68 silver badges99 bronze badges1 Answer
Reset to default 10You also need MarkerCluster.css
and MarkerCluster.Default.css
var map = L.map('mapid').setView([51.505, -0.09], 13);
L.tileLayer('https://api.tiles.mapbox./v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
maxZoom: 18,
attribution: 'Map data © <a href="http://openstreetmap">OpenStreetMap</a> contributors, ' +
'<a href="http://creativemons/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Imagery © <a href="http://mapbox.">Mapbox</a>',
id: 'mapbox.streets'
}).addTo(map);
var markers = L.markerClusterGroup();
markers.addLayer(L.marker([51.505, -0.09]));
markers.addLayer(L.marker([51.506, -0.09]));
map.addLayer(markers);
<link rel="stylesheet" href="https://unpkg./[email protected]/dist/leaflet.css" integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" crossorigin="" />
<script src="https://unpkg./[email protected]/dist/leaflet.js" integrity="sha512-mNqn2Wg7tSToJhvHcqfzLMU6J4mkOImSPTxVZAdo+lcPlk+GhZmYgACEe0x35K7YzW1zJ7XyJV/TT1MrdXvMcA==" crossorigin=""></script>
<link rel="stylesheet" href="https://leaflet.github.io/Leaflet.markercluster/dist/MarkerCluster.css" />
<link rel="stylesheet" href="https://leaflet.github.io/Leaflet.markercluster/dist/MarkerCluster.Default.css" />
<script src="https://leaflet.github.io/Leaflet.markercluster/dist/leaflet.markercluster-src.js"></script>
<div id="mapid" style="height:380px;"></div>
本文标签: javascriptLeaflet map marker clusters not showing iconsStack Overflow
版权声明:本文标题:javascript - Leaflet map marker clusters not showing icons - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742145924a2422791.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论