Public
Edited
Jul 13, 2023
Fork of base map
1 fork
Insert cell
# base map - cornell summer 2023 - 0713
Insert cell
d3 = require("d3@6")
Insert cell
chart = {
const width = 960,
height = 900;
const svg = d3.create("svg")
.attr("viewBox", [50, 50, width-100, height-100]);

// Use Mercator projection
var projection = d3
.geoMercator()
.fitSize([width - 50, height - 50], bbox);

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");

/////////// LINES = bounding box
g.selectAll("path1") //d3 geopath
.data(bbox.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", path1) //The d attribute defines a path to be drawn, only applies to appended elements
.style("stroke", "none")
.style('fill-opacity','.25')
.style("fill", "rgb(237, 125, 58)")
/////////// LINES = borough boundaries
g.selectAll("path2") //d3 geopath
.data(boundary.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", path1) //The d attribute defines a path to be drawn, only applies to appended elements
.style("stroke", "none")
.style('fill-opacity','1')
.style("fill", "rgb(240,240,240)")

/////////// LINES = building outlines
g.selectAll("path3") //d3 geopath
.data(bldgs.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(255,255,255)")
.style("fill-opacity", ".25")
.style('stroke-opacity','1')
.style("stroke-width", '1')
.style("stroke", "rgb(255,255,255)")

/////////// LINES = street centerlines
g.selectAll("path4") //d3 geopath
.data(stLns.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','1')
.style("stroke-width", '1.25')
.style("stroke", "rgb(220,220,220)")

/////////// LINES = subway lines
g.selectAll("path5") //d3 geopath
.data(subLns.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','1')
.style("stroke-width", '2')
.style("stroke", "rgb(200,200,200)")
/*
var c = svg.selectAll("circle") //d3 geopath
.data(subSts.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)
.attr('fill','black')
.style('fill-opacity','1')

*/

var c = svg.selectAll("circle") //d3 geopath
/////////// DOTS = Chinese spots
c.enter().append("circle") //after the first use of a circle, use this method to add more
.data(chineseSpot)
.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',6)
.attr('fill','rgb(237, 125, 58)')
.style('fill-opacity','.85')
.style('stroke','rgb(255,255,255)')
.style('stroke-width','2')

/////////// DOTS = ATM locations
c.enter().append("circle") //after the first use of a circle, use this method to add more
.data(atmLoc)
.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',4)
.attr('fill','rgb(31, 1, 185)')
.style('fill-opacity','.75')
.style('stroke','rgb(255,255,255)')
.style('stroke-width','1')


return svg.node();
}
Insert cell
subLns = FileAttachment("nyc_subway.geojson").json()
Insert cell
bldgs = FileAttachment("bldgs@1.geojson").json()
Insert cell
bbox = FileAttachment("site_boundary@3.geojson").json()
Insert cell
stLns = FileAttachment("nyc_street@1.geojson").json()
Insert cell
boundary = FileAttachment("nyc_boundary@1.geojson").json()
Insert cell
Insert cell
chineseSpot = d3.csv(chineseSpotLink,d3.autoType)
Insert cell
Insert cell
atmLoc = d3.csv(atmLocLink,d3.autoType)
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more