import { useRef, useState, useEffect, lazy } from 'react'; import { Root, createRoot } from 'react-dom/client'; import { useTranslation } from 'react-i18next'; import initI18n from './i18n'; import MapView from '@arcgis/core/views/MapView'; import WebMap from '@arcgis/core/WebMap'; import esriConfig from '@arcgis/core/config'; import ScaleBar from '@arcgis/core/widgets/ScaleBar'; import Legend from '@arcgis/core/widgets/Legend'; import WMTSLayer from '@arcgis/core/layers/WMTSLayer'; import VectorTileLayer from '@arcgis/core/layers/VectorTileLayer'; import TileLayer from '@arcgis/core/layers/TileLayer'; import Map from '@arcgis/core/Map.js'; import Basemap from '@arcgis/core/Basemap'; import * as intl from '@arcgis/core/intl'; // set asset path for ArcGIS Maps SDK widgets esriConfig.assetsPath = './assets'; // ids of web map items in portal const webMapDEID = '7d0768f73d3e4be2b32c22274c600cb3'; const webMapENID = 'dbf5532d06954c6a989d4f022de83f70'; // lazy load print component const Print = lazy(() => import('./print')); const Layers = lazy(() => import('./layer-list')); const Basemaps = lazy(() => import('./basemap-list')); const Search = lazy(() => import('./search')); // import Calcite components import '@esri/calcite-components/dist/calcite/calcite.css'; import { setAssetPath } from '@esri/calcite-components/dist/components'; setAssetPath(window.location.href); import '@esri/calcite-components/dist/components/calcite-shell'; import '@esri/calcite-components/dist/components/calcite-shell-panel'; import '@esri/calcite-components/dist/components/calcite-shell-center-row'; import '@esri/calcite-components/dist/components/calcite-action-bar'; import '@esri/calcite-components/dist/components/calcite-action'; import '@esri/calcite-components/dist/components/calcite-panel'; import { CalciteShell, CalciteShellPanel, CalciteActionBar, CalciteAction, CalcitePanel, } from '@esri/calcite-components-react'; // load localized strings const match = location.pathname.match(/\/(\w+)/); if (match && match.length > 1) { const locale = match[1]; initI18n(locale); } export default function MapComponent({ locale }: { locale: string }) { const printRoot = useRef(null); const maskRoot = useRef(null); const tableRoot = useRef(null); const mapView = useRef(null); const previousId = useRef(null); const [actionBarExpanded, setActionBarExpanded] = useState(false); const { t } = useTranslation(); useEffect(() => { if (!mapView.current) { // set locale for ArcGIS Maps SDK widgets intl.setLocale(locale); const webMap = new WebMap({ portalItem: { id: locale === 'de' ? webMapDEID : webMapENID, portal: { url: 'https://gis.geosphere.at/portal', }, }, }); // const wmtsLayer = new WMTSLayer({ // url: 'https://mapsneu.wien.gv.at/basemapneu', // }); // const basemap = new Basemap({ // baseLayers: [wmtsLayer], // }); const lightgrayBase = new VectorTileLayer({ url: 'https://gis.geosphere.at/portal/sharing/rest/content/items/291da5eab3a0412593b66d384379f89f/resources/styles/root.json', opacity: 0.5, }); const lightGrayReference = new VectorTileLayer({ url: 'https://gis.geosphere.at/portal/sharing/rest/content/items/1768e8369a214dfab4e2167d5c5f2454/resources/styles/root.json', opacity: 1, }); const worldHillshade = new TileLayer({ url: 'https://services.arcgisonline.com/arcgis/rest/services/Elevation/World_Hillshade/MapServer', }); const basemapEsri = new Basemap({ baseLayers: [worldHillshade, lightgrayBase, lightGrayReference], title: 'Esri', thumbnailUrl: 'https://gis.geosphere.at/portal/sharing/rest/content/items/3eb1510943be4f29ae01c01ce229d8ba/data', }); const map = new Map({ basemap: basemapEsri, }); const view = new MapView({ container: 'map-container', map: map, padding: { left: 49, }, popup: { dockOptions: { position: 'auto', breakpoint: { width: 5000, }, }, }, extent: { ymax: 6424330, xmin: 923200, xmax: 2017806, ymin: 5616270, spatialReference: { wkid: 3857, }, }, }); mapView.current = view; view.ui.empty('top-left'); webMap.load().then(() => { map.layers = webMap.layers; createRoot(document.createElement('div')).render(); }); const scaleBar = new ScaleBar({ view: view, unit: 'metric', }); view.ui.add([scaleBar], 'bottom-left'); new Legend({ view: view, container: 'legend-container', }); } return () => {}; }, [locale]); const handleCalciteActionBarToggle = () => { setActionBarExpanded(!actionBarExpanded); if (mapView.current) { mapView.current.padding = !actionBarExpanded ? { left: 150 } : { left: 49 }; } if (tableRoot.current) { if (!actionBarExpanded) { tableRoot.current.classList.add('left-40'); tableRoot.current.classList.remove('left-14'); } else { tableRoot.current.classList.add('left-14'); tableRoot.current.classList.remove('left-40'); } } }; const handleClick = (event: any) => { if (event.target.tagName !== 'CALCITE-ACTION') { return; } const nextId = event.target.dataset.actionId; if (previousId.current) { const previousPanel = document.querySelector(`[data-panel-id=${previousId.current}]`) as HTMLCalcitePanelElement; if (previousPanel) { previousPanel.hidden = true; } if (previousId.current === 'print') { maskRoot.current?.classList.add('hidden'); } } const nextPanel = document.querySelector(`[data-panel-id=${nextId}]`) as HTMLCalcitePanelElement; if (nextPanel && nextId !== previousId.current) { nextPanel.hidden = false; previousId.current = nextId; if (nextId === 'print') { maskRoot.current?.classList.remove('hidden'); } } else { previousId.current = null; } }; return (

); }