// this file is only used for sidebar demo import React, { useState, ReactElement, CSSProperties } from 'react'; // needs to be check later // import { MapVEuMapProps } from "./TypesSidebar"; // change markerElement's prop import { BoundsViewport, AnimationFunction } from './Types'; import { BoundsDriftMarkerProps } from './BoundsDriftMarker'; import { MapContainer, TileLayer, LayersControl, ZoomControl, ScaleControl, } from 'react-leaflet'; import SemanticMarkers from './SemanticMarkers'; import 'leaflet/dist/leaflet.css'; import { LeafletMouseEvent } from 'leaflet'; import { Viewport } from './MapVEuMap'; // for layers const { BaseLayer } = LayersControl; // a generic function to remove a class: here it is used for removing highlight-marker function removeClassName(targetClass: string) { let targetElement = document.getElementsByClassName(targetClass)[0]; if (targetElement != null) { targetElement.classList.remove(targetClass); } } // a generic function to remove a class: here it is used for removing highlight-marker function removeClassNameActive(targetClass: string) { let targetElement = document.getElementsByClassName(targetClass)[0]; if (targetElement != null) { targetElement.classList.remove('active'); } } /** * Renders a Leaflet map with semantic zooming markers * * * @param props */ // NASTY cut and paste of props. BM is assuming MapVEuMapSidebar will go away, so this is just temporary. interface MapVEuMapPropsCutAndPasteCopy { /** Center lat/long and zoom level */ viewport: Viewport; /** Height and width of plot element */ height: CSSProperties['height']; width: CSSProperties['width']; onViewportChanged: (bvp: BoundsViewport) => void; markers: ReactElement[]; nudge?: 'geohash' | 'none'; // add this for closing sidebar at MapVEuMap: passing setSidebarCollapsed() sidebarOnClose?: (value: React.SetStateAction) => void; animation: { method: string; duration: number; animationFunction: AnimationFunction; } | null; showGrid: boolean; } // export default function MapVEuMapSidebar({ viewport, height, width, onViewportChanged, markers, nudge }: MapVEuMapProps) { export default function MapVEuMapSidebarSibling({ viewport, height, width, onViewportChanged, markers, animation, nudge, sidebarOnClose, }: MapVEuMapPropsCutAndPasteCopy) { // this is the React Map component's onViewPortChanged handler // we may not need to use it. // onViewportchanged in SemanticMarkers is more relevant // because it can access the map's bounding box (aka bounds) // which is useful for fetching data to show on the map. // The Viewport info (center and zoom) handled here would be useful for saving a // 'bookmarkable' state of the map. const [state, setState] = useState(viewport as Viewport); // trying to add map click events: e.g., removing marker highlight, closing sidebar, etc. const mapClick = (e: LeafletMouseEvent) => { // remove marker highlight removeClassName('highlight-marker'); // use this for closing sidebar: setSidebarCollapsed(true). Use if condition to avoid type error if (sidebarOnClose) sidebarOnClose(true); // deactivate selected sidebar tab removeClassNameActive('sidebartabs active'); }; const handleViewportChanged = (viewport: Viewport) => { setState(viewport); }; return ( <> ); }