|
| 1 | +import "maplibre-gl/dist/maplibre-gl.css"; |
| 2 | + |
| 3 | +import { NakshaMaplibreLayers } from "@biodiv-platform/naksha-maplibre-layers"; |
| 4 | + |
| 5 | +import axios from "axios"; |
| 6 | +import React from "react"; |
| 7 | +import { tw } from "twind"; |
| 8 | + |
| 9 | +const Popup = (props) => { |
| 10 | + return ( |
| 11 | + <div className={tw`max-w-[250px] overflow-auto`}> |
| 12 | + <button onClick={() => alert("Clicked")}>Clicked</button> |
| 13 | + <pre>{JSON.stringify(props, null, 2)}</pre> |
| 14 | + </div> |
| 15 | + ); |
| 16 | +}; |
| 17 | + |
| 18 | +const HoverPopup = ({ feature }) => ( |
| 19 | + <div key={feature?.properties?.count}> |
| 20 | + {feature?.properties?.count} Observations |
| 21 | + </div> |
| 22 | +); |
| 23 | + |
| 24 | +const fetchGridData = async (geoProps) => { |
| 25 | + const params = { |
| 26 | + ...geoProps, |
| 27 | + view: "map", |
| 28 | + geoField: "location", |
| 29 | + // taxon: 5275, |
| 30 | + }; |
| 31 | + |
| 32 | + const response = await axios.post( |
| 33 | + `http://localhost:8010/proxy/observation-api/api/v1/observation/list/extended_observation/_doc`, |
| 34 | + {}, |
| 35 | + { params } |
| 36 | + ); |
| 37 | + return response.data.geohashAggregation; |
| 38 | +}; |
| 39 | + |
| 40 | +const handleOnGeoserverLayerClick = (feat) => { |
| 41 | + console.debug("gs_clicked!", feat); |
| 42 | +}; |
| 43 | + |
| 44 | +export default function NakshaMaplibreListPage() { |
| 45 | + return ( |
| 46 | + <div className={tw`h-[100vh] w-[100vw]`}> |
| 47 | + <NakshaMaplibreLayers |
| 48 | + loadToC={true} |
| 49 | + showToC={true} |
| 50 | + managePublishing={true} |
| 51 | + nakshaApiEndpoint="http://localhost:8010/proxy/naksha-api/api" |
| 52 | + nakshaEndpointToken={process.env.NEXT_PUBLIC_NAKSHA_TOKEN} |
| 53 | + geoserver={{ |
| 54 | + endpoint: "http://localhost:8010/proxy/geoserver", |
| 55 | + store: "naksha", |
| 56 | + workspace: "biodiv", |
| 57 | + }} |
| 58 | + onLayerDownload={console.log} |
| 59 | + canLayerShare={true} |
| 60 | + // selectedLayers={[ |
| 61 | + // "global-observations", |
| 62 | + // "lyr_3_agar_soil", |
| 63 | + // "lyr_1_agar_geology", |
| 64 | + // ]} |
| 65 | + markers={[ |
| 66 | + { |
| 67 | + latitude: 23.241346, |
| 68 | + longitude: 78.046875, |
| 69 | + colorHex: "07BEF1", |
| 70 | + }, |
| 71 | + ]} |
| 72 | + layers={[ |
| 73 | + { |
| 74 | + id: "global-observations", |
| 75 | + title: "Global Observations", |
| 76 | + source: { type: "grid", fetcher: fetchGridData }, |
| 77 | + onClick: Popup, |
| 78 | + onHover: HoverPopup, |
| 79 | + data: { |
| 80 | + index: "extended_observation", |
| 81 | + type: "extended_records", |
| 82 | + geoField: "location", |
| 83 | + summaryColumn: ["count"], |
| 84 | + propertyMap: { count: "Count" }, |
| 85 | + }, |
| 86 | + }, |
| 87 | + ]} |
| 88 | + /> |
| 89 | + </div> |
| 90 | + ); |
| 91 | +} |
0 commit comments