Lau*_*con 10 javascript svg d3.js
我已经创建了一个从mbtile转换为geojson的地图,投影是WGS84.我加载它:
var map = svg.append("g").attr("class", "map");
var path = d3.geo.path().projection(d3.geo.albers().origin([3.4,46.8]).scale(12000).translate([590, 570]));
d3.json('myjsonfile.json', function(json) {
map.selectAll('path').data(json.features).enter().append('path').attr('d', path)
});
Run Code Online (Sandbox Code Playgroud)
现在我想在我的svg中添加一个svg元素(一个点,一个圆,一个点(我不知道))和它的(lat,lng)坐标.
我无法想象如何做到这一点.
nra*_*itz 17
您需要将投影分开,以便再次使用它来投射点的纬度/经度:
var map = svg.append("g").attr("class", "map");
var projection = d3.geo.albers()
.origin([3.4,46.8])
.scale(12000)
.translate([590, 570]);
var path = d3.geo.path().projection(projection);
d3.json('myjsonfile.json', function(json) {
map.selectAll('path')
.data(json.features)
.enter().append('path').attr('d', path);
// now use the projection to project your coords
var coordinates = projection([mylon, mylat]);
map.append('svg:circle')
.attr('cx', coordinates[0])
.attr('cy', coordinates[1])
.attr('r', 5);
});
Run Code Online (Sandbox Code Playgroud)
另一种方法是通过投射的坐标转换点:
map.append('svg:circle')
.attr("transform", function(d) {
return "translate(" + projection(d.coordinates) + ")";
})
.attr('r', 5);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8236 次 |
| 最近记录: |