【发布时间】:2018-04-24 09:25:13
【问题描述】:
当我在 SVG 元素中绘制百慕大三角形时,比例不是我所期望的(三角形应该延伸到框的边缘)并且填充是向后的(而不是绘制三角形,它绘制了一个切掉了三角形的正方形)。
var geojson = {
"features": [
{
"type": "Feature",
"properties": {
"name": "Bermuda Triangle",
"area": 1150180
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-64.73, 32.31],
[-80.19, 25.76],
[-66.09, 18.43],
[-64.73, 32.31]
]
]
}
}
],
"type":"FeatureCollection"
};
var width = 480;
var height = 480;
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.attr("style", "border: 2px solid black");
var projection = d3.geoMercator().fitSize([width, height], geojson);
var path = d3.geoPath().projection(projection);
svg.selectAll('path')
.data(geojson.features)
.enter()
.append('path')
.attr('d', path)
.style("fill", "red")
.style("stroke-width", "1")
.style("stroke", "black");
<script src="//d3js.org/d3.v4.js"></script>
我做错了什么?
【问题讨论】:
标签: javascript d3.js svg geo