Last active
August 29, 2015 14:08
-
-
Save hotzeplotz/338275668b86b2b67de5 to your computer and use it in GitHub Desktop.
Future of large cities d3+leaflet
This file contains hidden or 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> | |
| <meta charset=utf-8 /> | |
| <title>Future of large cities</title> | |
| <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' /> | |
| <script src='https://api.tiles.mapbox.com/mapbox.js/v2.1.4/mapbox.js'></script> | |
| <script src="http://d3js.org/d3.v3.min.js"></script> | |
| <style> | |
| body { margin:0; padding:0; } | |
| #map { position:absolute; top:0; bottom:0; width:100%; } | |
| </style> | |
| </head> | |
| <body> | |
| <div id="map"></div> | |
| <script> | |
| L.mapbox.accessToken = 'pk.eyJ1IjoibHNlY2l0aWVzIiwiYSI6IjJ6ZjA5UGMifQ.8y1yiWucAic55wg5YoiTGQ'; | |
| var map = L.mapbox.map('map', 'examples.map-i86nkdio') | |
| .setView([38, -95], 4); | |
| /* | |
| var svg = d3.select(map.getPanes().overlayPane).append("svg"), | |
| g = svg.append("g").attr("class", "leaflet-zoom-hide"); | |
| d3.json("largecities.json", function(collection) { | |
| var transform = d3.geo.transform({point: projectPoint}), | |
| path = d3.geo.path().projection(transform); | |
| var feature = g.selectAll("path") | |
| .data(collection.features) | |
| .enter().append("path"); | |
| map.on("viewreset", reset); | |
| reset(); | |
| // Reposition the SVG to cover the features. | |
| function reset() { | |
| var bounds = path.bounds(collection), | |
| topLeft = bounds[0], | |
| bottomRight = bounds[1]; | |
| svg .attr("width", bottomRight[0] - topLeft[0]) | |
| .attr("height", bottomRight[1] - topLeft[1]) | |
| .style("left", topLeft[0] + "px") | |
| .style("top", topLeft[1] + "px"); | |
| g .attr("transform", "translate(" + -topLeft[0] + "," + -topLeft[1] + ")"); | |
| feature.attr("d", path); | |
| } | |
| // Use Leaflet to implement a D3 geometric transformation. | |
| function projectPoint(x, y) { | |
| var point = map.latLngToLayerPoint(new L.LatLng(y, x)); | |
| this.stream.point(point.x, point.y); | |
| } | |
| }); | |
| */ | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment