Built with blockbuilder.org
Last active
January 29, 2018 14:15
-
-
Save sbrudz/89cd4c5100a20ddc1dc5a3a7b3ecbba1 to your computer and use it in GitHub Desktop.
testing geoIdentity fitExtent
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
license: mit |
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> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script src="https://unpkg.com/topojson-client@3"></script> | |
<style> | |
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
path.land { | |
stroke: #ea0000; | |
stroke-width: 0.5px; | |
} | |
path.mark { | |
stroke: blue; | |
stroke-width: 0.5px; | |
} | |
</style> | |
</head> | |
<body> | |
<script> | |
var svg = d3.select("body").append("svg") | |
.attr("width", 960) | |
.attr("height", 500) | |
var width = 960; | |
var height= 500; | |
svg.append('rect') | |
.attr('width', width) | |
.attr('height', height); | |
var miamiToNYCGeoJson = { | |
type: 'LineString', | |
coordinates: [ | |
[-80.191788, 25.761681], [-74.006058, 40.712772] | |
] | |
}; | |
var projection = d3.geoIdentity().fitExtent([[10, 10], [width - 10, height - 10]], miamiToNYCGeoJson); | |
var path = d3.geoPath().projection(projection); | |
d3.json('https://raw.githubusercontent.com/johan/world.geo.json/master/countries.geo.json', function(error, worldGeoJson) { | |
svg.append("g").append("path") | |
.datum(worldGeoJson) | |
.attr("class", "land") | |
.attr("d", path); | |
svg.append("g") | |
.append("path") | |
.datum(miamiToNYCGeoJson) | |
.attr("class", "mark") | |
.attr("d", path); | |
}); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment