Public
Edited
Nov 30, 2023
Insert cell
# UD Fall 2023 - New Orleans (Large Scale)
Insert cell
d3 = require("d3@6")
Insert cell
chart = {
const width = 1300,
height = 900
;
const svg = d3.create("svg")
.attr("viewBox", [400, 250, width-500, height-400]) //use in tandom to create a better square
;
var projection = d3
.geoMercator()
.fitSize([width - 50, height - 50], bbox);

var path1 = d3.geoPath().projection(projection);//any path that comes from qgis
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");

svg.append('image')
.attr('href',view)
.attr('class','spotImage')
.attr('x', '340')
.attr('y','75')
.attr('width', 905)
.attr('height', 845)

var c = svg.selectAll("circle")
.data(cities1.features)
.enter()
.append("circle")
.attr("cx", function(d) {return path1.centroid(d)[0]})
.attr("cy", function(d) {return path1.centroid(d)[1]})
.attr('r',3)
.style('fill','red')
.style('fill-opacity','1')
.on('mouseover',fireText)
.on('mouseout',removefireText)

function fireText(event,d){
console.log(d)

svg
.append("text")
.attr('x','400')
.attr('y','375')
.attr('class','mypoints_position')
.style('font-family','helvetica')
.style('font-size','20px')
.style('font-weight','light')
.text(d.properties.description)

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

svg
.append("line")
.attr('x1','400')
.attr('y1','370')
.attr('x2', path1.centroid(d)[0])
.attr('y2', path1.centroid(d)[1])
.attr('class','fireLine')
.style("stroke-width", '3')
.style("stroke", "rgb(0,0,0)")
.style('stroke-dasharray', '6 4')
}

function removefireText(){
d3.selectAll('text.mypoints_position').remove()
d3.selectAll('line.fireLine').remove()
}

c.enter().append("circle")
.data(cities1)
.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',100)
.style('stroke','red')
.style('stroke-width','1')
.style('fill','cyan')
.style('fill-opacity','1')


svg
.append("text")
.attr('x','400')
.attr('y','275')
.style('font-family','garamond')
.style('font-size','18px')
.style('font-weight','bold')
.text('Coastal Louisiana Oyster Reef Map')


svg
.append("line")
.attr('x1','300')
.attr('y1','277')
.attr('x2','675')
.attr('y2','277')
.style("stroke-width", '1')
.style("stroke", "rgb(0,0,0)")
return svg.node();
}
Insert cell
viewcapture20231129_212353 = FileAttachment("ViewCapture20231129_212353.png").image()
Insert cell
view2 = FileAttachment("ViewCapture20231129_205502.png").image()

Insert cell
cities1 = FileAttachment("cities@1.geojson").json()
Insert cell
bbox = FileAttachment("Bbox.geojson").json()
Insert cell
Insert cell
personal_spots = d3.csv(personal_spots_link,d3.autoType)
Insert cell
import { wrap_text, wrap_text_nchar } from "@ben-tanen/svg-text-and-tspan-word-wrapping"
Insert cell
view = FileAttachment("ViewCapture20231129_212353.png").url()
Insert cell
cities = FileAttachment("cities.geojson").json()
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