Public
Edited
Aug 6, 2024
Insert cell
Insert cell
chart = {
const width = 900,//pixel size of the map
height = 900;
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width-50, height-10]);

// Use Mercator projection
var projection = d3
.geoMercator()//projection system used
.fitSize([width, height], looser);//out bounding box is here

var path = d3.geoPath().projection(projection);//need one of these for each line layer from qgis
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.selectAll('g').attr("id", "paths");//qgis lines variable //one variable for each geometry type
var c = svg.selectAll("circle")//for circles
var p = svg.selectAll("polyline")//for polylines from rhino
var t = svg.selectAll("text")
var l = svg.selectAll("line")


//lines from rhino
polyline(seaExtended,'rgb(236,247,254)','100','0.9','rgb(246,244,254)')

//static lines from qgis
//staticLines(path3, subways.features,"none",1,.5,"rgb(180,180,180)")
staticLines(path5, sea.features,"rgb(236,244,254)",'1','0.2',"rgb(245,246,251)")
staticLines(path5, borough.features,"rgb(230,230,228)",'1','0.2',"rgb(200,200,200)")
staticLines(path5, parks1.features,"rgb(200,215,200)",'1','.1',"rgb(185,200,185)")
staticLines(path5, residential.features,"rgb(250,250,220)",'0.2','1',"rgb(247,247,217)")
staticLines(path5, streetCenterline.features,"none",'1','0.2',"rgb(170,170,170)")


function staticLines(path, data, sfill, sOpac, sW, stroke){

g.enter().append("path")
.data(data) //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", path) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", sfill)
.style('stroke-opacity',sOpac)
.style("stroke-width", sW)
.style("stroke", stroke)
}


//static points from qgis
staticCircles(wifiHotspot.features,'2','rgb(253,236,1)','1',"0")
staticCircles(linkStations.features,'2','rgb(85,65,125)','1',"0")

function staticCircles(data,r,sfill, sOpac, sWidth){

c.enter().append('circle')
.data(data) //get data to define path
.enter() //there are more data than elements, this selects them
.append("circle") //appends path to data
.attr('cx',function(d) {return path.centroid(d)[0]})
.attr("cy",function(d) {return path.centroid(d)[1]})
.attr('r', r)
.attr('fill', sfill)
.style('fill-opacity',sOpac)
.style("stroke-width",sWidth)



}


//lines from rhino
polyline(body,'none','1','0.65','rgb(191,63,63)')
polyline(pivot,'none','1','0.55','rgb(155,181,155)')
polyline(camera,'none','1','0.55','rgb(89,166,254)')
polyline(f,'rgb(177,62,66)','1','1','rgb(215,66,72)')
polyline(l1,'rgb(177,62,66)','1','1','rgb(215,66,72)')
polyline(y,'rgb(186,93,81)','1','1','rgb(215,66,72)')
polyline(untitled,'rgb(196,156,155)','1','1','rgb(215,66,72)')
polyline(gCarryingDrone,'none','1','1','rgb(196,156,155)')
polyline(drone,'none','100','0.5','rgb(196,156,155)')
polyline(wifidrone,'none','100','2','rgb(245,236,15)')
polyline(dronelink,'none','100','2','rgb(185,25,25)')
polyline(dronelink1,'none','100','0.9','rgb(185,25,25)')

function polyline(data, sfill, sOpac, sW, stroke){

g.enter().append("polyline")
.data(data) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr("points", function(d){return d}) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", sfill)
.style('stroke-opacity',sOpac)
.style("stroke-width", sW)
.style("stroke", stroke)
}
p.enter().append("polyline")
.data(Newbar) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr("points", martini) //The d attribute defines a path to be drawn, only applies to appended elements
.attr('transform', function(d) {
var coordinates = projection([d.Longitude, d.Latitude]);
return 'translate(' + (coordinates[0] - 10) + ',' + (coordinates[1] + 10) + ')';
})
.style("fill", 'rgb(71,80,216)')
.style("stroke-width", '1')
.style("stroke", 'rgb(85,65,125)')
.on("mouseover", addText)
.on("mouseout", removeText)

p.enter().append("polyline")
.data(wifipoints) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr("points", function(d){return d}) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", 'white')
.style("opacity", '0.5')
.style("stroke-width", '1')
.style("stroke", 'white')
.on("mouseover", addwifistream)
.on("mouseout", removewifistream)

function addwifistream(event, d) {
p.enter().append("polyline")
.data(wifistream) //get data to define path
.enter()
.append('polyline')
.attr('class', 'wifistream')
.attr('points', function(d){return d}) // The d attribute defines a path to be drawn, only applies to appended elements
.style('stroke-width', '0.2')
.style('stroke', 'rgb(186,93,81)')
.style('fill', 'rgb(215,66,72)')
.style('opacity', '0.5')
}
function removewifistream(event, d) {
svg.selectAll('.wifistream').remove(); // Correctly select and remove elements with class 'wifistream'
}

