From a42c6d99a1807d3073bc45315dc1c0b917ed219e Mon Sep 17 00:00:00 2001 From: evlist Date: Sat, 28 Jan 2023 21:51:28 +0100 Subject: [PATCH] Calling when receiving location intent. --- src/components/infos/Infos.tsx | 6 ++++-- src/components/map/Map.tsx | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/infos/Infos.tsx b/src/components/infos/Infos.tsx index e10a01d..5ffb1bc 100644 --- a/src/components/infos/Infos.tsx +++ b/src/components/infos/Infos.tsx @@ -24,6 +24,7 @@ import style from '../gpx/styles'; import OsmFindAll from './OsmFindAll'; import { eventNames } from 'pouchdb-browser'; import { toLonLat } from 'ol/proj'; +import { getMap } from '../map'; const Item = styled(Paper)(({ theme }) => ({ ...theme.typography.body2, @@ -47,9 +48,10 @@ const level2Key = (feature: Feature) => export const clickHandler = (event: any) => { hierarchy = {}; + const map = event.map || getMap(); const pixel = [event.originalEvent.x, event.originalEvent.y]; - const features = event.map.getFeaturesAtPixel(pixel, { hitTolerance: 30 }); - setLocation(toLonLat(event.map.getCoordinateFromPixel(pixel))); + const features = map.getFeaturesAtPixel(pixel, { hitTolerance: 30 }); + setLocation(toLonLat(map.getCoordinateFromPixel(pixel))); console.log({ caller: 'Infos.tsx / clickHandler', features, event }); selectedFeatures.map((feature) => { if (feature.set) { diff --git a/src/components/map/Map.tsx b/src/components/map/Map.tsx index 22d1f22..111561a 100644 --- a/src/components/map/Map.tsx +++ b/src/components/map/Map.tsx @@ -50,6 +50,7 @@ import MVT from 'ol/format/MVT.js'; import style from '../gpx/styles'; import ClusterableVectorTileSourceProxy from '../../lib/ClusterableVectorTileSourceProxy'; import { Overlays } from '../overlays/Overlays'; +import { WindowSharp } from '@suid/icons-material'; const [getState, setState] = createSignal({ lon: 0, @@ -93,13 +94,17 @@ const Map: Component = () => { const url = new URL(intent.data); const q = url.search; const [, lat, lon] = q.match(/q=([0-9.-]+),([0-9.-]+)/); - const zoom = Math.min(18, getState().zoom); + const zoom = Math.max(18, getState().zoom); console.log({ caller: 'Intent receiver', intent, url, lat, lon, zoom }); navigate( `/map/${getState().provider}/${lon}/${lat}/${zoom}/${ getState().rotation }` ); + clickHandler({ + map: false, + originalEvent: { x: window.innerWidth / 2, y: window.innerHeight / 2 }, + }); }); } else { console.log({