Public
Edited
Dec 15, 2022
Insert cell
# Berlin GreenBahn TEST
Insert cell
bbox2 = FileAttachment("Berlin BB 10-13-22.geojson")
Insert cell
d3 = require("d3@6")
Insert cell
chart = {
const width =1000,
height = 1100;
const svg = d3.create("svg")
.attr("viewBox", [100, 100, width-400, height-450]);

// Use Mercator projection
var projection = d3
.geoMercator()
.fitSize([width - 100, height - 200], 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 g = svg.append("g").attr("id", "paths");

var clickYear = 2000
//i'm not using the boundary lines, so I'm going to comment them out
/*
g.selectAll("path1") //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("fill", "none")
.style('stroke-opacity','1')
.style("stroke-width", '.5')
.style("stroke", "rgb(0,0,0)")
*/

//cleanup old systems
// display roads
//show current transit sytems
//display connected parks
//display proposed sytem
//Movable object across an array of points along a single curve
//select parks for information
//hover over tram to get information on it


//mouse over current metro stops
g.selectAll("path2") //d3 geopath
.data(berlinTransportStops1.features) //get data to define path
.enter() //there are more data than elements, this selects them
.append("path") //appends path to data
.attr('class','stops')
.style("fill", "black")
.style("fill-opacity", "0")
.style('stroke-opacity','0')
.style("stroke-width", '0')
.style("stroke", "none")

g.selectAll("path2") //d3 geopath
.data(waterways.features) //get data to define path
.enter() //there are more data than elements, this selects them
.append("path") //appends path to data
.attr('class','water')
.attr("d", path2) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "azure")
.style("fill-opacity", "1")
.style('stroke-opacity','1')
.style("stroke-width", '.5')
.style("stroke", "white")



var c = svg.selectAll("circle")
.data(berlinTransportStops1.features)
.enter()
.append("circle")
.attr("cx", function(d) {return path1.centroid(d)[0]})
.attr("cy", function(d) {return path1.centroid(d)[1]})
.attr('r','1.5')
.attr('fill','red')
.style('fill-opacity','1')
.style("stroke-width", '0.8')
.style("stroke", "black")
.on('mouseover',metrostops)
.on('mouseout',removespotText)

var c = svg.selectAll("circle")
.data(Berlinparklink)
.enter()
.append("circle")
.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','blue')
.style('fill-opacity','1')
.style("stroke-width", '0.8')
.style("stroke", "black")
.on('mouseover',parkmouse)
.on('mouseout',removespotText)




function layersClick(event,d){
console.log(d)
if(d=='Current'){
clickYear = Current
d3.selectAll('path.outlines').remove()
d3.selectAll('text.layersText').remove()
g.selectAll("path2") //d3 geopath
.data(Current.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", '.5')
.style("stroke", "black")
svg.append('text')
.attr('class','layersText')
.attr('x', '410')
.attr('y','400')
.attr('font-family','Helvetica')
.attr('font-size', '.65em')
.attr('text.anchor','start')
.attr('font-weight', 'Bold')
.text('The system continues to grow and the restorations also continue')

svg.append('text')
.attr('class','layersText')
.attr('x', '110')
.attr('y','85')
.attr('font-family','Helvetica')
.attr('font-size', '.55em')
.attr('text.anchor','start')
.attr('font-weight', 'normal')
.text('')

svg.append('text')
.attr('class','layersText')
.attr('x', '110')
.attr('y','95')
.attr('font-family','Helvetica')
.attr('font-size', '.55em')
.attr('text.anchor','start')
.attr('font-weight', 'normal')
.text('')
}
}
//make parks change opacity & give a info blurb

//hey, you're naming this function the same thing as your dataset - 'Parkpoints' - name it something else!!!!
function parkmouse(event,d) {
d3.select(this).attr('fill','yellow')
d3 .select(this) .attr('r',4)

svg.append('text')//use this for second and all subsequent text add
.attr("x", '650')
.attr("y", '720')
.attr('class','parks')
.attr('font-family','helvetica')
.attr('font-size','.55em')
.attr('font-weight','bold')
.style("fill", "rgb(0,0,0)")
.attr('text-anchor','start')
.text(d.Name)

svg.append('text')//use this for second and all subsequent text add
.attr("x", '650')
.attr("y", '730')
.attr('class','parks')
.attr('font-family','helvetica')
.attr('font-size','.55em')
.attr('font-weight','400')
.style("fill", "rgb(50,50,50)")
.attr('text-anchor','start')
.text(d.description)

svg.append('line')
.attr('class','spotline')
.attr('x1','650')
.attr('y1','720')
.attr('x2',path1.centroid(d)[0])
.attr('y2','720')
.style('stroke-width','1')
.style('stroke','black')
.style('stroke-dasharray','4 2')
svg.append('line')
.attr('class','spotline')
.attr('x1',path1.centroid(d)[0])
.attr('y1','720')
.attr('x2',path1.centroid(d)[0])
.attr('y2',path1.centroid(d)[1])
.style('stroke-width','1')
.style('stroke','black')
.style('stroke-dasharray','4 2')


}
//makes a metro sign pop up or tells what stop it is
function metrostops(event,d) {
d3.select(this).attr('fill','yellow')
d3 .select(this) .attr('r',2.5)

svg.append('text')//use this for second and all subsequent text add
.attr("x", '650')
.attr("y", '720')
.attr('class','metrostops')
.attr('font-family','helvetica')
.attr('font-size','.55em')
.attr('font-weight','bold')
.style("fill", "rgb(0,0,0)")
.attr('text-anchor','start')
.text('Metrostop')

svg.append('text')//use this for second and all subsequent text add
.attr("x", '650')
.attr("y", '730')
.attr('class','metrostops')
.attr('font-family','helvetica')
.attr('font-size','.55em')
.attr('font-weight','400')
.style("fill", "rgb(50,50,50)")
.attr('text-anchor','start')
.text('U & S Bahn')

svg.append('line')
.attr('class','spotline')
.attr('x1','650')
.attr('y1','720')
.attr('x2',path1.centroid(d)[0])
.attr('y2','720')
.style('stroke-width','1')
.style('stroke','black')
.style('stroke-dasharray','4 2')
svg.append('line')
.attr('class','spotline')
.attr('x1',path1.centroid(d)[0])
.attr('y1','720')
.attr('x2',path1.centroid(d)[0])
.attr('y2',path1.centroid(d)[1])
.style('stroke-width','1')
.style('stroke','black')
.style('stroke-dasharray','4 2')


}
function removeparktext(event,d)
{
d3.selectAll('text.parkmouse').remove()
d3.selectAll('line.parkmouse').remove()

}
function removespotText(event,d)
{d3.selectAll('text.metrostops').remove()
d3.selectAll('text.parks').remove()
d3.selectAll('line.spotline').remove()
d3.select(this).attr('fill','red')
d3 .select(this).attr('r',1.5)

}



return svg.node();
}
Insert cell
legend = FileAttachment("legend.geojson").json()
Insert cell
Parkpoints = FileAttachment("parkpoints.geojson").json()
Insert cell
Tramstop = FileAttachment("newstops@1.geojson").json()
Insert cell
Tramline = FileAttachment("spitinmyface@1.geojson").json()
Insert cell
layers = ['1902', '1910', '1920','1930','1940','1970','1995','Current']
Insert cell
berlinTransportStops1 = FileAttachment("Berlin Transport Stops@1.geojson").json()
Insert cell
bldgs = FileAttachment("Berlin Parks@2.geojson").json()
Insert cell
bldgs2 = FileAttachment("LU-Residential 4 @1.geojson").json()
Insert cell
Current = FileAttachment("Railways.geojson").json()
Insert cell
waterways = FileAttachment("Berlin Waterways@1.geojson").json()
Insert cell
bbox = FileAttachment("Berlin BB 10-13-22.geojson").json()
Insert cell
Insert cell
d3.csv(Berlinparklink,d3.autoType)
Insert cell
greenways = FileAttachment("greenways.geojson").json()
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