Compare commits
2 Commits
798447760f
...
develop
Author | SHA1 | Date | |
---|---|---|---|
642433994d
|
|||
922760de3e
|
@@ -30,7 +30,7 @@
|
|||||||
"@stitches/core": "^1.2.8",
|
"@stitches/core": "^1.2.8",
|
||||||
"date-fns": "^2.29.3",
|
"date-fns": "^2.29.3",
|
||||||
"matrix-widget-api": "^1.1.1",
|
"matrix-widget-api": "^1.1.1",
|
||||||
"ol": "^7.3.0",
|
"ol": "^8.2.0",
|
||||||
"solid-js": "^1.6.6",
|
"solid-js": "^1.6.6",
|
||||||
"solid-transition-group": "^0.0.10",
|
"solid-transition-group": "^0.0.10",
|
||||||
"solidjs-lazily": "^0.1.2"
|
"solidjs-lazily": "^0.1.2"
|
||||||
|
@@ -41,57 +41,13 @@ export const Map: ParentComponent<{}> = () => {
|
|||||||
// TODO: Set padding according to the marker design.
|
// TODO: Set padding according to the marker design.
|
||||||
const fitPointsPadding = [50, 50, 50, 50];
|
const fitPointsPadding = [50, 50, 50, 50];
|
||||||
|
|
||||||
let mapDiv: HTMLDivElement | undefined;
|
|
||||||
let popup: StopPopup | undefined = undefined;
|
let popup: StopPopup | undefined = undefined;
|
||||||
|
|
||||||
|
const [mapRef, setMapRef] = createSignal<HTMLDivElement>();
|
||||||
|
|
||||||
const stopVectorSource = new OlVectorSource({ features: [] });
|
const stopVectorSource = new OlVectorSource({ features: [] });
|
||||||
const stopVectorLayer = new OlVectorLayer({ source: stopVectorSource });
|
const stopVectorLayer = new OlVectorLayer({ source: stopVectorSource });
|
||||||
|
|
||||||
let overlay: OlOverlay | undefined = undefined;
|
|
||||||
let map: OlMap | undefined = undefined;
|
|
||||||
|
|
||||||
const displayedFeatures: Record<number, OlFeature> = {};
|
|
||||||
|
|
||||||
const buildMap = (div: HTMLDivElement): void => {
|
|
||||||
overlay = new OlOverlay({
|
|
||||||
element: popup,
|
|
||||||
autoPan: {
|
|
||||||
animation: {
|
|
||||||
duration: 250,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
map = new OlMap({
|
|
||||||
target: div,
|
|
||||||
controls: [], // remove controls
|
|
||||||
view: new OlView({
|
|
||||||
center: mapCenter,
|
|
||||||
zoom: 10,
|
|
||||||
}),
|
|
||||||
layers: [
|
|
||||||
new OlTileLayer({
|
|
||||||
source: new OlOSM(),
|
|
||||||
}),
|
|
||||||
stopVectorLayer,
|
|
||||||
],
|
|
||||||
overlays: [overlay],
|
|
||||||
});
|
|
||||||
console.log("map=", map);
|
|
||||||
map.on('singleclick', onClickedMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
const onClickedMap = async (event): Promise<void> => {
|
|
||||||
const features = await stopVectorLayer.getFeatures(event.pixel);
|
|
||||||
// Handle only the first feature
|
|
||||||
if (features.length > 0) {
|
|
||||||
await onClickedFeature(features[0]);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
setPopupDisplayed(false);
|
|
||||||
setSelectedMapStop(undefined);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const onClickedFeature = async (feature: OlFeatureLike): Promise<void> => {
|
const onClickedFeature = async (feature: OlFeatureLike): Promise<void> => {
|
||||||
const stopId: number = feature.getId();
|
const stopId: number = feature.getId();
|
||||||
const stop = getStop(stopId);
|
const stop = getStop(stopId);
|
||||||
@@ -109,10 +65,48 @@ export const Map: ParentComponent<{}> = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
const onClickedMap = async (event): Promise<void> => {
|
||||||
buildMap(mapDiv);
|
const features = await stopVectorLayer.getFeatures(event.pixel);
|
||||||
})
|
// Handle only the first feature
|
||||||
;
|
if (features.length > 0) {
|
||||||
|
await onClickedFeature(features[0]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setPopupDisplayed(false);
|
||||||
|
setSelectedMapStop(undefined);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const displayedFeatures: Record<number, OlFeature> = {};
|
||||||
|
|
||||||
|
const overlay = new OlOverlay({
|
||||||
|
element: popup,
|
||||||
|
autoPan: {
|
||||||
|
animation: {
|
||||||
|
duration: 250,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const map = new OlMap({
|
||||||
|
target: "map",
|
||||||
|
controls: [], // remove controls
|
||||||
|
view: new OlView({
|
||||||
|
center: mapCenter,
|
||||||
|
zoom: 10,
|
||||||
|
}),
|
||||||
|
layers: [
|
||||||
|
new OlTileLayer({
|
||||||
|
source: new OlOSM(),
|
||||||
|
}),
|
||||||
|
stopVectorLayer,
|
||||||
|
],
|
||||||
|
overlays: [overlay],
|
||||||
|
});
|
||||||
|
map.on('singleclick', onClickedMap);
|
||||||
|
|
||||||
|
createEffect(() => {
|
||||||
|
map.setTarget(mapRef());
|
||||||
|
});
|
||||||
|
|
||||||
// Filling the map with stops shape
|
// Filling the map with stops shape
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
@@ -211,7 +205,7 @@ export const Map: ParentComponent<{}> = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return <>
|
return <>
|
||||||
<div ref={mapDiv!} class="map">
|
<div ref={setMapRef!} class="map">
|
||||||
<StopPopup ref={popup!} stop={selectedMapStop()} show={isPopupDisplayed()} />
|
<StopPopup ref={popup!} stop={selectedMapStop()} show={isPopupDisplayed()} />
|
||||||
</div>
|
</div>
|
||||||
<For each={getFoundStops()}>{(stop) => <MapStop stop={stop} selected={selectedMapStop()} />}</For>
|
<For each={getFoundStops()}>{(stop) => <MapStop stop={stop} selected={selectedMapStop()} />}</For>
|
||||||
|
Reference in New Issue
Block a user