Public
Edited
Jul 27, 2023
Insert cell
# base map - cornell 2023-0713
Insert cell
d3 = require("d3@6")
Insert cell
chart = {
const width = 960,
height = 900;
const svg = d3.create("svg")
.attr("viewBox", [-150, 80, width-100, height-100]);

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

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 g = svg.append("g").attr("id", "paths");
g.selectAll("path2") //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", '.75')
.style("stroke", "rgb(247,147,30)")

g.selectAll("path3") //d3 geopath
.data(parks.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(238,232,222)")
.style("fill-opacity", "1")
.style('stroke-opacity','.4')
.style("stroke-width", '.5')
.style("stroke", "rgb(0,0,0)")

g.selectAll("path4") //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", path4) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "rgb(46,49,146)")
.style("fill-opacity", ".1")
.style('stroke-opacity','.4')
.style("stroke-width", '.5')
.style("stroke", "rgb(0,0,0)")

g.selectAll("path4") //d3 geopath
.data(footprints.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", path4) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "rgb(46,49,146)")
.style("fill-opacity", ".2")
.style('stroke-opacity','.4')
.style("stroke-width", '.15')
.style("stroke", "rgb(0,0,0)")


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.5)
.attr('fill','rgb(247,147,30)')
.style('fill-opacity','.8')

var p = svg.selectAll("polyline") //d3 geopath

p.enter().append("polyline") //d3 geopathAT
.data(philosopher)
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr("points", function(d) {return d})
.style("stroke","rgb(46,49,146)")
.style("stroke-width",".7px")
.style("fill","none")

p.enter().append("polyline") //d3 geopathAT
.data(className)
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr("points", function(d) {return d})
.style("stroke","rgb(46,49,146)")
.style("stroke-width",".2px")
.style("fill","none")

p.enter().append("polyline") //d3 geopathAT
.data(ccup)
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr("points", function(d) {return d})
.style("stroke","rgb(46,49,146)")
.style("stroke-width","2.5px")
.style("fill","none")
p.enter().append("polyline") //d3 geopath
.data(ccup)
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr("points", function(d) {return d.Icon})
.style("stroke","black")
.style("stroke-width","20px")
.style("fill","black")
.attr("transform",function(d){return 'translate('+ projection([d.lat,d.long])[0]+" "+ projection([d.lat,d.long])[1] + ")"})
.on("mouseover",museumroutes)
.on("mouseover",removemuseumroutes)

function museumroutes(i,d){

console.log(d.name)

if(d.name=="The Skyscraper Museum'")
p.enter().append("polyline")
.data(route1)
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr("points", function(d) {return d.Icon})
.style("stroke","black")
.style("stroke-width","20px")
.style("fill","black")
}

function removemuseumroutes(){
svg.selectAll("polyline.route1").remove()
}



var t = svg.selectAll("text") //d3 geopath
.data(subSts.features)
.enter() //there are more data than elements, this selects them
.append("text") //appends path to data
.attr("x", function(d) {return path1.centroid(d)[0]})
.attr("y", function(d) {return path1.centroid(d)[1]-5})
.style('fill','rgb(0,32,255)')
.style("font-family","didot")
.style("font-weight","100")
.style("font-size","4.5px")
.style("text-anchor","end")
.text(function(d) {return d.properties.name})
c.enter().append("circle")//after the first use of a circle, use this method to add more
.data(museumData)
.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.5)
.attr('fill','rgb(96,96,96)')
.style('fill-opacity','1')
.on("mouseover",museumHover)
.on("mouseout",museumRemove)

function museumHover(i,d){
console.log(d.name)

svg.append("text")
.attr("class","dText")
.attr("x","20")
.attr("y","300")
.style("font-family","didot")
.style("font-weight","800")
.style("font-size","15px")
.style("text-anchor","start")
.text(d.name)

svg.append("text")
.attr("class","dText")
.attr("x","20")
.attr("y","310")
.style("font-family","didot")
.style("font-weight","200")
.style("font-size","7px")
.style("text-anchor","start")
.text(d.description)

var wrap = svg.selectAll("text.dText")
.each(function(d, i) { wrap_text(d3.select(this), 350) });

svg.append("line")
.attr("class","dLine")
.attr("x1","50")
.attr("y1","340")
.attr("x2",projection([d.long, d.lat])[0])
.attr("y2",projection([d.long, d.lat])[1])
.style("stroke","red")
.style("stroke-width",".5px")
.style("stroke-dasharray","4 1 2")

p.enter().append("polyline") //d3 geopath
.data(droneMap)
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr("points", function(d) {return d})
.attr("class","dMap")
.style("stroke","rgb(0,32,255)")
.style("stroke-width",".5px")
.style("fill","none")
.style("stroke-dasharray","4 1 2")

p.enter().append("polyline") //d3 geopath
.data(droneMapCircle)
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr("points", function(d) {return d})
.attr("class","dMapcircle")
.style("stroke","rgb(0,32,255)")
.style("stroke-width",".5px")
.style('fill-opacity','.15')
.style("stroke-dasharray","4 1 2")
.style("fill","rgb(247,147,30)")

p.enter().append("polyline") //d3 geopath
.data(drone)
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr("points", function(d) {return d})
.attr("class","dronesh")
.style("stroke","rgb(0,32,255)")
.style("stroke-width",".3px")
.style("fill","none")
.style('fill-opacity','0')


p.enter().append("polyline") //d3 geopathAT
.data(museumicon)
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr("class","MIcon")
.attr("points", function(d) {return d})
.style("stroke","black")
.style("stroke-width",".55px")
.style("fill","none")
}

function museumRemove(){
svg.selectAll("text.dText").remove()
svg.selectAll("line.dLine").remove()
svg.selectAll("polyline.dMap").remove()
svg.selectAll("polyline.dMapcircle").remove()
svg.selectAll("polyline.MIcon").remove()
svg.selectAll("polyline.dronesh").remove()
}
return svg.node();
}
Insert cell
subSts = FileAttachment("Subway Station.geojson").json()
Insert cell
bldgs = FileAttachment("bldgs.geojson").json()
Insert cell
bbox2 = FileAttachment("Bounding Box.geojson").json()
Insert cell
subLns = FileAttachment("Subway Line.geojson").json()
Insert cell
parks = FileAttachment("Parks.geojson").json()
Insert cell
boundary = FileAttachment("Geometry.geojson").json()
Insert cell
footprints = FileAttachment("Footprints.geojson").json()
Insert cell
Insert cell
museumData = d3.csv(museumDataLink,d3.autoType)
Insert cell
import { wrap_text, wrap_text_nchar } from "@ben-tanen/svg-text-and-tspan-word-wrapping"
Insert cell
museumicon = FileAttachment("museum icon@3.txt").tsv({array:true})
Insert cell
droneMap = FileAttachment("Drone Map.txt").tsv({array:true})
Insert cell
ccup = FileAttachment("museum icon2@4.txt").tsv({array:true})
Insert cell
museumwIcon = {

var combinedData = []
for (let i = 0; i < museumData.length; i++) {
combinedData.push({name:museumData[i].name,lat:museumData[i].lat,long:museumData[i].long,description:museumData[i].description,Icon:ccup})
}

return combinedData
}
Insert cell
droneMapCircle = FileAttachment("Drone Map Circle@1.txt").tsv({array:true})
Insert cell
box = FileAttachment("Box.txt").tsv({array:true})
Insert cell
philosopher = FileAttachment("Philosopher Path@3.txt").tsv({array:true})
Insert cell
className = FileAttachment("Class Name.txt").tsv({array:true})
Insert cell
drone = FileAttachment("Drone@1.txt").tsv({array:true})
Insert cell
route1 = FileAttachment("Route.txt").tsv({array:true})
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