Skip to content

Commit

Permalink
#381: correctly update map widgets when store keys are changing
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas committed Jan 7, 2025
1 parent 0284af0 commit 395c145
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions viewer/components/MapWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Created by andreas on 23.02.16.
*/

import {useEffect, useRef} from "react";
import {useCallback, useEffect, useRef} from "react";
import PropTypes from 'prop-types';
import {useKeyEventHandler} from '../util/GuiHelpers.js';
import base from "../base";
Expand All @@ -12,6 +12,8 @@ import base from "../base";
const MapWidget=(props)=>{
useKeyEventHandler(props,"widget");
const drawing=useRef(null);
const currentProps=useRef(props);
currentProps.current=props;
const userContext=useRef({
/**
* convert lon, lat to canvas pixel
Expand Down Expand Up @@ -78,14 +80,14 @@ const MapWidget=(props)=>{
window.setTimeout(()=>props.triggerRender(),0);
}
});
const getProps=()=>{
const getProps=useCallback( ()=>{
if (! props.translateFunction){
return props;
return currentProps.current;
}
else{
return {...props,...props.translateFunction(...props)};
return {...currentProps.current,...props.translateFunction(...currentProps.current)};
}
}
},[]);
useEffect(() => {
if (typeof(props.initFunction) === 'function'){
try {
Expand Down

0 comments on commit 395c145

Please sign in to comment.