Public
Edited
Sep 23, 2024
Insert cell
Insert cell
chart = {
const width = 1000,//pixel size of the map
height = 1000;
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width-1, height-1]);

// Use Mercator projection
var projection = d3
.geoMercator()//projection system used
.fitSize([width, height], box);//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")


/////////////////////////////////////////////////////////////////////////////////////////////////////////////// MAP LINES

//static lines from qgis
staticLines(path5, surfacestuff.features,"rgb(30, 30, 30)",'1','1',"Gray")
staticLines(path3, roads.features,"none",'1','.5',"Gray")
///staticLines(path4, buildings.features,"none",'1','.5',"Silver")


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)
}



/////////////////////////////////////////////////////////////////////////////////////////////////////////////// BORDER LINES

//polyline(chunkyborder,'black','1','2','black')
//polyline(chunkyextra,'none','1','1','White')
//polyline(chunckypanel,'rgb(40, 40, 40)','1','1','White')
polyline(xfillborder,'black','1','2','black')
polyline(xinnerborder,'none','1','2','White')
polyline(xpanels,'rgb(40, 40, 40)','1','1','White')
polyline(lakes,'rgb(25, 25, 25)','1','2','white')
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)

/////////////////////////////////////////////////////////////////////////////////////////////////////////////// ZONE BOX
g.enter().append("polyline")
.data(data) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr('class','zone')
.attr("points", rangebox) //The d attribute defines a path to be drawn, only applies to appended elements
.attr('transform',function(d) {return'translate('+480+','+420+')'})
//.attr('x', 800)
//.attr("y", 100)
.style("fill", 'white')
.style('fill-opacity','.01')
.style("stroke-width", '1')
.style('stroke-dasharray','5 5')
.style("stroke", "White")
.on("mouseover", addZoneIcon)
.on("mouseout", removeZoneIcon)

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////// LONGBOARD ICON
p.enter().append("polyline")
.data(Spots) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr('class','spotsName')
.attr("points", theicon) //The d attribute defines a path to be drawn, only applies to appended elements
.attr('transform',function(d) {return'translate('+projection([d.Longitude,d.Latitude])[0]+','+projection([d.Longitude,d.Latitude])[1]+')'})
.style("fill", 'Gray')
.style("stroke-width", '1')
.style("stroke", "white")
.on("mouseover", addText)
.on("mouseout", removeText)

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

/////////////////////////////////////////////////////////////////////////////////////////////////////////////// PLACE + TYPE : TEXT EVENT
function addText(event,d){

svg
.append("text") //appends path to data
.attr('class','spotsName')
.attr('x', 790)
.attr("y", 200)
.attr('fill', 'white')
.style('font-family', 'Helvetica')
.style("font-size","25px")
.text(d.Place)

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

//svg
//.append("text") //appends path to data
//.attr('class','spotsName')
//.attr('x', 790)
//.attr("y", 100)
//.attr('fill', 'white')
//.style('font-family', 'Helvetica')
//.style("font-size","20px")
//.text(d.Type)

//svg
//.append("text") //appends path to data
//.attr('class','spotsName')
//.attr('x', 790)
//.attr("y", 130)
//.attr('fill', 'white')
//.style('font-family', 'Helvetica')
//.style("font-size","20px")
//.text(d.Rating)

////////////////////////////////////////////////////////////////////
if (d.Type=="Hill"){
svg
p.enter().append("polyline")
.data(hillicon) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr('class','GroundType')
.attr("points", function(d) {return d})
.attr('transform',function(d) {return d})
.style("fill", 'white')
.style('fill-opacity','.01')
.style("stroke-width", '2')
.style("stroke", "White")
}


if (d.Type=="Flat"){
svg
p.enter().append("polyline")
.data(flaticon) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr('class','GroundType')
.attr("points", function(d) {return d})
.attr('transform',function(d) {return d})
.style("fill", 'white')
.style('fill-opacity','0')
.style("stroke-width", '2')
.style("stroke", "White")
}
/////////////////////////////////////////////////////////////////////////
if (d.Rating=="1"){
svg
p.enter().append("polyline")
.data(ratingbox1) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr('class','GroundType')
.attr("points", function(d) {return d})
.attr('transform',function(d) {return d})
.style("fill", 'FireBrick')
.style('fill-opacity','1')
.style("stroke-width", '2')
.style("stroke", "none")
}

if (d.Rating=="2"){
svg
p.enter().append("polyline")
.data(ratingbox2) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr('class','GroundType')
.attr("points", function(d) {return d})
.attr('transform',function(d) {return d})
.style("fill", 'DarkOrange')
.style('fill-opacity','1')
.style("stroke-width", '2')
.style("stroke", "none")
}

if (d.Rating=="3"){
svg
p.enter().append("polyline")
.data(ratingbox3) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr('class','GroundType')
.attr("points", function(d) {return d})
.attr('transform',function(d) {return d})
.style("fill", 'Gold')
.style('fill-opacity','1')
.style("stroke-width", '2')
.style("stroke", "none")
}

if (d.Rating=="4"){
svg
p.enter().append("polyline")
.data(ratingbox4) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr('class','GroundType')
.attr("points", function(d) {return d})
.attr('transform',function(d) {return d})
.style("fill", 'LightGreen')
.style('fill-opacity','1')
.style("stroke-width", '2')
.style("stroke", "none")
}

if (d.Rating=="5"){
svg
p.enter().append("polyline")
.data(ratingbox5) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr('class','GroundType')
.attr("points", function(d) {return d})
.attr('transform',function(d) {return d})
.style("fill", 'ForestGreen')
.style('fill-opacity','1')
.style("stroke-width", '2')
.style("stroke", "none")
}

}

