Published
Edited
Aug 11, 2018
1 fork
1 star
Insert cell
Insert cell
Insert cell
centerpoint = {
// Create the \`map\` object with the mapboxgl.Map constructor, referencing
// the container div
let map = new mapboxgl.Map({
container: mapContainer,
center: [
-121,
38
],
zoom: 6,
style: 'mapbox://styles/mapbox/light-v9'
});
map.on('click', 'fire', function (e) {
console.log(e.features[0].properties);
new mapboxgl.Popup()
.setLngLat(e.lngLat)
.setHTML(e.features[0].properties.name)
.addTo(map);
});
map.addControl(new mapboxgl.NavigationControl());
map.addControl(new mapboxgl.FullscreenControl());
map.on('load', function () {
console.log(kml)

map.addLayer({
'id': 'fire',
'type': 'fill',
'source': {
'type': 'geojson',
'data': geojson
},
'layout': {},
'paint': {
'fill-color': '#f00',
'fill-opacity': 0.5
}
});
map.addLayer( {
"id": "label",
"type": "symbol",
"source": {
'type': 'geojson',
'data': geojson
},
"minzoom": 5,
"maxzoom": 24,
"layout": {
"text-optional": false,
"text-size": {
"base": 1.4,
"stops": [
[
7,
14
],
[
15,
18
]
]
},
"symbol-spacing": 500,
"text-field": "{name}"
},
"paint": {
"text-color": "#000",
"text-halo-color": "hsl(0, 0%, 100%)",
"text-halo-width": 2
}
});
});
return Generators.observe(change => {
map.on('mousemove', e => {
change(e.lngLat);
});
});
}
Insert cell
Insert cell
Insert cell
d3 = require("d3")
Insert cell
Insert cell
md`
### Mapbox CSS
<link href='https://unpkg.com/mapbox-gl@0.47.0/dist/mapbox-gl.css' rel='stylesheet' />
`
Insert cell
Insert cell
mapboxgl = {
let mapboxgl = await require('mapbox-gl@0.47.0');

mapboxgl.accessToken = 'pk.eyJ1Ijoicm9ibGFicyIsImEiOiJwVlg0cnZnIn0.yhekddtKwZohGoORaWjqIw';
return mapboxgl;
}
Insert cell
Insert cell
kml = d3.xml("https://gec.cr.usgs.gov/outgoing/GeoMAC/ActiveFirePerimeters.kml", function(error, response) {
console.log(error, response)
})
Insert cell
togeojson = require('@mapbox/togeojson@0.16.0/togeojson.js').catch(() => window.toGeoJSON)
Insert cell
Insert cell
geojson = togeojson.kml(kml)
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