<body>
<div id="map"></div>
<div id="delete">Wis alles</div>
<a href="#" id="export">Exporteer alles</a>
<script>
const blueIcon = L.icon({
iconUrl: 'assets/parking_bicycle-2.png',
iconSize: [32, 37], // size of the icon
iconAnchor: [16, 37], // point of the icon which will correspond to marker's location
popupAnchor: [0, -30], // point from which the popup should open relative to the iconAnchor
})
const map = L.map('map').setView([51.7918951, 4.6827132], 13)
attribution: `© ${mapLink} Contributors`,
maxZoom: 18,
}).addTo(map)
const drawnItems = new L.FeatureGroup()
map.addLayer(drawnItems)
const drawControl = new L.Control.Draw({
draw: {
polygon: false,
polyline: false,
rectangle: false,
circle: false,
circlemarker: false,
marker: {
icon: blueIcon,
repeatMode: true,
},
},
edit: {
featureGroup: drawnItems,
},
})
map.addControl(drawControl)
map.on('draw:created', (e) => {
const type = e.layerType,
layer = e.layer
drawnItems.addLayer(layer)
})
// on click, clear all layers
document.getElementById('delete').onclick = () => {
drawnItems.clearLayers()
}
const exportBtn = document.getElementById('export')
exportBtn.onclick = () => {
// Extract GeoJson from drawnItems
const data = drawnItems.toGeoJSON()
// Stringify the GeoJson
const convertedData =
'text/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(data))
// Create export
exportBtn.setAttribute('href', 'data:' + convertedData)
exportBtn.setAttribute('download', 'data.geojson')
}
</script>
</body>