Put markers to a map generated with topoJSON and d3.js

若如初见. 提交于 2019-12-06 08:09:24

问题


I am creating a map of a particular state, I have been experimenting with d3.js and topojson and have created a great map, but now I want to add a marker on the map.

But now I have problems because as I add the marker have a GeoJSON file to add markers to the map generated and also the power I'd like to open a tooltip whenever a marker is pressed.

My map is very similar to this: http://bl.ocks.org/mbostock/4699541 and all I want is to add markers to states through a GeoJSON file that has the geographical coordinates of the markers.

So the map is currently

Map expected...

回答1:


You can add somthing like this at the end of your json callback:

var marks = [{long: -75, lat: 43},{long: -78, lat: 41},{long: -70, lat: 53}];

svg.selectAll(".mark")
    .data(marks)
    .enter()
    .append("image")
    .attr('class','mark')
    .attr('width', 20)
    .attr('height', 20)
    .attr("xlink:href",'https://cdn3.iconfinder.com/data/icons/softwaredemo/PNG/24x24/DrawingPin1_Blue.png')
    .attr("transform", d => `translate(${projection([d.long,d.lat])}`);


来源:https://stackoverflow.com/questions/21397608/put-markers-to-a-map-generated-with-topojson-and-d3-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!