var generator = new arc.GreatCircle({x: -90, y: -70},{x: 89, y: 70}); // points to connect
var n = 50; // n of points
var coords = generator.Arc(n).geometries[0].coords;
var geojson = {"type":"Feature","geometry":{"type":"LineString","coordinates": coords},"properties":null } ;
连接两个点的基本线条可能如下所示(取决于设置):
var geojson = {"type":"Feature","geometry":{"type":"LineString","coordinates": [[90,50],[-89,50]]},"properties":null };
var feature = svg.append("path")
.datum(geojson)
.attr("d",path);
var width = 600, height = 300;
var svg = d3.select("svg")
.attr("width",width)
.attr("height",height);
var projection = d3.geoMercator() // projection type
.translate([width/2,height/2])
.scale(width/Math.PI/2*0.7)
var path = d3.geoPath().projection(projection) // path generator
var geojson = [
{"type":"Feature","geometry":{"type":"LineString","coordinates": [[90,50],[-89,50]]},"properties":null },
{"type":"Feature","geometry":{"type":"LineString","coordinates": [[90,-50],[-89,50]]},"properties":null }];
var feature = svg.selectAll("path")
.data(geojson)
.enter().append("path")
.attr("d",path)
.attr("stroke","steelblue")
.attr("stroke-width",3)
// Add the world to reference the lines:
d3.json("https://unpkg.com/world-atlas@1/world/110m.json", function(error, world) {
if (error) throw error;
svg.append("path")
.datum(topojson.mesh(world))
.attr("d",path)
.attr("stroke","#ccc")
.lower();
});
path {
fill: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.10.0/d3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/topojson/3.0.2/topojson.js"></script>
<svg></svg>