|
| 1 | +import React, { useState, useEffect } from "react"; |
| 2 | +import { createRoot } from "react-dom/client"; |
| 3 | +import { StaticMap, MapContext, NavigationControl } from "react-map-gl"; |
| 4 | +import DeckGL, { Layer } from "deck.gl/typed"; |
| 5 | +import { GeoArrowScatterplotLayer } from "@geoarrow/deck.gl-layers"; |
| 6 | +import * as arrow from "apache-arrow"; |
| 7 | + |
| 8 | +const GEOARROW_MULTIPOINT_DATA = |
| 9 | + "http://localhost:8080/naturalearth_cities_multipoint.feather"; |
| 10 | + |
| 11 | +const INITIAL_VIEW_STATE = { |
| 12 | + latitude: 20, |
| 13 | + longitude: 0, |
| 14 | + zoom: 2, |
| 15 | + bearing: 0, |
| 16 | + pitch: 0, |
| 17 | +}; |
| 18 | + |
| 19 | +const MAP_STYLE = |
| 20 | + "https://basemaps.cartocdn.com/gl/positron-nolabels-gl-style/style.json"; |
| 21 | +const NAV_CONTROL_STYLE = { |
| 22 | + position: "absolute", |
| 23 | + top: 10, |
| 24 | + left: 10, |
| 25 | +}; |
| 26 | + |
| 27 | +console.log("multipoint") |
| 28 | +console.log(arrow); |
| 29 | + |
| 30 | +function Root() { |
| 31 | + const onClick = (info) => { |
| 32 | + if (info.object) { |
| 33 | + // eslint-disable-next-line |
| 34 | + alert( |
| 35 | + `${info.object.properties.name} (${info.object.properties.abbrev})` |
| 36 | + ); |
| 37 | + } |
| 38 | + }; |
| 39 | + |
| 40 | + const [table, setTable] = useState<arrow.Table | null>(null); |
| 41 | + |
| 42 | + useEffect(() => { |
| 43 | + // declare the data fetching function |
| 44 | + const fetchData = async () => { |
| 45 | + const data = await fetch(GEOARROW_MULTIPOINT_DATA); |
| 46 | + const buffer = await data.arrayBuffer(); |
| 47 | + const table = arrow.tableFromIPC(buffer); |
| 48 | + console.log(table); |
| 49 | + setTable(table); |
| 50 | + }; |
| 51 | + |
| 52 | + if (!table) { |
| 53 | + fetchData().catch(console.error); |
| 54 | + } |
| 55 | + }); |
| 56 | + |
| 57 | + const layers: Layer[] = []; |
| 58 | + |
| 59 | + table && |
| 60 | + layers.push( |
| 61 | + new GeoArrowScatterplotLayer({ |
| 62 | + id: "geoarrow-points", |
| 63 | + data: table, |
| 64 | + getPosition: table.getChild("geometry")!, |
| 65 | + getFillColor: [255, 0, 0], |
| 66 | + // getFillColor: table.getChild("colors")!, |
| 67 | + // getLineColor: table.getChild("colors")!, |
| 68 | + radiusMinPixels: 4, |
| 69 | + getPointRadius: 10, |
| 70 | + pointRadiusMinPixels: 0.8, |
| 71 | + }) |
| 72 | + ); |
| 73 | + |
| 74 | + return ( |
| 75 | + <DeckGL |
| 76 | + initialViewState={INITIAL_VIEW_STATE} |
| 77 | + controller={true} |
| 78 | + layers={layers} |
| 79 | + // @ts-expect-error |
| 80 | + ContextProvider={MapContext.Provider} |
| 81 | + > |
| 82 | + <StaticMap mapStyle={MAP_STYLE} /> |
| 83 | + <NavigationControl style={NAV_CONTROL_STYLE} /> |
| 84 | + </DeckGL> |
| 85 | + ); |
| 86 | +} |
| 87 | + |
| 88 | +/* global document */ |
| 89 | +const container = document.body.appendChild(document.createElement("div")); |
| 90 | +createRoot(container).render(<Root />); |
0 commit comments