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], portlandbbox);
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 path6 = d3.geoPath().projection(projection);
var g = svg.append("g").attr("id", "paths");
g.selectAll("path2")
.data(portlandstreets.features)
.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','1')
.style("stroke-width", '.75')
.style("stroke", "rgb(0,0,0)")
g.selectAll("path3") //d3 geopath
.data(portlandbuilds.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("path4") //d3 geopath
.data(portlandbikeride.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(197, 227, 226)")
.style("fill-opacity", "0.15")
.style('stroke-opacity','1')
.style("stroke-width", '1')
.style("stroke", "rgb(0,0,0)")
.style('stroke-dasharray','2 2')
g.selectAll("path4") //d3 geopath
.data(portlandShoreline.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", ".2")
.style('stroke-opacity','.5')
.style("stroke-width", '.02')
.style("stroke", "rgb(0,0,0)")
/* g.selectAll("path5") //d3 geopath
.data(portlandPoints.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(0,0,0)")
.style("fill-opacity", "1")
.style('stroke-opacity','1')
.style("stroke-width", '1')
.style("stroke", "rgb(0,0,0)") */
var c = svg.selectAll("circle") //circle
.data(locations)
.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', colorType) // add function to control color by 'type'
.style('fill-opacity','1')
.style('stroke','black')
.style('stroke-width','0.1')
.on('mouseover', spotText)
.on('mouseout', removeSpotText)
function colorType(d,i){
var color = 'black'
if(d.Type=='food/drink')(color = 'rgb(37, 79, 107)')
if(d.Type=='historic')(color = 'rgb(125, 121, 102)')
if(d.Type=='park')(color = 'rgb(95, 163, 113)')
if(d.Type=='store')(color = 'rgb(153, 127, 145)')
return color
}
function spotText(event,d) {
d3.select(this).attr('fill','yellow')
svg.append('text')
.attr('class','locations')
.attr('x', projection([d.Long,d.Lat])[0])
.attr('y', projection([d.Long,d.Lat])[1])
.attr('x', 300)
.attr('y', 150)
.attr('font-family','Calibri')
.attr('font-size','.7em')
.attr('text-anchor','start')
.attr('font-weight','bold')
.text(d.Name)
svg.append('text')
.attr('class','locations')
.attr('x', projection([d.Long,d.Lat])[0])
.attr('y', projection([d.Long,d.Lat])[1])
.attr('x', 300)
.attr('y', 160)
.attr('font-family','Calibri')
.attr('font-size','.5em')
.attr('text-anchor','start')
.attr('font-weight','lighter')
.text(d.Description)
svg.append('line')
.attr('class','locations')
.attr('x1','300')
.attr('y1','165')
.attr('x2',projection([d.Long,d.Lat])[0])
.attr('y2','165')
.style("stroke-width", '1')
.style('stroke','black')
.style('stroke-dasharray','4 4')
svg.append('line')
.attr('class','locations')
.attr('x1',projection([d.Long,d.Lat])[0])
.attr('y1','165')
.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',colorType)
d3.selectAll('text','locations').remove()
d3.selectAll('line','locationsline').remove()
}
/*
c.enter.append('circle') // format to add additional circles
.data(trees)
.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')
*/
return svg.node();
}