function removeText(){
svg.selectAll('text.spotsName').remove()
svg.selectAll('polyline.GroundType').remove()
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////// HOUSE ICON : ZONE EVENT
function addZoneIcon(event,d){

svg
p.enter().append("polyline")
.data(houseicon) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr('class','zone2')
.attr("points", function(d) {return d})
.attr('transform',function(d) {return'translate('+890+','+900+')'})
.style("fill", 'white')
.style('fill-opacity','.01')
.style("stroke-width", '2')
.style("stroke", "White")

}

function removeZoneIcon(){
svg.selectAll('polyline.zone2').remove()
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// STATIONARY TEXT
svg
//t.enter().append("text")
.append("text") //appends path to data
.attr('x', 790)
.attr("y", 50)
.attr('fill', 'white')
.style('font-family', 'Helvetica')
.style("font-size","20px")
.text("LONGBOARDING IN")

svg
//t.enter().append("text")
.append("text") //appends path to data
.attr('x', 840)
.attr("y", 80)
.attr('fill', 'white')
.style('font-family', 'Helvetica')
.style("font-size","20px")
.text("SENECA")
svg
//t.enter().append("text")
.append("text") //appends path to data
.attr('x', 790)
.attr("y", 150)
.attr('fill', 'white')
.style('font-family', 'Helvetica')
.style("font-size","20px")
.text("PLACE:")

svg
//t.enter().append("text")
.append("text") //appends path to data
.attr('x', 790)
.attr("y", 590)
.attr('fill', 'white')
.style('font-family', 'Helvetica')
.style("font-size","20px")
.text("RATING:")

svg
//t.enter().append("text")
.append("text") //appends path to data
.attr('x', 790)
.attr("y", 810)
.attr('fill', 'white')
.style('font-family', 'Helvetica')
.style("font-size","20px")
.text("TYPE:")
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// EXTRA
// function addDetail(event,d){

// svg
// .append("text") //appends path to data
// .attr('class','spotsName')
// .attr('x', projection([d.Longitude,d.Latitude])[0]-10)
// .attr("y", projection([d.Longitude,d.Latitude])[1]+10)
// .attr('fill', 'DarkSlateGray')
// .style('font-family', 'Helvetica')
// .style("font-size","25px")
// .text(d.Type)
// }

// function removeDetail(){
// svg.selectAll('text.spotsName').remove()
// }

//static points from qgis
//staticCircles(restrooms.features,'2','black','1',"0")
//staticCircles(skatespots.features,'8','DarkOliveGreen','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)
}
*/


return svg.node();
}
Insert cell
ratingbox2 = FileAttachment("RatingBox2.txt").tsv({array:true})
Insert cell
xnewpanels = FileAttachment("Xnewpanels.txt").tsv({array:true})
Insert cell
ratingbox3 = FileAttachment("RatingBox3.txt").tsv({array:true})
Insert cell
ratingbox4 = FileAttachment("RatingBox4.txt").tsv({array:true})
Insert cell
ratingbox5 = FileAttachment("RatingBox5.txt").tsv({array:true})
Insert cell
xpanels = FileAttachment("Xpanels.txt").tsv({array:true})
Insert cell
chunkyextra = FileAttachment("Chunkyextra.txt").tsv({array:true})
Insert cell
longboardicon = FileAttachment("longboardICON.txt").tsv({array:true})
Insert cell
newborder = FileAttachment("newborder.txt").tsv({array:true})
Insert cell
TheSpot = "https://docs.google.com/spreadsheets/d/e/2PACX-1vSaTnJsleLmls1tSt9vyrqWpO8honE3K7dhfhonFInu8abIveqGpny4YVD0sWlPVPAvJbfb2zFk-tuY/pub?output=csv"
Insert cell
Spots = d3.csv(TheSpot,d3.autoType)
Insert cell
surfacestuff = FileAttachment("SurfaceStuff.geojson").json()
Insert cell
box = FileAttachment("BOX.geojson").json()
Insert cell
import { wrap_text, wrap_text_nchar } from "@ben-tanen/svg-text-and-tspan-word-wrapping"
Insert cell
buildings = FileAttachment("Buildings.geojson").json()
Insert cell
roads = FileAttachment("Roads.geojson").json()
Insert cell
skatespots = FileAttachment("SkateSpots.geojson").json()
Insert cell
surficial = FileAttachment("Surficial.geojson").json()
Insert cell
theicon = FileAttachment("TheICON.txt").tsv({array:true})
Insert cell
chunckypanel = FileAttachment("chunckypanel.txt").tsv({array:true})
Insert cell
chunkyborder = FileAttachment("chunkyborder.txt").tsv({array:true})
Insert cell
houseicon = FileAttachment("Houseicon.txt").tsv({array:true})
Insert cell
hillicon = FileAttachment("HillIcon.txt").tsv({array:true})
Insert cell
lakes = FileAttachment("LAKES.txt").tsv({array:true})
Insert cell
ratingbox1 = FileAttachment("RatingBox1.txt").tsv({array:true})
Insert cell
xfillborder = FileAttachment("Xfillborder.txt").tsv({array:true})
Insert cell
xinnerborder = FileAttachment("Xinnerborder.txt").tsv({array:true})
Insert cell
flaticon = FileAttachment("flatIcon.txt").tsv({array:true})
Insert cell
rangebox = FileAttachment("Rangebox.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