Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var svg = d3.select("body").append("svg")
- .attr("width",width)
- .attr("height",height)
- function createMap(countries, cities) {
- var projection = d3.geoMercator()
- .scale(scale)
- .translate([width/2,height/2])
- var mapZoom = d3.zoom()
- .on("zoom", zoomed)
- var zoomSettings = d3.zoomIdentity
- .translate(width/2, height/2)
- .scale(scale)
- svg.call(mapZoom).call(mapZoom.transform, zoomSettings) // ?!!!
- function zoomed() {
- var e = d3.event
- .translate([e.transform.x, e.transform.y])
- .scale(e.transform.k)
- // I didn't include the drawing of the paths, but
- they are appended to the SVG, and this updates their data.
- d3.selectAll("path.graticule").attr("d", geoPath)
- d3.selectAll("path.countries").attr("d", geoPath)
- d3.selectAll("circle.cities")
- .attr("cx", d => projection([d.x,d.y])[0])
- .attr("cy", d => projection([d.x,d.y])[1])
- }
- var zoom = d3.zoom()
- .scaleExtent([1,3])
- .on("zoom", zoomed)
- function zoomed(){
- g.attr("transform", d3.event.transform)
- }
- var svg = d3.select("body").append("svg")
- .attr("width",width)
- .attr("height",height)
- .call(zoom)
- var g = d3.select("svg").append("g")
- // All elements are bound to group^
Add Comment
Please, Sign In to add comment