|
| 1 | +import { MapboxOverlay } from "@deck.gl/mapbox"; |
| 2 | +import { GeoJsonLayer } from "@deck.gl/layers"; |
| 3 | +import maplibregl from "maplibre-gl"; |
| 4 | +import { asyncBufferFromUrl } from "hyparquet"; |
| 5 | +import { toGeoJson } from "geoparquet"; |
| 6 | + |
| 7 | +async function initializeMap() { |
| 8 | + try { |
| 9 | + // Load and convert GeoParquet file |
| 10 | + const url = "https://raw.githubusercontent.com/astrojuanlu/desalkila/refs/heads/app/app/public/registry_cam_no_vuts_simple.geoparquet"; |
| 11 | + const data = await asyncBufferFromUrl({ url }); |
| 12 | + console.log(data); |
| 13 | + const geojson = await toGeoJson({ data }); |
| 14 | + console.log(geojson); |
| 15 | + |
| 16 | + const map = new maplibregl.Map({ |
| 17 | + container: "map", |
| 18 | + style: { |
| 19 | + version: 8, |
| 20 | + sources: { |
| 21 | + osm: { |
| 22 | + type: "raster", |
| 23 | + tiles: ["https://tile.openstreetmap.org/{z}/{x}/{y}.png"], |
| 24 | + tileSize: 256, |
| 25 | + attribution: "© OpenStreetMap Contributors", |
| 26 | + maxzoom: 19, |
| 27 | + }, |
| 28 | + }, |
| 29 | + layers: [ |
| 30 | + { |
| 31 | + id: "osm", |
| 32 | + type: "raster", |
| 33 | + source: "osm", |
| 34 | + minzoom: 0, |
| 35 | + maxzoom: 19, |
| 36 | + }, |
| 37 | + ], |
| 38 | + }, |
| 39 | + center: [-3.7038, 40.4168], // Madrid |
| 40 | + zoom: 11, |
| 41 | + }); |
| 42 | + |
| 43 | + map.on("load", () => { |
| 44 | + // Initialize your deck instance |
| 45 | + const deckOverlay = new MapboxOverlay({ |
| 46 | + layers: [ |
| 47 | + new GeoJsonLayer({ |
| 48 | + id: "geojson-layer", |
| 49 | + data: geojson, |
| 50 | + filled: true, |
| 51 | + pointRadiusMinPixels: 8, |
| 52 | + pointRadiusScale: 2000, |
| 53 | + getPointRadius: 1, |
| 54 | + getFillColor: [255, 0, 0, 200], // Red dots |
| 55 | + pickable: true, |
| 56 | + onHover: ({ object }) => { |
| 57 | + if (object) { |
| 58 | + console.log(object.properties.name); |
| 59 | + } |
| 60 | + }, |
| 61 | + }), |
| 62 | + ], |
| 63 | + }); |
| 64 | + |
| 65 | + map.addControl(deckOverlay); |
| 66 | + map.addControl(new maplibregl.NavigationControl()); |
| 67 | + }); |
| 68 | + } catch (error) { |
| 69 | + console.error("Error initializing map:", error); |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +initializeMap(); |
0 commit comments