chart = {
const width = 960,
height = 900;
const svg = d3.create("svg")
.attr("viewBox", [50, 50, width-100, height-100]);
var projection = d3
.geoMercator()
.fitSize([width - 50, height - 50], fbox);
var path1 = d3.geoPath().projection(projection);
var path2 = d3.geoPath().projection(projection);
var path3 = d3.geoPath().projection(projection);
var g = svg.append("g").attr("id", "paths");
g.selectAll("path2")
.data(streets.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path2) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "none")
.style('stroke-opacity','1')
.style("stroke-width", '.75')
.style("stroke", "rgb(0,0,0)")
g.selectAll("path3") //d3 geopath
.data(suffolk.features) //get data to define path
.enter() //there are more data than elements, this selects them
.append("path") //appends path to data
.attr('class','outlines')
.attr("d", path3) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "rgb(240,240,240)")
.style("fill-opacity", ".5")
.style('stroke-opacity','.4')
.style("stroke-width", '.5')
.style("stroke", "rgb(0,0,0)")
g.selectAll("path3") //d3 geopath
.data(nassau.features) //get data to define path
.enter() //there are more data than elements, this selects them
.append("path") //appends path to data
.attr('class','outlines')
.attr("d", path3) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "rgb(240,240,240)")
.style("fill-opacity", ".5")
.style('stroke-opacity','.4')
.style("stroke-width", '.5')
.style("stroke", "rgb(0,0,0)")
var c = svg.selectAll("circle") //d3 geopath
.data(spots)
.enter() //there are more data than elements, this selects them
.append("circle") //appends path to data
.attr("cx", function(d) {return projection([d.long,d.lat])[0]})
.attr("cy", function(d) {return projection([d.long,d.lat])[1]})
.attr('r',3)
.attr('fill', 'black')
.style('fill-opacity','1')
.style('stroke','black')
.style('stroke-width','1')
.on('mouseover', spotText)
.on('mouseout' , removeSpotText)
function spotText(event,d){
d3.select(this).attr('fill' , 'green')
svg.append('text')
.attr('class' , 'spots')
.attr('x' , '700')
.attr('y' , '110')
.attr('font-family' , 'Helvetica')
.attr('font-size' , '.7em')
.attr('text-anchor' , 'start')
.attr('font-weight' , 'bold')
.text(d.name)
svg.append('text')
.attr('class' , 'spots')
.attr('x' , '700')
.attr('y' , '125')
.attr('font-family' , 'Helvetica')
.attr('font-size' , '.5em')
.attr('text-anchor' , 'start')
.attr('font-weight' , 'normal')
.text(d.description)
svg.append('line')
.attr('class' , 'spotLine')
.attr('x1' , '697')
.attr('y1' , '122')
.attr('x2' , projection([d.long,d.lat])[0])
.attr('y2' , projection([d.long,d.lat])[1])
.style('stroke-width' , '1')
.style('stroke' , 'black')
.style('stroke-dasharray' , '4 4')
}
function removeSpotText(event,d){
d3.select(this).attr('fill' , 'black')
d3.selectAll('text.spots').remove()
d3.selectAll('line.spotLine').remove()
}
return svg.node();
}