admin管理员组文章数量:1310290
I've managed to cluster my markers. What I want to do now is to display a custom icon with the number of points in the cluster, but I can't figure out how to do that or if it's even possible.
I read the documentation and understood that I need to implement my own iconCreateFunction when creating the marker cluster.
addSomeMarkers: function(data, markerProperties) {
var markers = L.markerClusterGroup({
iconCreateFunction: function(cluster) {
// TODO
}
});
....
}
I know I can return L.divIcon with a custom css class and cluster.getChildCount()
, but I can't specify markerProperties.iconUrl
as an image that should be displayed.
I could also use L.icon
with my custom icon from markerProperties.iconUrl
, but in that case I don't see how I should get cluster.getChildCount()
to display.
So what I need is a bination of both. Is there anything like that? And if not, can someone hint a workaround to achieve this?
I've managed to cluster my markers. What I want to do now is to display a custom icon with the number of points in the cluster, but I can't figure out how to do that or if it's even possible.
I read the documentation and understood that I need to implement my own iconCreateFunction when creating the marker cluster.
addSomeMarkers: function(data, markerProperties) {
var markers = L.markerClusterGroup({
iconCreateFunction: function(cluster) {
// TODO
}
});
....
}
I know I can return L.divIcon with a custom css class and cluster.getChildCount()
, but I can't specify markerProperties.iconUrl
as an image that should be displayed.
I could also use L.icon
with my custom icon from markerProperties.iconUrl
, but in that case I don't see how I should get cluster.getChildCount()
to display.
So what I need is a bination of both. Is there anything like that? And if not, can someone hint a workaround to achieve this?
Share Improve this question asked Jun 17, 2014 at 8:18 SandraSandra 3,7605 gold badges26 silver badges33 bronze badges1 Answer
Reset to default 6Using the example here: https://github./Leaflet/Leaflet.markercluster/blob/master/example/marker-clustering-custom.html
And the documentation of L.divIcon is here: http://leafletjs./reference.html#divicon
I came up with this example: http://franceimage.github.io/leaflet/8/?map=46.566414,2.4609375,6
Hopefully it will help you
Meaningful parts are:
var markerCluster = new L.MarkerClusterGroup({
iconCreateFunction: function (cluster) {
var markers = cluster.getAllChildMarkers();
var html = '<div class="circle">' + markers.length + '</div>';
return L.divIcon({ html: html, className: 'mycluster', iconSize: L.point(32, 32) });
},
spiderfyOnMaxZoom: false, showCoverageOnHover: true, zoomToBoundsOnClick: false
});
and css
.circle {
width: 32px;
height: 32px;
line-height: 32px;
background-image: url('circle.png');
text-align: center;
}
There may be other ways ...
本文标签: javascriptLeaflet clustermarker with custom iconStack Overflow
版权声明:本文标题:javascript - Leaflet clustermarker with custom icon - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741834597a2400137.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论