p.enter().append("polyline")
.data(dronepath) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr("points", function(d){return d}) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", 'none')
.style("stroke-width", '1')
.style("stroke-opacity", '0.5')
.style("stroke", 'white')
.style("stroke-dasharray", "5 5")
.on("mouseover", addfire) // add 'mouseover' event listener
.on("mouseout", removefire); // add 'mouseout' event listener
function addfire(event, d) {
p.enter().append("polyline")
.data(fire) //get data to define path
.enter()
.append('polyline')
.attr('class', 'fire')
.attr('points', function(d){return d}) // The d attribute defines a path to be drawn, only applies to appended elements
.style('stroke-width', '1')
.style('stroke', 'rgb(215,66,72)')
.style('stroke-opacity', '1')
.style('fill', 'yellow')
.style('fill-opacity', '0.5')
}
function removefire(event, d) {
svg.selectAll('.fire').remove(); // Correctly select and remove elements with class 'wifistream'
}












p.enter().append("polyline")
.data(bodynew) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr("points", function(d){return d}) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", 'white')
.style("stroke-width", '3')
.style("stroke-opacity", '0.')
.style("stroke", 'rgb(215,66,72)')
.style("stroke-dasharray", "2 3")
.on("mouseover", addextra) // add 'mouseover' event listener
.on("mouseout", removeextra); // add 'mouseout' event listener
function addextra(event, d) {
p.enter().append("polyline")
.data(extra) //get data to define path
.enter()
.append('polyline')
.attr('class', 'extra')
.attr('points', function(d){return d}) // The d attribute defines a path to be drawn, only applies to appended elements
.style('stroke-width', '0.2')
.style('stroke', 'rgb(186,93,81)')
.style('fill', 'rgb(215,66,72)')
.style('opacity', '0.1')
}
function removeextra(event, d) {
svg.selectAll('.extra').remove(); // Correctly select and remove elements with class 'wifistream'
}










//display names from spreadsheet
t.enter().append('text')
.data(symbol) //get data to define path
.enter() //there are more data than elements, this selects them
.append("text") //appends path to data
//.attr('class','spots')
.attr('x',200)
.attr('y',function(d,i) {return 400+(i*15);})
.attr('fill', 'rgb(186,93,81)')
.style('font-family','helvetica')
.style('text-anchor','end')
.style("font-size", "10px")
.text(function(d) {
return d.Name; // assuming 'Name' is a property of your data object
})
.on("mouseover",symboltext)
.on("mouseout",removesymboltext)
function removesymboltext(event,d){
svg.selectall('line.symline').remove()
}
function symboltext(event,d){
//display lines
l.enter().append('line')
.data(symbol) //get data to define path
.enter() //there are more data than elements, this selects them
.append("line") //appends path to data
.attr('class','symline')
.attr('x1',200)
.attr('y1',function(d,i) {return 400+(i*15);})
.attr('x2',function(d) {return projection([d.Long,d.Lat])[0]-5})
.attr("y2",function(d,i) {return 400+(i*15);})
.attr('stroke', 'rgb(71,80,216)')
.attr('stroke-width', '0.2')
.style("stroke-dasharray", "2 3")

//display lines
l.enter().append('line')
.data(symbol) //get data to define path
.enter() //there are more data than elements, this selects them
.append("line") //appends path to data
.attr('class','symline')
.attr('x1',function(d) {return projection([d.Long,d.Lat])[0]-5})
.attr('y1',function(d,i) {return 400+(i*15);})
.attr('x2',function(d) {return projection([d.Long,d.Lat])[0]-5})
.attr("y2",function(d) {return projection([d.Long,d.Lat])[1]+5})
.attr('stroke', 'rgb(71,80,216)')
.attr('stroke-width', '0.2')
.style("stroke-dasharray", "2 3")
//display lines
// l.enter().append('line')
//.data(symbol) //get data to define path
//.enter() //there are more data than elements, this selects them
//.append("line") //appends path to data
//.attr('class','spots')
//.attr('x1',200)
//.attr('y1',function(d,i) {return 400+(i*15);})
//.attr('x2',function(d) {return projection([d.Long,d.Lat])[0]-5})
//.attr("y2",function(d) {return projection([d.Long,d.Lat])[1]+5})
//.attr('stroke', 'rgb(186,93,81)')
//.attr('stroke-width', '1')
}

//points from spreadsheet
c.enter().append('circle')
.data(Newbar) //get data to define path
.enter() //there are more data than elements, this selects them
.append("circle") //appends path to data
.attr('class','spots')
.attr('cx',function(d) {return projection([d.Longitude,d.Latitude])[0]-5})
.attr("cy",function(d) {return projection([d.Longitude,d.Latitude])[1]+5})
.attr('r', 1)
.attr('fill', 'yellow')
.style('fill-opacity','1')
.style("stroke-width", "0.5")
.style("stroke", "black")
.on("mouseover", addText)
.on("mouseout", removeText)

