Published
Edited
Sep 15, 2021
1 fork
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { color } from "@jashkenas/inputs"
Insert cell
c = color()
Insert cell
c.value
Insert cell
c
Insert cell
L = require('leaflet@1.2.0')
Insert cell
html`<link href='${resolve(
'leaflet@1.2.0/dist/leaflet.css'
)}' rel='stylesheet' />`
Insert cell
Insert cell
w = width
Insert cell
h = width/1.5
Insert cell
container = {
// this is a javascript thing
const div = DOM.element("div", { style: `height:800px;` });
//yield div;
//this is a Leaflet thing
const map = L.map(div).setView([40.7299, -85], 5);

L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
attribution:
'&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

const mystyle = {
color: "red",
weight: 2,
opacity: 0.5,
flavor: "red"
};
//adding static data to the map
const json = L.geoJSON(geojson.features, { style: mystyle });
json.addTo(map);
return div;
}
Insert cell
Insert cell
Insert cell
Insert cell
d3 = require('d3', 'd3-geo')
Insert cell
topojson = require('topojson')
Insert cell
Insert cell
json = d3.json("https://unpkg.com/world-atlas@1/world/110m.json")
Insert cell
Insert cell
Insert cell
projection = d3
.geoOrthographic()
.center([-73.9888682, 40.6916651])
.translate([width / 2, h / 2])
//.scale(width / (2 * Math.PI))
.fitSize([width, h], geojson)
Insert cell
graticule = d3.geoGraticule10()
Insert cell
path = d3.geoPath().projection(projection)
Insert cell
html`<svg id ="d3map" style="height: ${h}px; width:${width}px">
<path d="${path(graticule)}" stroke=${c.value} fill="none"></path>
</svg>`
Insert cell
path(graticule)
Insert cell
svg = d3
.select("#d3map")
.style("background-color", "cyan")
.attr("height", h)
.attr("width", width)
Insert cell
svg
.selectAll("path")
.data(geojson.features)
.enter()
.append("path")
.attr("stroke", "gray")
.attr("stroke-width", "1")
.attr("fill", "chartreuse")
.attr("d", path)
.attr("id", function (n) {
return n.id;
})
.exit()
Insert cell
path(geojson.features[1])
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