Adding a selectHandler (not functional yet).

This commit is contained in:
Eric van der Vlist 2022-11-28 21:36:12 +01:00
parent 42d66ecfa5
commit 400711eb80
3 changed files with 34 additions and 4 deletions

View File

@ -12,6 +12,7 @@ import ScaleLine from 'ol/control/ScaleLine';
import Control from 'ol/control/Control'; import Control from 'ol/control/Control';
import OSM from 'ol/source/OSM'; import OSM from 'ol/source/OSM';
import { useGeographic as olUseGeographic } from 'ol/proj'; import { useGeographic as olUseGeographic } from 'ol/proj';
import DragRotate from 'ol/interaction/DragRotate';
import 'ol/ol.css'; import 'ol/ol.css';
import './Map.css'; import './Map.css';
@ -24,6 +25,16 @@ import { Back, Forward } from '../back-forward';
import GpxImport from '../gpx-import'; import GpxImport from '../gpx-import';
import AllGpxes from '../all-gpxes'; import AllGpxes from '../all-gpxes';
import MapTileProvider, { mapTileProviders } from '../map-tile-provider'; import MapTileProvider, { mapTileProviders } from '../map-tile-provider';
import Interaction from 'ol/interaction/Interaction';
import DoubleClickZoom from 'ol/interaction/DoubleClickZoom';
import DragPan from 'ol/interaction/DragPan';
import PinchRotate from 'ol/interaction/PinchRotate';
import PinchZoom from 'ol/interaction/PinchZoom';
import KeyboardPan from 'ol/interaction/KeyboardPan';
import KeyboardZoom from 'ol/interaction/KeyboardZoom';
import MouseWheelZoom from 'ol/interaction/MouseWheelZoom';
import DragZoom from 'ol/interaction/DragZoom';
import Select from 'ol/interaction/Select';
const [getState, setState] = createSignal({ const [getState, setState] = createSignal({
lon: 0, lon: 0,
@ -115,6 +126,10 @@ const Map: Component = () => {
} }
}); });
const selectHandler = (event: any) => {
console.log({ caller: 'selectHandler', event });
};
onMount(() => { onMount(() => {
olUseGeographic(); olUseGeographic();
@ -144,6 +159,9 @@ const Map: Component = () => {
}); });
tileLayer.set('provider', params.provider, true); tileLayer.set('provider', params.provider, true);
const selectInteraction = new Select({ multi: true });
selectInteraction.on('select', selectHandler);
const olMap = new OlMap({ const olMap = new OlMap({
view: new View({ view: new View({
center: [+getState().lon, +getState().lat], center: [+getState().lon, +getState().lat],
@ -157,6 +175,18 @@ const Map: Component = () => {
new Rotate(), new Rotate(),
new ScaleLine({ bar: true }), new ScaleLine({ bar: true }),
]), ]),
interactions: new Collection<Interaction>([
new DragRotate(),
new DoubleClickZoom(),
new DragPan(),
new PinchRotate(),
new PinchZoom(),
new KeyboardPan(),
new KeyboardZoom(),
new MouseWheelZoom(),
new DragZoom(),
selectInteraction,
]),
}); });
olMap.on(['moveend'], changeListener); olMap.on(['moveend'], changeListener);

View File

@ -37,7 +37,7 @@ export const Trkseg: Component<Props> = ({ vectorSource, trksegId }) => {
type: 'Point', type: 'Point',
coordinates: [trkseg().trkpt[0].$.lon, trkseg().trkpt[0].$.lat], coordinates: [trkseg().trkpt[0].$.lon, trkseg().trkpt[0].$.lat],
}, },
properties: { type: 'trkseg-start' }, properties: { type: 'trkseg-start', id: trksegId },
}, },
{ {
type: 'Feature', type: 'Feature',
@ -48,7 +48,7 @@ export const Trkseg: Component<Props> = ({ vectorSource, trksegId }) => {
trkpt.$.lat, trkpt.$.lat,
]), ]),
}, },
properties: { type: 'trkseg' }, properties: { type: 'trkseg', id: trksegId },
}, },
{ {
type: 'Feature', type: 'Feature',
@ -59,7 +59,7 @@ export const Trkseg: Component<Props> = ({ vectorSource, trksegId }) => {
trkseg().trkpt.at(-1).$.lat, trkseg().trkpt.at(-1).$.lat,
], ],
}, },
properties: { type: 'trkseg-finish' }, properties: { type: 'trkseg-finish', id: trksegId },
}, },
], ],
}; };

View File

@ -37,7 +37,7 @@ export const Wpt: Component<Props> = ({ vectorSource, wptId: wptId }) => {
type: 'Point', type: 'Point',
coordinates: [wpt().$.lon, wpt().$.lat], coordinates: [wpt().$.lon, wpt().$.lat],
}, },
properties: { type: 'wpt', ...wpt() }, properties: { type: 'wpt', ...wpt(), id: wptId },
}, },
], ],
}; };