chart = {
const width = 960,
height = 900;
const svg = d3.create("svg")
.attr("viewBox", [12, 60, width-100, height-80]);
var projection = d3
.geoMercator()
.fitSize([width - 60, height - 50], boundingBox);
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");
svg.append('image')
.attr('href',streetsUnderlay)
.attr('class','spotImage')
.attr('x', '-15')
.attr('y','-50')
.attr('width', 905)
.attr('height', 845)
g.selectAll("path3")
.data(boroughs1.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path3)
.style("fill", "none")
.style('stroke-opacity','1')
.style("stroke-width", '1.25')
.style("stroke", "slategrey")
g.selectAll("path3")
.data(boroughs2.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path3)
.style("fill", "slategrey")
.style("fill-opacity", ".1")
.style('stroke-opacity','1')
.style("stroke-width", '.5')
.style("stroke", "slategrey")
g.selectAll("path3")
.data(parks2V2.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path3)
.style("fill", "lightsteelblue")
.style("fill-opacity", ".5")
.style('stroke-opacity','.1')
.style("stroke-width", '.1')
.style("stroke", "lightsteelgrey")
g.selectAll("path3")
.data(parks3.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path3)
.style("fill", "none")
.style("fill-opacity", ".5")
.style('stroke-opacity','.1')
.style("stroke-width", '.1')
.style("stroke", "lightsteelgrey")
g.selectAll("path3")
.data(waterfrontParks2.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path3)
.style("fill", "slategrey")
.style("fill-opacity", ".1")
.style('stroke-opacity','.1')
.style("stroke-width", '.1')
.style("stroke", "lightslategrey")
g.selectAll("path3")
.data(parkWaters.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path3)
.style("fill", "none")
.style('stroke-opacity','.1')
.style("stroke-width", '.1')
.style("stroke", "black")
g.selectAll("path2")
.data(ferryLine.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path2)
.style("fill", "none")
.style('stroke-opacity','1')
.style("stroke-width", '2')
.style("stroke", "dodgerblue")
.style('stroke-dasharray','2 2')
g.selectAll("path2")
.data(trail1.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path2)
.style("fill", "none")
.style('stroke-opacity','1')
.style("stroke-width", '2')
.style("stroke", "dodgerblue")
.style('stroke-dasharray','2 2')
g.selectAll("path2")
.data(trail2.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path2)
.style("fill", "none")
.style('stroke-opacity','1')
.style("stroke-width", '2')
.style("stroke", "dodgerblue")
.style('stroke-dasharray','2 2')
g.selectAll("path2")
.data(batBoundary.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path2)
.style("fill", "slategrey")
.style("fill-opacity", ".3")
.style('stroke-opacity','.1')
.style("stroke-width", '.1')
.style("stroke", "lightslategrey")
.on('mouseover', spotImage3)
.on('mouseout', removespotImage3)
g.selectAll("path2")
.data(rockawayBeachBoundary.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path2)
.style("fill", "slategrey")
.style("fill-opacity", ".3")
.style('stroke-opacity','.1')
.style("stroke-width", '.1')
.style("stroke", "lightslategrey")
.on('mouseover', spotImage2)
.on('mouseout', removespotImage2)
g.selectAll("path2")
.data(cemeteryBoundary.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path2)
.style("fill", "slategrey")
.style("fill-opacity", ".3")
.style('stroke-opacity','.1')
.style("stroke-width", '.1')
.style("stroke", "lightslategrey")
.on('mouseover', spotImage1)
.on('mouseout', removespotImage1)
g.selectAll("path2")
.data(twaBoundary2.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path2)
.style("fill", "slategrey")
.style("fill-opacity", ".3")
.style('stroke-opacity','.1')
.style("stroke-width", '.1')
.style("stroke", "lightslategrey")
.on('mouseover', spotImage)
.on('mouseout', removespotImage)
function spotImage(event,d){
d3.select(this).attr('fill','lavenderblush')
svg.append('image')
.attr('xlink:href','https://api.time.com/wp-content/uploads/2019/08/twa-hotel-queens-new-york.jpg')
.attr('class','spotImage')
.attr('x', '485')
.attr('y','720')
.attr('width', 350)
.attr('height', 150)
}
function removespotImage(event,d){
d3.select(this).attr('fill',colorType)
d3.selectAll('image.spotImage').remove()
}
function spotImage1(event,d){
d3.select(this).attr('fill','lavenderblush')
svg.append('image')
.attr('xlink:href','https://upload.wikimedia.org/wikipedia/commons/thumb/1/18/Green-Wood_Cemetery_gate_%2853784p%29_cropped.jpg/1200px-Green-Wood_Cemetery_gate_%2853784p%29_cropped.jpg')
.attr('class','spotImage1')
.attr('x', '485')
.attr('y','720')
.attr('width', 350)
.attr('height', 150)
}
function removespotImage1(event,d){
d3.select(this).attr('fill',colorType)
d3.selectAll('image.spotImage1').remove()
}
function spotImage2(event,d){
d3.select(this).attr('fill','lavenderblush')
svg.append('image')
.attr('xlink:href','https://media.timeout.com/images/103881813/750/562/image.jpg')
.attr('class','spotImage2')
.attr('x', '485')
.attr('y','720')
.attr('width', 350)
.attr('height', 150)
}
function removespotImage2(event,d){
d3.select(this).attr('fill',colorType)
d3.selectAll('image.spotImage2').remove()
}
function spotImage3(event,d){
d3.select(this).attr('fill','lavenderblush')
svg.append('image')
.attr('xlink:href','https://www.nycgo.com/images/venues/30801/brooklyn-army-terminal-sunset-park-manhattan-nyc-freightnyc_july_2018-071__large.jpg')
.attr('class','spotImage3')
.attr('x', '485')
.attr('y','720')
.attr('width', 350)
.attr('height', 150)
}
function removespotImage3(event,d){
d3.select(this).attr('fill',colorType)
d3.selectAll('image.spotImage3').remove()
}
var c = svg.selectAll("circle")
.data(spots)
.enter()
.append("circle")
.attr("cx", function(d) {return projection([d.longitude, d.latitude])[0]})
.attr("cy", function(d) {return projection([d.longitude, d.latitude])[1]})
.attr('r',4)
.attr('fill',colorType)
.style('fill-opacity','2')
.style('stroke','black')
.style('stroke-width','.8')
.on('mouseover', spotText)
.on('mouseout', removespotText)
function colorType(d,i){
var color = 'steelblue'
if(d.type=='Food'){color = 'steelblue'}
if(d.type=='Academics'){color = 'steelblue'}
if(d.type=='House'){color = 'steelblue'}
if(d.type=='Sports Facility'){color = 'steelblue'}
if(d.type=='Social Facility'){color = 'steelblue'}
if(d.type=='Market'){color = 'steelblue'}
if(d.type=='Field'){color = 'steelblue'}
return color
}
svg.append('text')
.attr('x','145')
.attr('y','725')
.attr('font-family','Helvetica')
.attr('font-size','.8em')
.attr('font-weight','light')
.attr('text-anchor','end')
.text(totalValues[0])
svg.append('text')
.attr('x','40')
.attr('y','725')
.attr('font-family','Helvetica')
.attr('font-size','.8em')
.attr('font-weight','bold')
.attr('text-anchor','start')
.text('Total Hours: ')
svg.append('text')
.attr('x','190')
.attr('y','745')
.attr('font-family','Helvetica')
.attr('font-size','.8em')
.attr('font-weight','light')
.attr('text-anchor','end')
.text(totalValues[1])
svg.append('text')
.attr('x','40')
.attr('y','745')
.attr('font-family','Helvetica')
.attr('font-size','.8em')
.attr('font-weight','bold')
.attr('text-anchor','start')
.text('Total Experience: ')
svg.append("rect")
.attr("x", 33)
.attr("y", 708)
.attr("width", 162)
.attr("height", 44)
.attr('fill', 'lightsteelblue')
.style('fill-opacity','.1')
.style('stroke', 'slategrey')
.style('stroke-width', '0.75')
if(totalEmotions[0]="🤩" && totalValues[1]>450){
svg.append('text')
.attr('class','spots')
.attr('x','480')
.attr('y','135')
.attr('font-family','Helvetica')
.attr('font-size','.8em')
.attr('text-anchor','middle')
.attr('font-weight','bold')
.text('(YOU WERE GREAT!)')
}
if(totalEmotions[0]="🤷" && totalValues[0]>5 && totalValues[1]<450){
svg.append('text')
.attr('class','spots')
.attr('x','480')
.attr('y','135')
.attr('font-family','Helvetica')
.attr('font-size','.8em')
.attr('text-anchor','middle')
.attr('font-weight','bold')
.text('(YOU WERE A TROOPER!)')
}
if(totalEmotions[0]="💩" && totalValues[1]<350){
svg.append('text')
.attr('class','spots')
.attr('x','480')
.attr('y','135')
.attr('font-family','Helvetica')
.attr('font-size','.8em')
.attr('text-anchor','middle')
.attr('font-weight','bold')
.text('(BETTER LUCK NEXT TIME!)')
}
if(totalValues[0]>7){
svg.append('text')
.attr('class','spots')
.attr('x','480')
.attr('y','120')
.attr('font-family','Helvetica')
.attr('font-size','1.5em')
.attr('text-anchor','middle')
.attr('font-weight','bold')
.text('⌛TOO SLOW⌛')
}
if(totalValues[0]<5){
svg.append('text')
.attr('class','spots')
.attr('x','480')
.attr('y','120')
.attr('font-family','Helvetica')
.attr('font-size','1.8em')
.attr('text-anchor','middle')
.attr('font-weight','bold')
.text('🏃🏻TOO RUSHED🏃🏻')
}
if(totalValues[0]<7 && totalValues[1]>450 ){
svg.append('text')
.attr('class','spots')
.attr('x','480')
.attr('y','120')
.attr('font-family','Helvetica')
.attr('font-size','1.8em')
.attr('text-anchor','middle')
.attr('font-weight','bold')
.text('💯 PERFECT TRIP 💯')
}
function spotText(event,d){
d3.select(this).attr('fill','lavenderblush')
svg.append('text')
.attr('class','spots')
.attr('x', '550')
.attr('y','687')
.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', '550')
.attr('y','705')
.attr('font-family','Helvetica')
.attr('font-size', '.65em')
.attr('text.anchor','start')
.attr('font-weight', 'normal')
.text(d.description)
svg.append('line')
.attr('class','spotLine')
.attr('x1', '550')
.attr('y1', '692')
.attr('x2', projection([d.longitude, d.latitude])[0])
.attr('y2', '692')
.style('stroke-width','.5')
.style('stroke','black')
.style('stroke-dasharray','2 2')
svg.append('line')
.attr('class','spotLine')
.attr('x1', projection([d.longitude, d.latitude])[0])
.attr('y1', '692')
.attr('x2', projection([d.longitude, d.latitude])[0])
.attr('y2', projection([d.longitude, d.latitude])[1])
.style('stroke-width','.7')
.style('stroke','darkblue')
.style('stroke-dasharray','2 2')
}
function removespotText(event,d){
d3.select(this).attr('fill',colorType)
d3.selectAll('text.spots').remove()
d3.selectAll('line.spotLine').remove()
}
return svg.node();
}