import { useCallback, useEffect, useRef, useState } from 'react' import GeoJSON from 'ol/format/GeoJSON' import 'ol/ol.css' import Map from 'ol/Map' import View from 'ol/View' import { Draw, Modify, Select, Snap, Translate } from 'ol/interaction' import { ImageStatic, OSM, Vector as VectorSource, XYZ } from 'ol/source' import { Tile as TileLayer, Vector as VectorLayer } from 'ol/layer' import { Type } from 'ol/geom/Geometry' import { click, never, noModifierKeys, platformModifierKeyOnly, primaryAction, shiftKeyOnly } from 'ol/events/condition' import Feature from 'ol/Feature' import { SatelliteMapsProvider } from '../../interfaces/map' import { containsExtent, Extent } from 'ol/extent' import { drawingLayerStyle, regionsLayerStyle, selectStyle } from './MapStyles' import { googleMapsSatelliteSource, regionsLayerSource, yandexMapsSatelliteSource } from './MapSources' import { mapCenter } from './MapConstants' import ImageLayer from 'ol/layer/Image' import VectorImageLayer from 'ol/layer/VectorImage' import { Circle, LineString, MultiPoint, Point, Polygon, SimpleGeometry } from 'ol/geom' import { fromCircle, fromExtent } from 'ol/geom/Polygon' import Collection from 'ol/Collection' import { Coordinate } from 'ol/coordinate' import { Stroke, Fill, Circle as CircleStyle, Style, Text } from 'ol/style' import { calculateCenter, calculateExtent, calculateRotationAngle, rotateProjection } from './mapUtils' import MapBrowserEvent from 'ol/MapBrowserEvent' import { get, transform } from 'ol/proj' import { useCities } from '../../hooks/swrHooks' import useSWR from 'swr' import { fetcher } from '../../http/axiosInstance' import { BASE_URL } from '../../constants' import { Accordion, ActionIcon, Autocomplete, Box, Button, CloseButton, Flex, Grid, Select as MantineSelect, Text as MantineText, MantineStyleProp, rem, ScrollAreaAutosize, Slider, useMantineColorScheme, Divider, Portal } from '@mantine/core' import { IconApi, IconArrowBackUp, IconArrowsMove, IconCircle, IconExclamationCircle, IconLine, IconPlus, IconPoint, IconPolygon, IconRuler, IconSettings, IconTable, IconUpload } from '@tabler/icons-react' import { getGridCellPosition } from './mapUtils' import { IFigure, ILine } from '../../interfaces/gis' import axios from 'axios' import ObjectParameter from './ObjectParameter' import { IObjectData, IObjectParam } from '../../interfaces/objects' import ObjectData from './ObjectData' const MapComponent = () => { //const { cities } = useCities(100, 1) // useEffect(() => { // if (cities) { // cities.map((city: any) => { // citiesLayer.current?.getSource()?.addFeature(new Feature(new Point(fromLonLat([city.longitude, city.width])))) // }) // } // }, [cities]) const [currentCoordinate, setCurrentCoordinate] = useState(null) const [currentZ, setCurrentZ] = useState(undefined) const [currentX, setCurrentX] = useState(undefined) const [currentY, setCurrentY] = useState(undefined) const [file, setFile] = useState(null) const [polygonExtent, setPolygonExtent] = useState(undefined) const [bottomLeft, setBottomLeft] = useState(undefined) const [topLeft, setTopLeft] = useState(undefined) const [topRight, setTopRight] = useState(undefined) const [bottomRight, setBottomRight] = useState(undefined) const mapElement = useRef(null) const [currentTool, setCurrentTool] = useState(null) const map = useRef(null) const [satMapsProvider, setSatMapsProvider] = useState('custom') const gMapsSatSource = useRef(googleMapsSatelliteSource) const customMapSource = useRef(new XYZ({ url: `${import.meta.env.VITE_API_EMS_URL}/tile/custom/{z}/{x}/{y}`, attributions: 'Custom map data' })) const yMapsSatSource = useRef(yandexMapsSatelliteSource) const satLayer = useRef(new TileLayer({ source: gMapsSatSource.current, })) const draw = useRef(null) const snap = useRef(null) const selectFeature = useRef