【发布时间】:2022-12-17 11:47:45
【问题描述】:
我试图根据经度和纬度在地图上画一些圆圈,但是,我认为我的投影有问题,因为它没有画出我的任何东西。
我得到以下,
我有一个全局变量
变种投影= d3.geoMercator()
然后,我定义投影:
projection.scale(1).translate([0, 0]);
var b = path.bounds(data);
var s = .95 / Math.max((b[1][0] - b[0][0]) / mwidth, (b[1][1] -
b[0][1]) / mheight);
var t = [(mwidth - s * (b[1][0] + b[0][0])) / 2, (mheight - s *
(b[1][1] + b[0][1])) / 2+50];
projection.scale(s).translate(t);
这就是我试图实现我的圈子的方式,
// Hospital points
svg.selectAll('.hospital-circle')
.data(hospitals)
.enter()
.append('circle')
.attr('class', 'boundary')
.attr('r', 5)
.attr('cx', function(d) {
var hospitalCoords = projection.scale(s).translate(t)([d.lon, d.lat])
console.log(d)
console.log(hospitalCoords);
return hospitalCoords[0]
})
.attr('cy', function(d) {
var hospitalCoords = projection.scale(s).translate(t)([d.lon, d.lat])
console.log(d)
console.log(hospitalCoords)
return hospitalCoords[1]
})
【问题讨论】:
标签: javascript d3.js