admin管理员组文章数量:1221329
Using some D3js code and projected topojson data on a map dataviz of any projection, how can I get back geocoordinates ? Something such:
var svg = d3.select("#viz").append("svg:svg")
.attr("width", 320)
.attr("height", 200)
.on("mousedown", mousedown)
.on("click", mouselocation);
How to get the geocordinates from a click on a D3js map visualisation ?
Links to demos welcome.
Edit: a list of relevant demos :
- OpenLayers demo... but we what D3js.
- Jason Davies/rotate/ use of
projection.invert(d3.mouse(this))
Using some D3js code and projected topojson data on a map dataviz of any projection, how can I get back geocoordinates ? Something such:
var svg = d3.select("#viz").append("svg:svg")
.attr("width", 320)
.attr("height", 200)
.on("mousedown", mousedown)
.on("click", mouselocation);
How to get the geocordinates from a click on a D3js map visualisation ?
Links to demos welcome.
Edit: a list of relevant demos :
- OpenLayers demo... but we what D3js.
- Jason Davies/rotate/ use of
projection.invert(d3.mouse(this))
2 Answers
Reset to default 18Use d3.mouse to get the pixel coordinates, and then use the projection (d3.geo.azimuthal, here) to invert x and y to longitude and latitude. For example:
d3.select("svg").on("mousedown.log", function() {
console.log(projection.invert(d3.mouse(this)));
});
If you want to support clicking on the background of the SVG, you may also want an invisible rect with pointer-events: all. (Also note: older versions of D3 used d3.svg.mouse rather than d3.mouse.)
Jason Davies/rotate/ use of projection.invert(d3.mouse(this))
is nice and may worth a look.
.on("mousedown.grab", function() {
var point;
if (mousePoint) point = svg.insert("path", ".foreground")
.datum({type: "Point", coordinates: projection.invert(d3.mouse(this))})
.attr("class", "point")
.attr("d", path); // add back the point
本文标签: javascriptD3js how to get LatLog geocoordinates from mouse clickStack Overflow
版权声明:本文标题:javascript - D3js: how to get LatLog geocoordinates from mouse click? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739358983a2159729.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论