Refactoring to use the finder from en intent.

This commit is contained in:
Eric van der Vlist 2023-02-02 16:58:23 +01:00
parent 55830251e0
commit dec79c9c2d
2 changed files with 37 additions and 31 deletions

View File

@ -14,26 +14,56 @@ import { Overlay } from 'ol';
import { fromLonLat } from 'ol/proj';
import WptEditDialog from '../wpt/WptEditDialog';
const [popup, setPopup] = createSignal<Overlay>();
const [open, setOpen] = createSignal(false);
let popupElement: HTMLElement;
export const findLocation = (
navigate: (url: string) => void,
coordinate: Coordinate
) => {
setOpen(false);
if (popup() === undefined) {
setPopup(
new Overlay({
element: popupElement,
positioning: 'center-center',
})
);
}
console.log({
caller: 'Finder / submitHandler / popup',
coordinate,
popup: popup(),
popupElement,
});
popup().setMap(getMap());
popup().setPosition(fromLonLat(coordinate));
getMap()?.addOverlay(popup());
navigate(
`/map/${getState().provider}/${coordinate[0]}/${coordinate[1]}/16/${
getState().rotation
}`
);
};
interface Props {}
const Finder: Component<Props> = (props) => {
const [open, setOpen] = createSignal(false);
const [searchString, setSearchString] = createSignal('');
const [popupContent, setPopupContent] = createSignal(<></>);
const navigate = useNavigate();
const [t, { add, locale, dict }] = useI18n();
const [popup, setPopup] = createSignal<Overlay>();
const [coordinate, setCoordinate] = createSignal<Coordinate>();
const searchStringChangeHandler = (event: any) => {
setSearchString(event.target.value);
};
const navigate = useNavigate();
const popupCloseHandler = () => {
popup()?.setMap(null);
};
let popupElement: HTMLElement;
const submitHandler = () => {
const latLonRegExp = /(-?[0-9]+.[0-9]+)\s*,\s*(-?[0-9]+.[0-9]+)/;
const latLonMatch = searchString().match(latLonRegExp);
@ -66,31 +96,7 @@ const Finder: Component<Props> = (props) => {
}
if (!!coordinate()) {
setOpen(false);
if (popup() === undefined) {
setPopup(
new Overlay({
element: popupElement,
positioning: 'center-center',
})
);
}
console.log({
caller: 'Finder / submitHandler / popup',
searchString: searchString(),
coordinate: coordinate(),
popup: popup(),
popupElement,
});
popup().setMap(getMap());
popup().setPosition(fromLonLat(coordinate()));
getMap()?.addOverlay(popup());
navigate(
`/map/${getState().provider}/${coordinate()[0]}/${coordinate()[1]}/16/${
getState().rotation
}`
);
findLocation(navigate, coordinate());
}
};

View File

@ -1 +1 @@
export { default } from './Finder';
export { default, findLocation } from './Finder';