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

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