c.enter().append('circle')
.data(symbol) //get data to define path
.enter() //there are more data than elements, this selects them
.append("circle") //appends path to data
.attr('class','spots')
.attr('cx',function(d) {return projection([d.Long,d.Lat])[0]-5})
.attr("cy",function(d) {return projection([d.Long,d.Lat])[1]+5})
.attr('r', 1)
.style("stroke-width", "50")
.style("stroke", "rgb(71,80,216)")
.style("stroke-opacity", "0.1")
.on("mouseover", addText)
.on("mouseout", removeText)


function addText(event,d) {
svg//draw text
.append("text") //appends path to data
.attr('class','BText')
.attr('x',projection([d.Longitude,d.Latitude])[0])
.attr("y",projection([d.Longitude,d.Latitude])[1])
.attr('fill', 'rgb(177,62,66)')
.style('font-family','helvetica')
.style("font-size", "15px")
.text(d.Name)

svg//draw text
.append("text") //appends path to data
.attr('class','BText')
.attr('x',50)
.attr("y",375)
.attr('fill', 'rgb(186,93,81)')
.style('font-family','impact')
.style("font-size", "25px")
.text(d.Description)
}

function removeText() {
svg.selectAll('text,BText').remove()
}
return svg.node();
}

Insert cell
extra = FileAttachment("newhighlight.txt").tsv({array:true})
Insert cell
bodynew = FileAttachment("bodynew.txt").tsv({array:true})
Insert cell
symbol = d3.csv(lemon,d3.autoType)
Insert cell
lemon = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vQ_RsWCCxKq7DtYJ1s6n7n-NG0EsZjkUcf1Cselj53yIvpPs19pZARobNyTBI9J8nr_36y0mK22jLFS/pub?output=csv'
Insert cell
allnightlong = FileAttachment("allnightlong.txt").tsv({array:true})
Insert cell
fire = FileAttachment("fire.txt").tsv({array:true})
Insert cell
wifipoints = FileAttachment("WIFIPOINTS@2.txt").tsv({array:true})
Insert cell
dronepath = FileAttachment("dronepath.txt").tsv({array:true})
Insert cell
NewbarL = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vRuUyBX3DpRF4T8NT6ZOgi67GMU2IH64oSpkGRj5IfkpEVKMN696SCslOjkXtXYNeMzprBTJOmZsrKn/pub?output=csv'
Insert cell
Newbar = d3.csv(NewbarL,d3.autoType)
Insert cell
seaExtended = FileAttachment("Sea Extended.txt").tsv({array:true})
Insert cell
dronelink1 = FileAttachment("DroneLink1.txt").tsv({array:true})
Insert cell
wifidrone = FileAttachment("WifiDrone.txt").tsv({array:true})
Insert cell
Insert cell
drone = FileAttachment("Drone Route@1.txt").tsv({array:true})
Insert cell
f = FileAttachment("f.txt").tsv({array:true})
Insert cell
l = FileAttachment("L.txt").tsv({array:true})
Insert cell
y = FileAttachment("Y.txt").tsv({array:true})
Insert cell
untitled = FileAttachment("5.txt").tsv({array:true})
Insert cell
gCarryingDrone = FileAttachment("g carrying drone.txt").tsv({array:true})
Insert cell
body = FileAttachment("Body@3.txt").tsv({array:true})
Insert cell
camera = FileAttachment("Camera@3.txt").tsv({array:true})
Insert cell
pivot = FileAttachment("Pivot@3.txt").tsv({array:true})
Insert cell
linkStations = FileAttachment("LINK Stations.geojson").json()
Insert cell
wifiHotspot = FileAttachment("Wifi Hotspot.geojson").json()
Insert cell
parks1 = FileAttachment("Parks.geojson").json()
Insert cell
residential = FileAttachment("Residential.geojson").json()
Insert cell
streetCenterline = FileAttachment("Street Centerline.geojson").json()
Insert cell
borough = FileAttachment("Borough .geojson").json()
Insert cell
sea = FileAttachment("Sea.geojson").json()
Insert cell
looser = FileAttachment("looser.geojson").json()
Insert cell
Insert cell
spots = d3.csv(spotsLink,d3.autoType)
Insert cell
martini = FileAttachment("martini glass@2.txt").tsv({array:true})
Insert cell
wifistream = FileAttachment("wifistream@5.txt").tsv({array:true})
Insert cell
workbook = FileAttachment("Untitled spreadsheet.xlsx").xlsx()
Insert cell
workbook.sheetNames
Insert cell
l1 = FileAttachment("L@1.txt").tsv({array:true})
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more