diff --git a/src/components/UI/Map/OpenLayerMap.css b/src/components/UI/Map/OpenLayerMap.css new file mode 100644 index 0000000..ea0bacd --- /dev/null +++ b/src/components/UI/Map/OpenLayerMap.css @@ -0,0 +1,27 @@ +html, body { + margin: 0; + padding: 0; + width: 100%; + height: 100%; + overflow: hidden; +} + +#root { + width: 100%; + height: 100%; +} + +/* For your map container specifically */ +.map-container { + width: 100%; + height: 100%; + position: absolute; + top: 0; + left: 0; +} + +/* Ensure OL map gets proper dimensions */ +.ol-viewport { + width: 100% !important; + height: 100% !important; +} \ No newline at end of file diff --git a/src/components/UI/Map/OpenLayerMap.tsx b/src/components/UI/Map/OpenLayerMap.tsx index b8ec282..f02c4ae 100644 --- a/src/components/UI/Map/OpenLayerMap.tsx +++ b/src/components/UI/Map/OpenLayerMap.tsx @@ -7,33 +7,42 @@ import { fromLonLat } from 'ol/proj'; import { Coordinate } from 'ol/coordinate'; import VectorLayer from 'ol/layer/Vector'; import { layerConfigs } from '../../Methods/Layers'; -import { loadAndRenderGeoJsonLayer } from '../../Methods/GeoJson_Load' +import { loadAndRenderGeoJsonLayer } from '../../Methods/GeoJson_Load'; import { addMarker } from '../../Methods/Marker'; const OpenLayersMap = () => { const [term, setTerm] = useState(''); - const [address, setAddress] = useState(); + const [address, setAddress] = useState(); const [layerVisibility, setLayerVisibility] = useState>({}); const [searchCompleted, setSearchCompleted] = useState(false); + const [sidebarOpen, setSidebarOpen] = useState(true); + const [isMobile, setIsMobile] = useState(window.innerWidth < 768); + + // Check for mobile view + useEffect(() => { + const handleResize = () => { + setIsMobile(window.innerWidth < 768); + if (window.innerWidth >= 768) { + setSidebarOpen(true); + } + }; + + window.addEventListener('resize', handleResize); + return () => window.removeEventListener('resize', handleResize); + }, []); // Submit Button Logic const submitForm = async (event: React.FormEvent) => { - // Preventing the page from reloading event.preventDefault(); const response = await fetch(`https://nominatim.openstreetmap.org/search?q=${term}&format=json&polygon=1&addressdetails=1`); const json = await response.json(); - console.log(json); setAddress(json); - console.log(address); setSearchCompleted(true); - - // Initialize all layers as visible + const initialVisibility = Object.fromEntries( layerConfigs.map(layer => [layer.topic, true]) ); setLayerVisibility(initialVisibility); - - alert(term); } const mapDivRef = useRef(null); @@ -50,11 +59,11 @@ const OpenLayersMap = () => { const toggleLayer = (layerTopic: string) => { const layerRef = layerRefs.current[layerTopic]; const isCurrentlyVisible = layerVisibility[layerTopic]; - + if (layerRef.current) { layerRef.current.setVisible(!isCurrentlyVisible); } - + setLayerVisibility(prev => ({ ...prev, [layerTopic]: !isCurrentlyVisible @@ -88,7 +97,7 @@ const OpenLayersMap = () => { })); markerLayerRef.current = addMarker(coords, mapRef.current!, markerLayerRef.current); - + layerConfigs.forEach((layerConfig) => { const url = layerConfig.getUrl(lon, lat, layerConfig.radius); const ref = layerRefs.current[layerConfig.topic]; @@ -102,171 +111,535 @@ const OpenLayersMap = () => { } }, [address]); - // UI return ( -
- {/* Sidebar */} -
+ {/* Google Fonts Link */} + + + + + {/* Header */} +
-

- Map Layers -

- - {/* Search Form */} -
- setTerm(e.target.value)} - type="text" - placeholder="Enter address to search" + {/* Mobile menu button - hidden on desktop */} + -
- {/* Layer Toggle List */} -
-

- Available Layers ({layerConfigs.length}) -

- - {layerConfigs.map((layer) => ( -
M +
+ + MapExplorer + +
+ + {/* Navigation - hidden on mobile */} + + +
+ +
+ U +
+
+
+ + {/* Main Content */} +
+ {/* Sidebar with responsive behavior */} +
+
+
+

+ Map Controls +

+
+ + {/* Search Form */} +
+
+ setTerm(e.target.value)} + type="text" + placeholder="Search for any location..." + style={{ + width: '100%', + padding: '14px 16px', + border: '1px solid #dee2e6', + borderRadius: '12px', + marginBottom: '12px', + fontSize: '14px', + fontFamily: "'Poppins', sans-serif", + backgroundColor: 'white', + boxShadow: '0 2px 4px rgba(0,0,0,0.04)', + transition: 'all 0.3s cubic-bezier(0.4, 0, 0.2, 1)', + boxSizing: 'border-box', + outline: 'none' + }} + /> + +
+
+ + {/* Layer Toggle List */} +
+
- - {formatLayerName(layer.topic)} + Data Layers + + + {layerConfigs.length} - - {searchCompleted && ( -
- - -
- - {/* Map Container */} -
-
- - {clickedCoordinate && ( -
- Coordinates: {clickedCoordinate[0].toFixed(2)} / {clickedCoordinate[1].toFixed(2)} + )} +
+ ))}
- )} +
+ + {/* Map Container */} +
+ {/* Overlay for mobile when sidebar is open */} + {isMobile && sidebarOpen && ( +
setSidebarOpen(false)} + /> + )} + +
+ + {/* Coordinate Display */} + {clickedCoordinate && ( +
+ 📍 Coordinates: {clickedCoordinate[0].toFixed(4)}, {clickedCoordinate[1].toFixed(4)} +
+ )} +
); -}; +} export default OpenLayersMap; \ No newline at end of file