Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var width = 300;
- var height = 300;
- var twoPi = 2 * Math.PI; // Full circle
- var formatPercent = d3.format(".0%");
- var data = [{
- "range": "0-20",
- "count": 20
- }, {
- "range": "21-40",
- "count": 10
- }, {
- "range": "41-60",
- "count": 17
- }, {
- "range": "61-80",
- "count": 49
- }, {
- "range": "81-100",
- "count": 90
- }];
- var max = d3.max(data, function(d) {
- return +d.count;
- });
- var percent = d3.max(data, function(d) {
- return +d.count / 10;
- });
- var radiusBackground = .25;
- var radiusForeground = .25;
- var gap = 28;
- var maxCount = max + percent;
- var bounds = path.bounds(collection),
- topLeft = bounds[0],
- bottomRight = bounds[1];
- var svg = d3.select(map.getPanes().overlayPane).append("svg")
- .attr("width", bottomRight[0] - topLeft[0])
- .attr("height", bottomRight[1] - topLeft[1]);
- var g = svg.append("g")
- .attr("transform", "translate(" + width / 10 + "," + height / 10 + ")")
- .attr("class", "leaflet-zoom-hide");
- var transform = d3.geo.transform({
- point: projectPoint
- });
- var d3path = d3.geo.path().projection(transform);
- function projectPoint(x, y) {
- console.log(x,y);
- var point = map.latLngToLayerPoint(new L.LatLng(y, x));
- console.log(point);
- this.stream.point(point.x, point.y);
- }
- g.selectAll(".twoPi")
- .data(data).enter()
- .append("path")
- .attr("class", "twoPi")
- .each(full);
- g.selectAll(".outerPath")
- .data(data).enter()
- .append("path")
- .attr("class", "outerPath")
- .each(drawArc);
- function full() {
- var arc = d3.svg.arc()
- .startAngle(0)
- .endAngle(twoPi)
- .innerRadius(0 + gap * radiusBackground)
- .outerRadius(26 + gap * radiusBackground);
- d3.select(this)
- .attr("transform", "translate(" + (width / 2.5) + "," + (height / 2.5) + ")")
- .attr("d", arc)
- .style("opacity", "0.5");
- radiusBackground++;
- }
- function drawArc(d, i) {
- var arc = d3.svg.arc()
- .startAngle(0)
- .endAngle(twoPi * (d.count / maxCount))
- .innerRadius(0 + gap * radiusForeground)
- .outerRadius(26 + gap * radiusForeground);
- d3.select(this)
- .attr("transform", "translate(" + (width / 2.5) + "," + (height / 2.5) + ")")
- .attr("d", arc)
- .attr("id", "path" + i)
- .on("mouseover", function() {
- d3.select(this)
- .style("fill", "red")
- .style("cursor", "pointer");
- })
- .on("mouseout", function() {
- d3.select(this)
- .style("fill", "#8FAAE5");
- })
- radiusForeground++;
- var text = g.append("text")
- .attr("x", 12 + radiusForeground)
- .attr("dy", 20)
- .style("pointer-events", "none");
- text.append("textPath")
- .attr("fill", "white")
- .attr("xlink:href", "#path" + i)
- .text(d.count);
- }
- L.mapbox.accessToken = 'ACCESS TOKEN HERE';
- var map = L.mapbox.map('map', 'NAME HERE',{ zoomControl: false });
- var myLayer = L.mapbox.featureLayer().addTo(map);
- var geojson = [
- {
- "type": "Feature",
- "geometry": {
- "type": "Point",
- "coordinates": [-2.9858672618865962,53.405470601865126]
- },
- "properties": {
- "icon": {
- "className": "sensor-icon",
- //"html": "▼",
- "iconSize": null
- }
- }
- },
- ];
- myLayer.on('layeradd', function(e) {
- var marker = e.layer,
- feature = marker.feature;
- marker.setIcon(L.divIcon(feature.properties.icon));
- });
- myLayer.setGeoJSON(geojson);
- new L.Control.Zoom({ position: 'bottomleft' }).addTo(map);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement