Published
Edited
Jul 20, 2019
4 forks
10 stars
Insert cell
Insert cell
Insert cell
data = d3.json("https://raw.githubusercontent.com/niiyz/JapanCityGeoJson/master/geojson/13/13101.json")
Insert cell
Insert cell
hexagons = geojson2h3.featureToH3Set(data.features[0], 10)
Insert cell
Insert cell
hexPolygon = geojson2h3.h3SetToMultiPolygonFeature(hexagons)
Insert cell
Insert cell
compact = h3.compact(hexagons)
Insert cell
compactPolygon = geojson2h3.h3SetToMultiPolygonFeature(compact)
Insert cell
Insert cell
height = 400
Insert cell
viewof map = {
const container = html`<div style="height:${height}px;">`;
yield container; // Give the container dimensions.
const map = container.value = new mapboxgl.Map({
container,
center: [139.75, 35.69],
zoom: 12,
style: "mapbox://styles/mapbox/light-v9",
scrollZoom: true
});

map.on("load", () => {
map.addSource("geojson", {
type: "geojson",
data: compactPolygon,
});

map.addLayer({
"id": "geojsonLayer",
"type": "line",
"source": "geojson",
"layout": {},
"paint": {
"line-width": 2,
"line-color": "#0000ff",
"line-opacity": 0.8
}
});

});
invalidation.then(() => map.remove());
}
Insert cell
viewof map2 = {
const container = html`<div style="height:${height}px;">`;
yield container; // Give the container dimensions.
const map = container.value = new mapboxgl.Map({
container,
center: [139.75, 35.69],
zoom: 12,
style: "mapbox://styles/mapbox/light-v9",
scrollZoom: true
});

map.on("load", () => {
map.addSource("geojson", {
type: "geojson",
data: hexPolygon
});

map.addLayer({
"id": "geojsonLayer",
"type": "fill",
"source": "geojson",
"layout": {},
"paint": {
"fill-color": "#0000ff",
"fill-opacity": 0.5,
}
});

});
invalidation.then(() => map.remove());
}
Insert cell
mapboxgl = {
const gl = await require("mapbox-gl@0.54");
if (!gl.accessToken) {
// token allowed only for @sw1227
gl.accessToken = "pk.eyJ1Ijoic3cxMjI3IiwiYSI6ImNqeTFiYXF5cTA2ajYzaHE4cmEycnRteTkifQ.FR2JtUicCVzbH7xszfObEA";
const href = await require.resolve("mapbox-gl@0.49/dist/mapbox-gl.css");
document.head.appendChild(html`<link href=${href} rel=stylesheet>`);
}
return gl;
}
Insert cell
Insert cell
Insert cell
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