Skip to content

Instantly share code, notes, and snippets.

@wboykinm
Last active September 27, 2017 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wboykinm/62c1d593ac9bf84cb849 to your computer and use it in GitHub Desktop.
Save wboykinm/62c1d593ac9bf84cb849 to your computer and use it in GitHub Desktop.
Clustering: unicode hexagon character as markercluster icon, two levels of popups
var customerPoints =
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-73.212890625,
44.472011210309695
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-73.21701049804688,
44.45436907523842
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-73.2568359375,
44.51511398458795
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-73.23898315429688,
44.49944393446856
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-73.09616088867188,
44.44456558540571
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-73.1634521484375,
44.564055739510955
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-73.19915771484375,
44.472011210309695
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-73.18954467773438,
44.49454617990028
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-73.1634521484375,
44.422011314236634
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-96.8170166015625,
32.80574473290688
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-96.8994140625,
32.77572870013365
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-96.8719482421875,
32.88189375925038
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-96.74560546875,
32.95106342152381
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-89.35300827026367,
43.09822536380049
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-89.3543815612793,
43.10963063220507
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-89.37858581542969,
43.07879391592319
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-89.42665100097656,
43.06663045459365
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-89.36622619628906,
43.11865307514252
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-89.36210632324219,
43.085188169547706
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-89.39746856689453,
43.06976559822158
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-89.38613891601562,
43.07164660742738
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-89.44210052490234,
43.06788453128748
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-89.40502166748047,
43.06086137134326
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-89.34751510620117,
43.063369735115884
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-89.44124221801758,
43.07904468353957
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-89.4400405883789,
43.07866853173014
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-89.44398880004883,
43.07929545012961
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-89.35609817504883,
43.09772398456919
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-89.36759948730469,
43.07992236211469
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-89.4587516784668,
43.05258304276628
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-89.39334869384766,
43.05521717762989
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-89.34837341308594,
43.062491819469194
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-89.3415069580078,
43.067759124772664
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-89.34803009033203,
43.059230879857886
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-89.34785842895508,
43.06186472916746
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.41197204589842,
38.61579745317875
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.34674072265624,
38.60077361738762
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.4154052734375,
38.59057708018653
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.36390686035155,
38.62706326550212
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.33094787597655,
38.61579745317875
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.5039825439453,
38.5632002667659
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.48612976074217,
38.63242731602097
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.43531799316406,
38.630281743971366
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.78207397460936,
38.676933444637925
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.74568176269531,
38.557294096029985
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.73675537109374,
38.54709138531694
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.47789001464844,
38.62330819136028
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.4483642578125,
38.61687046392973
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.41334533691408,
38.65870536210694
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.49093627929689,
38.65602437034701
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.44630432128906,
38.60238346454492
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.40716552734375,
38.57930553828264
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.4044189453125,
38.61257832462118
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.5252685546875,
38.624381089751544
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.51977539062499,
38.66728386136457
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.51771545410155,
38.65227081329621
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.4270782470703,
38.62223527691723
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.43943786621092,
38.624381089751544
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.45729064941405,
38.63510919078497
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.45797729492186,
38.65870536210694
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.39617919921874,
38.60882249206389
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.47789001464844,
38.55783104069692
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.49299621582031,
38.58520989992523
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.53350830078124,
38.5771583773376
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.49024963378905,
38.55085044718565
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.48406982421875,
38.55890491799819
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.49711608886719,
38.57071650940461
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.47033691406249,
38.557294096029985
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.72988891601562,
38.54601733154524
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.76010131835938,
38.52614444334863
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.76628112792967,
38.563737167312375
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.77658081054688,
38.548165423046584
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.75666809082033,
38.549239444734
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.83013916015624,
38.4519755295767
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-122.09587097167967,
38.518086303163024
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-122.14805603027344,
38.47509432050245
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.98326110839844,
38.35027253825765
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.82601928710938,
38.44874906264676
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.74087524414064,
38.53635012572907
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.70928955078126,
38.559441850632474
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.728515625,
38.57017966100314
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.72027587890624,
38.531516035578406
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.78070068359375,
38.53849850597664
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.96403503417969,
38.35350340353833
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-122.00042724609374,
38.34057907754285
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.98875427246092,
38.37019391098433
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.981201171875,
38.34327183564684
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.96266174316406,
38.533127435052776
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.42364501953124,
38.518086303163024
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.014404296875,
38.982897808179985
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.28082275390625,
38.724090458956965
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.30279541015624,
38.788345355085625
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.2506103515625,
38.78406349514289
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.31652832031249,
37.96368875328558
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.431884765625,
38.417014454352035
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.40167236328125,
38.40410147066251
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.35772705078125,
38.507340712903485
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.08306884765624,
38.49014443285755
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.61315917968749,
38.96154447940716
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.45111083984375,
38.41916639395372
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.42639160156249,
38.38903340675905
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.29180908203125,
37.97668004819228
]
}
},
{
"type": "Feature",
"properties": {
"person": "Fulano Detal"
},
"geometry": {
"type": "Point",
"coordinates": [
-121.45111083984375,
38.41271038284709
]
}
}
]
}
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Leaflet Markercluster</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.mapbox.com/mapbox.js/v2.3.0/mapbox.js'></script>
<link href='https://api.mapbox.com/mapbox.js/v2.3.0/mapbox.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; background-color: #000; }
#map { position:absolute; top:0; bottom:0; width:100%; background-color: #000; }
.hex {
width: 40px;
height: 40px;
color: #9bd2ce;
text-align: center;
text-shadow:
-0.5px -0.5px 0 #49ada6,
0.5px -0.5px 0 #49ada6,
-0.5px 0.5px 0 #49ada6,
0.5px 0.5px 0 #49ada6;
}
.leaflet-div-icon {
background-color:rgba(0,0,0,0);
border:0px;
}
</style>
</head>
<body>
<script src='https://api.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v0.4.0/leaflet.markercluster.js'></script>
<link href='https://api.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v0.4.0/MarkerCluster.css' rel='stylesheet' />
<link href='https://api.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v0.4.0/MarkerCluster.Default.css' rel='stylesheet' />
<script type="text/javascript" src="customers.js"></script>
<div id='map'></div>
<script>
L.mapbox.accessToken = 'pk.eyJ1IjoiZmFyYWRheTIiLCJhIjoiTUVHbDl5OCJ9.buFaqIdaIM3iXr1BOYKpsQ';
var map = L.mapbox.map('map').setView([40,-98],4);
L.mapbox.styleLayer('mapbox://styles/faraday2/0fd3756a').addTo(map);
var markers = new L.MarkerClusterGroup({
spiderfyOnMaxZoom: false,
showCoverageOnHover: false,
singleMarkerMode: true,
maxClusterRadius: 120,
iconCreateFunction: function(cluster) {
markers.on('clustermouseover', function(c) {
var popup = L.popup()
.setLatLng(c.layer.getLatLng())
.setContent('<h2>' + c.layer._childCount +' customers</h2>')
.openOn(map);
}).on('clustermouseout',function(c){
map.closePopup();
}).on('clusterclick',function(c){
map.closePopup();
});
var clusterSize = function(count) {
return (count < 2) ? 16 :
(count >= 2 && count <= 10) ? 32 :
(count > 10 && count <= 50) ? 48 :
64
};
return new L.DivIcon({
iconSize: [40, 40],
html: '<div class="hex" style="font-size:' + clusterSize(cluster.getChildCount()) + 'px">&#x2B22;</div>'
});
}
});
var featureLayer = L.geoJson(customerPoints, {
onEachFeature: function(feature, layer) {
var popupText = 'Customer: ' + feature.properties.person;
layer.bindPopup(popupText)
layer.on('mouseover', function (e) {
this.openPopup();
});
layer.on('mouseout', function (e) {
this.closePopup();
});
}
})
markers.addLayer(featureLayer);
map.addLayer(markers);
featureLayer.on('ready', function() {
map.fitBounds(featureLayer.getBounds());
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment