{"version":3,"file":"map.js","sources":["../../src/map.js"],"sourcesContent":["/*\nRender a map based on a query or table view by fetching its GeoJSON representation\n*/\n\nasync function render() {\n\tconsole.debug(\"Rendering GeoJSON map\");\n\t// window.datasette.leaflet.JAVASCRIPT_URL\n\tconst L = await import(window.datasette.leaflet.JAVASCRIPT_URL);\n\n\t// simplestyle\n\tawait import(\"leaflet-simplestyle\");\n\n\tconst geojson = await fetch(geojsonURL(window.location)).then(r => r.json());\n\n\tconst parent = document.querySelector(\".table-wrapper\");\n\tconst container = document.createElement(\"DIV\");\n\n\tObject.assign(container, {\n\t\tid: \"map\",\n\t});\n\n\tparent.insertBefore(container, parent.firstElementChild);\n\n\tconst map = createMap(L, container);\n\tconst layer = L.geoJSON(geojson, { useSimpleStyle: true, useMakiMarkers: true })\n\t\t.addTo(map)\n\t\t.bindPopup(popup);\n\tconst bounds = layer.getBounds();\n\n\tmap.fitBounds(bounds);\n\n\t// make debugging easier\n\twindow.map = map;\n}\n\nfunction createMap(L, container) {\n\tconst map = L.map(container);\n\n\tL.tileLayer(window.TILE_LAYER, window.TILE_LAYER_OPTIONS).addTo(map);\n\n\treturn map;\n}\n\nfunction geojsonURL(location) {\n\tconst url = new URL(location);\n\turl.pathname = url.pathname + \".geojson\";\n\treturn url;\n}\n\nfunction popup(layer) {\n\tconst { properties } = layer.feature;\n\tconst items = Object.entries(properties).map(\n\t\t([key, value]) => `\n