Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
sirmmo committed Dec 9, 2024
1 parent 0f883ce commit 86e1f99
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
14 changes: 9 additions & 5 deletions src/app/components/Map/VectorWrapperLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const VectorWrapperLayer = (props: any) => {
const map = useMap();
const context = useLeafletContext();

let selected = false;
let selected = useRef<any>();

const url = `https://arpav.geobeyond.dev/vector-tiles/municipalities/{z}/{x}/{y}`;

Expand Down Expand Up @@ -51,9 +51,13 @@ export const VectorWrapperLayer = (props: any) => {
},
})
.on('click', function (e) {
_vectorLayer.resetFeatureStyle(selected);
selected = e.layer.properties.name;
_vectorLayer.setFeatureStyle(e.layer.properties.name, {
const ls = localStorage.getItem('muni');
if (ls) {
_vectorLayer.resetFeatureStyle(ls);
}
selected.current = e.layer.properties.name;
localStorage.setItem('muni', e.layer.properties.name);
_vectorLayer.setFeatureStyle(selected.current, {
color: '#164d36',
weight: 2,
radius: 1,
Expand All @@ -62,7 +66,7 @@ export const VectorWrapperLayer = (props: any) => {
opacity: 1,
});
_vectorLayer.bringToFront();
if (selected && e.layer) {
if (selected.current && e.layer) {
const payload = {
...e.layer.properties,
latlng: e.latlng,
Expand Down
40 changes: 34 additions & 6 deletions src/app/pages/MapPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* MapPage
*
*/
import React, { useEffect, useState } from 'react';
import React, { useEffect, useState, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import {
Box,
Expand Down Expand Up @@ -107,6 +107,9 @@ export function MapPage(props: MapPageProps) {
const [currentYear, setCurrentYear] = useState(2036);
//const [loading, showLoader] = useState(false);

const currentInfo = useRef(false);
const currentHide = useRef<any>();

const handleMapReady = (map: LMap) => {
mapRef.current = map;
const mapScreenPlugin = new SimpleMapScreenshoter(PLUGIN_OPTIONS);
Expand Down Expand Up @@ -293,6 +296,32 @@ export function MapPage(props: MapPageProps) {
} catch (e) {
console.log(e);
}

//@ts-ignore
mapRef.current.on(
'simpleMapScreenshoter.takeScreen',
() => {
currentInfo.current = document
.getElementsByClassName('leaflet-time-info')[0]
//@ts-ignore
.checkVisibility();
currentHide.current = setInterval(() => {
document
//@ts-ignore
.getElementsByClassName('leaflet-time-info')[0].style.display =
'none';
});
},
250,
);
//@ts-ignore
mapRef.current.on('simpleMapScreenshoter.done', () => {
clearInterval(currentHide.current);
document
//@ts-ignore
.getElementsByClassName('leaflet-time-info')[0].style.display =
currentInfo.current ? 'flex' : 'none';
});
}, [currentMap]);

useEffect(() => {
Expand Down Expand Up @@ -330,7 +359,6 @@ export function MapPage(props: MapPageProps) {
'.leaflet-control-coordinates',
'.leaflet-bar-timecontrol',
'.leaflet-control-layers',
'.leaflet-time-info',
], // by default hide map controls All els must be child of _map._container
mimeType: 'image/jpeg', // used if format == image,
caption: `${findValueName('variable', 'variables')}
Expand Down Expand Up @@ -377,8 +405,8 @@ export function MapPage(props: MapPageProps) {

setInProgress(true);
const caption = `${isMobile
? currentMap.climatological_variable
: labelFor(currentMap.climatological_variable)
? currentMap.climatological_variable
: labelFor(currentMap.climatological_variable)
}
- ${joinNames([
labelFor(currentMap.climatological_model),
Expand Down Expand Up @@ -407,8 +435,8 @@ export function MapPage(props: MapPageProps) {
labelFor(currentMap.aggregation_period),
labelFor(currentMap.measure),
])} ${currentMap.time_window && currentMap.aggregation_period === '30yr'
? ' - ' + labelFor(currentMap.time_window)
: ''
? ' - ' + labelFor(currentMap.time_window)
: ''
} - ${labelFor(currentMap.year_period)} ${currentMap.aggregation_period != '30yr' && currentYear
? ` - Anno ${year}`
: ''
Expand Down

0 comments on commit 86e1f99

Please sign in to comment.