Published
Edited
Apr 2, 2020
1 star
Insert cell
Insert cell
map1 = {
/*
Specifique à observable
Dans le contexte d'une page web, il nous faut une <div>
avec des propriétés height et width définies
*/
const WIDTH = width
const HEIGHT = width * 0.6
let container = DOM.element('div', { style: `width:${WIDTH}px;height:${HEIGHT}px` })
yield container

// Monter la carte sur la <div>
// Dans une page web, passez l'id de la <div> à L.map
const map = L.map(container)
// définir la position de la carte "[latitude, longitude], zoom"
// ATTENTION les valeurs latitude et longitude sont inversée par rapport à un point GeoJSON
.setView([46.7785, 6.6412], 14)
// Fond de carte
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map)
// Ajouter des données au format GeoJSON
L.geoJSON(
// un objet GeoJSON
{
type: 'Feature',
properties: { name: 'Yverdon' },
geometry: { type: 'Point', coordinates: [6.6412, 46.7785] }
},
// options
// ici nous ajoutons un "popup" à chaque "feature" affichant la propriété "name"
{
onEachFeature: (feature, layer) => layer.bindPopup(feature.properties.name),
}
).addTo(map)
}
Insert cell
Insert cell
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