Created
July 14, 2013 13:24
-
-
Save milkbread/5994264 to your computer and use it in GitHub Desktop.
HTML: D3: Leaflet: Transparency Demo
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> | |
<title>Testmap</title> | |
<meta charset="utf-8" /> | |
<script src="http://cdn.leafletjs.com/leaflet-0.6.1/leaflet.js"></script> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<style> | |
@import url(http://cdn.leafletjs.com/leaflet-0.6.1/leaflet.css); | |
</style> | |
</head> | |
<body> | |
<div id="map" style="width: 960px; height: 300px"></div> | |
<script> | |
var map = L.map('map').setView([52.52,13.384], 13); | |
var toolserver = L.tileLayer('http://{s}.www.toolserver.org/tiles/bw-mapnik/{z}/{x}/{y}.png'); | |
var stamen = L.tileLayer('http://{s}.tile.stamen.com/toner/{z}/{x}/{y}.png', {attribution: 'Add some attributes here!'}).addTo(map); | |
var baseLayers = {"stamen": stamen, "toolserver-mapnik":toolserver}; | |
var overlays = {}; | |
d3.json("roads2.js", function(collection) { | |
//console.log(collection) | |
collection.features.forEach(function(feature,i){ | |
//console.log(feature.geometry.coordinates) | |
var polyline_red = L.polyline(feature.geometry.coordinates.map(function(d){return [d[1],d[0]]}), {color: 'rgba(100%,0%,0%,0.33)'}); | |
overlays["Polyline red"+i] = polyline_red; | |
var polyline_blue = L.polyline(feature.geometry.coordinates.map(function(d){return [d[1],d[0]]}), {color: 'rgba(0%,0%,100%,0.33)'}); | |
overlays["Polyline blue"+i] = polyline_blue; | |
var polyline_green = L.polyline(feature.geometry.coordinates.map(function(d){return [d[1],d[0]]}), {color: 'rgba(0%,100%,0%,0.33)'}); | |
overlays["Polyline green"+i] = polyline_green; | |
}) | |
//console.log(overlays) | |
L.control.layers(baseLayers, overlays).addTo(map); | |
}) | |
</script> | |
</body> | |
</html> |
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
{ | |
"type": "FeatureCollection", | |
"features": [ | |
{ "type": "Feature", "id": 0, "properties": { "id": 0, "street": "number 1", "length": 1 }, "geometry": { "type": "LineString", "coordinates": [ [ 13.424244, 52.539179 ], [ 13.421705701409467, 52.539576815907466 ], [ 13.42183003062355, 52.539687723163105 ], [ 13.422166851598536, 52.540291556826226 ], [ 13.42236706832899, 52.540650784116721 ], [ 13.4226, 52.54064 ] ] } } | |
, | |
{ "type": "Feature", "id": 9, "properties": { "id": 10, "street": "number 2", "length": 10 }, "geometry": { "type": "LineString", "coordinates": [ [ 13.40031, 52.51801 ], [ 13.3996705721827, 52.517765112439875 ], [ 13.399670572182709, 52.517765112439861 ], [ 13.399176455188746, 52.517654943693323 ], [ 13.397880188568315, 52.517573576643279 ], [ 13.397615860238052, 52.518724568870446 ], [ 13.397225437613784, 52.519266719174603 ], [ 13.397065264229472, 52.519479922561445 ], [ 13.396694863278245, 52.519650484525975 ], [ 13.396414559855696, 52.519668758982903 ], [ 13.396134256433148, 52.519760131153504 ], [ 13.395183226963786, 52.520460644814797 ], [ 13.394102056619669, 52.5212646989009 ], [ 13.393401298063297, 52.521776362020844 ], [ 13.393501406428491, 52.521812909158513 ], [ 13.39383176403364, 52.521989553228643 ], [ 13.393921861562315, 52.522062647118865 ], [ 13.394974927632834, 52.521762139072038 ] ] } } | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment