Based on this ernesmb bl.ock. Click on the clustered points to see the spidering effect
Last active
September 13, 2016 07:30
-
-
Save oriolbx/7518b5834d1b679759bda218871cb315 to your computer and use it in GitHub Desktop.
L.Markercluster spidify() cartodb.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/3.15/themes/css/cartodb.css" /> | |
<link rel="stylesheet" href="http://asset.geosprocket.com/leaflet/cluster/MarkerCluster.Default.css" /> | |
<script src="http://libs.cartocdn.com/cartodb.js/v3/3.15/cartodb.js"></script> | |
<script src="http://asset.geosprocket.com/leaflet/cluster/leaflet.markercluster.js"></script> | |
<style type="text/css"> | |
body { | |
padding: 0; | |
margin: 0; | |
} | |
html, body, #map { | |
height: 100%; | |
} | |
</style> | |
<body> | |
<div id="map"></div> | |
<script> | |
// Base layer | |
var baseLayer = L.tileLayer('http://{s}.api.cartocdn.com/base-light/{z}/{x}/{y}.png', { | |
attribution: 'CartoDB' | |
}) | |
// MarkerCluster layer and options | |
var markers = L.markerClusterGroup({ | |
showCoverageOnHover:false, | |
spiderfyOnMaxZoom:true, | |
spiderLegPolylineOptions:{ | |
weight:1, color:'#FF0000', opacity:1 | |
}, | |
zoomToBoundsOnClick:true, | |
removeOutsideVisibleBounds:true | |
}); | |
//Change the username and the SQL query below | |
$.getJSON("http://oboix.cartodb.com/api/v2/sql?format=GeoJSON&q=SELECT * FROM populated_places_spf", function(data) { | |
var geojson = L.geoJson(data, { | |
onEachFeature: function (feature, layer) { | |
// Here you will need to change 'name' and 'pop_max' with actual column names from your dataset. | |
layer.bindPopup("<h2>" + feature.properties.name + "</h2><hr><p>Population: " + feature.properties.pop_max + "</p>"); | |
} | |
}); | |
markers.addLayer(geojson); | |
// Build the map | |
var map = L.map('map', {maxZoom: 9}).fitBounds(markers.getBounds()); | |
baseLayer.addTo(map); | |
markers.addTo(map); | |
}); | |
// click spiders effect | |
markers.on('clusterclick', function (a) { | |
a.layer.spiderfy(); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment