// frontend/src/KGMap/KyrgyzstanMap.jsx import React, { useState } from 'react'; import…
- User
// frontend/src/KGMap/KyrgyzstanMap.jsx
import React, { useState } from 'react'; import { MapContainer, TileLayer, GeoJSON } from 'react-leaflet'; import 'leaflet/dist/leaflet.css'; import './KyrgyzstanMap.scss'; import Button from '../Button/Button';
import kyrgyzstanData from '../data/kyrgyzstan.json'; import worldData from '../data/world.json';
const KyrgyzstanMap = () => { // State variables to manage panel visibility and info const [currentStyle, setCurrentStyle] = useState('streets'); const [isControlPanelOpen, setIsControlPanelOpen] = useState(false); const [isInfoPanelOpen, setIsInfoPanelOpen] = useState(false); const [kyrgyzstanInfo, setKyrgyzstanInfo] = useState(null);
const bounds = [ [34, 64], [48, 85], ];
const center = [41.2044, 74.7661]; const minZoom = 5; const maxZoom = 15;
const handleChangeStyle = (styleId) => { setCurrentStyle(styleId); };
const styleMap = { streets: { url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', attribution: '© OpenStreetMap contributors', }, satellite: { url: 'https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', attribution: '© OpenTopoMap', }, light: { url: 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png', attribution: '© CARTO', }, dark: { url: 'https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png', attribution: '© CARTO', }, outdoors: { url: 'https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', attribution: '© OpenStreetMap contributors, Tiles style by HOT', }, };
// Styles for other countries and Kyrgyzstan const otherCountriesStyle = { fillColor: '#808080', fillOpacity: 0.4, weight: 0, opacity: 0, };
const kyrgyzstanStyle = { fillColor: 'transparent', fillOpacity: 0, weight: 0, opacity: 0, };
// Function to handle clicks on Kyrgyzstan const onKyrgyzstanClick = () => { // Adjust based on your JSON structure setKyrgyzstanInfo(kyrgyzstanData.properties); setIsInfoPanelOpen(true); };
// Component to render Kyrgyzstan GeoJSON with event handlers const KyrgyzstanGeoJSON = () => { const onEachFeature = (feature, layer) => { if (feature.properties && (feature.properties.ADMIN === 'Kyrgyzstan' || feature.properties.NAME === 'Kyrgyzstan')) { layer.on({ click: onKyrgyzstanClick, }); layer.bindTooltip('Кыргызстан'); // Optional tooltip } };
codereturn ( <GeoJSON data={kyrgyzstanData} style={kyrgyzstanStyle} onEachFeature={onEachFeature} /> );};
return ( {/* Top-Left Button: Control Panel Toggle */} <Button className={
top-left-button ${isControlPanelOpen ? 'active' : ''}} onClick={() => setIsControlPanelOpen(!isControlPanelOpen)} variant="outline" aria-label="Toggle Control Panel" > ≡code - Assistant