chart = {
const width = 960,
height = 960;
const svg = d3.create("svg")
.attr("viewBox", [70,80, width-800, height-800]);
var projection = d3
.geoMercator()
.fitSize([width - 50, height - 50], boundingBox);
var path1 = d3.geoPath().projection(projection);
var path2 = d3.geoPath().projection(projection);
var path3 = d3.geoPath().projection(projection);
var path4 = d3.geoPath().projection(projection);
var path5 = d3.geoPath().projection(projection);
var g = svg.append("g").attr("id", "paths");
g.selectAll("path2")
.data(subwayLines.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path2)
.style("fill", "none")
.style('stroke-opacity','.2')
.style("stroke-width", '.25')
.style("stroke", "rgb(0,0,0)")
g.selectAll("path3")
.data(buildingFootprints.features)
.enter()
.append("path")
.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", "1")
.style('stroke-opacity','.1')
.style("stroke-width", '.5')
.style("stroke", "rgb(0,0,0)")
g.selectAll("path4") //d3 geopath
.data(streets.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", path2) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "none")
.style('stroke-opacity','.75')
.style("stroke-width", '.25')
.style("stroke", "rgb(0,0,0)")
g.selectAll("path5") //d3 geopath
.data(borough.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", path2) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "none")
.style('stroke-opacity','.70')
.style("stroke-width", '.25')
.style("stroke", "rgb(0,0,0)")
var c = svg.selectAll("circle") //use this line the first time we create a circle
.data(fountains.features)
.enter() //there are more data than elements, this selects them
.append("circle") //appends path to data
.attr("cx", function(d) {return path1.centroid(d)[0]})//we use a function in order to draw ALL of the fountains - loop through the fountains
.attr("cy", function(d) {return path1.centroid(d)[1]})
.attr('r',1)
.style('fill','black')
.style('fill-opacity','1')
.on('mouseover',fountainText)
.on('mouseout',removeFountainText)
function fountainText(event,d){//this is everything that happens when we hover over a fountain
//console.log(d)
svg
.append("text")
.attr('x','100')
.attr('y','220')
.attr('class','fountain_position')
.style('font-family','helvetica')
.style('font-size','10px')
.style('font-weight','light')//use 'fill' to change color
.text(d.properties.Position)
var wrap = svg.selectAll("text.fountain_position")
.each(function(d, i) { wrap_text(d3.select(this), 75) });//control how many pixels wide our text block can be
svg
.append("line")
.attr('x1','240')
.attr('y1','195')
.attr('x2', path1.centroid(d)[0])
.attr('y2', path1.centroid(d)[1])
.attr('class','fLine')
.style('stroke-width', '1')
.style("stroke", "rgb(0,0,0)")
.style('stroke-dasharray', '6 4')
p.enter().append("polyline") //use this line the first time we create a polyline
.data(f1)
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr("points", function(d) {return d})//we use a function in order to draw ALL of the fountains - loop through the fountains
.attr("class", 'fountain')
.style('fill','black')
.style('stroke','none')
.style('stroke-width','.5')
p.enter().append("polyline") //use this line the first time we create a polyline
.data(f2)
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr("points", function(d) {return d})//we use a function in order to draw ALL of the fountains - loop through the fountains
.attr("class", 'fountain')
.style('fill','none')
.style('stroke','blue')
.style('stroke-width','2')
}//this is where fountainText function ends
function removeFountainText(){
d3.selectAll('text.fountain_position').remove()//geometry type, then class name
d3.selectAll('line.fLine').remove()
d3.selectAll('polyline.fountain').remove()
}
c.enter().append("circle") // use this line everytime after the first time we create a circle
.data(galleries.features)
.enter() //there are more data than elements, this selects them
.append("circle") //appends path to data
.attr("cx", function(d) {return path1.centroid(d)[0]})
.attr("cy", function(d) {return path1.centroid(d)[1]})
.attr('r',3)
.style('stroke','black')
.style('stroke-width','1')
.style('fill','red')
.style('fill-opacity','1')
c.enter().append("circle") // use this line everytime after the first time we create a circle
.data(personal_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]})//projection([d.long,d.lat])[0]
.attr("cy", function(d) {return projection([d.LONG,d.LAT])[1]})
.attr('r',1)
.style('stroke','black')
.style('stroke-width','.25')
.style('fill','cyan')
.style('fill-opacity','1')
svg
.append("text")
.attr('x','70')
.attr('y','90')
.style('font-family','georgia')
.style('font-size','7px')
.style('font-weight','bold')//use 'fill' to change color
.text('MARINAS MAP')
svg
.append("text")
.attr('x','70')
.attr('y','93')
.style('font-family','georgia')
.style('font-size','2px')
.style('font-weight','light')//use 'fill' to change color
.text('IN THE BEAUTIFUL CHELSEA ART DISTRICT')
svg
.append("line")
.attr('x1','70')
.attr('y1','94')
.attr('x2','170')
.attr('y2','94')
.style("stroke-width", '.25')
.style("stroke", "rgb(0,0,0)")
var p = svg.selectAll("polyline") //use this line the first time we create a polyline
.data(test1)
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr("points", function(d) {return d})//we use a function in order to draw ALL of the fountains - loop through the fountains
.style('fill','none')
.style('stroke','black')
.style('stroke-width','2')
p.enter().append("polyline") //use this line the first time we create a polyline
.data(test2)
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr("points", function(d) {return d})//we use a function in order to draw ALL of the fountains - loop through the fountains
.style('fill','cyan')
.style('stroke','black')
.style('stroke-width','2')
return svg.node();
}