Skip to content

Commit 4f9ce02

Browse files
committed
Enable FreieTonne layers again using new service
1 parent 33fd002 commit 4f9ce02

7 files changed

Lines changed: 45 additions & 19 deletions

File tree

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"leaflet-doubletapdrag": "^0.1.2",
6262
"leaflet-doubletapdragzoom": "^0.3.2",
6363
"leaflet-draggable-lines": "^3.2.1",
64+
"leaflet-freie-tonne": "^2.1.2",
6465
"leaflet-mouse-position": "^1.2.0",
6566
"leaflet.heightgraph": "^1.4.0",
6667
"leaflet.locatecontrol": "^0.83.1",

frontend/src/lib/components/client-provider.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
function isMapNotFoundError(serverError: Client["serverError"]): boolean {
1515
return !!serverError && serverError instanceof MapNotFoundError;
1616
}
17+
18+
export const activeClients = new Set<ClientContext>();
1719
</script>
1820

1921
<script setup lang="ts">
@@ -65,6 +67,7 @@
6567
}
6668
});
6769
connectingClient.value = newClient;
70+
activeClients.add(newClient);
6871
6972
let lastMapId: MapId | undefined = undefined;
7073
let lastMapData: MapData | undefined = undefined;
@@ -93,11 +96,15 @@
9396
if (toRaw(connectingClient.value) !== newClient) {
9497
// Another client has been initiated in the meantime
9598
newClient.disconnect();
99+
activeClients.delete(newClient);
96100
return;
97101
}
98102
99103
connectingClient.value = undefined;
100-
client.value?.disconnect();
104+
if (client.value) {
105+
client.value.disconnect();
106+
activeClients.delete(toRaw(client.value));
107+
}
101108
client.value = newClient;
102109
}, { immediate: true });
103110

frontend/src/map/map.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import "../lib/bootstrap.scss"; // Not imported in lib/index.ts because we don't
66
import { setLayerOptions } from "facilmap-leaflet";
77
import config from "./config";
88
import { registerDereferrerHandler } from "../utils/dereferrer";
9+
import { getFreieTonneUrl, setFreieTonneFetchAdapter } from "leaflet-freie-tonne";
10+
import { activeClients } from "../lib/components/client-provider.vue";
911

1012
if (import.meta.hot) {
1113
// Prevent full reload, see https://github.com/vitejs/vite/issues/5763#issuecomment-1974235806
@@ -35,6 +37,20 @@ const initialMapId = decodeURIComponent(location.pathname.match(/[^/]*$/)![0]) |
3537

3638
registerDereferrerHandler(baseUrl);
3739

40+
setFreieTonneFetchAdapter(async (bounds, zoom) => {
41+
const url = getFreieTonneUrl(bounds, zoom);
42+
const client = activeClients.values().next().value;
43+
if (client) {
44+
const result = await client.find({ query: url, loadUrls: true });
45+
if (typeof result !== "string") {
46+
throw new Error(`Search for URL (${url}) did not return string.`);
47+
}
48+
return result;
49+
} else {
50+
return await fetch(url).then((res) => res.text());
51+
}
52+
});
53+
3854
if(!location.hash || location.hash == "#") {
3955
const moveKeys = Object.keys(queryParams).filter((key) => ([ "zoom", "lat", "lon", "layer", "l", "q", "s", "c" ].includes(key)));
4056
if(moveKeys.length > 0) {

leaflet/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"filtrex": "^2.2.3",
4747
"leaflet-auto-graticule": "^2.0.0",
4848
"leaflet-draggable-lines": "^3.2.1",
49-
"leaflet-freie-tonne": "^2.0.1",
49+
"leaflet-freie-tonne": "^2.1.2",
5050
"leaflet-highlightable-layers": "^4.0.4",
5151
"leaflet.markercluster": "^1.5.3",
5252
"lodash-es": "^4.17.21"

leaflet/src/layers.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Layer, Map, tileLayer, type TileLayer } from "leaflet";
22
import AutoGraticule from "leaflet-auto-graticule";
33
import { getI18n } from "./utils/i18n";
44
import { markdownInline } from "facilmap-utils";
5+
import FreieTonne from "leaflet-freie-tonne";
56

67
export const defaultVisibleLayers: VisibleLayers = {
78
baseLayer: "Mpnk",
@@ -99,11 +100,11 @@ export function createDefaultLayers(): Layers & { fallbackLayer: string | undefi
99100
noWrap: true
100101
})),
101102

102-
// MpnW: fixAttribution(tileLayer("http://ftdl.de/tile-cache/tiles/{z}/{x}/{y}.png", {
103-
// ...fmName(() => getI18n().t("layers.mpnw-name")),
104-
// ...attribution(() => getI18n().t("layers.mpnw-attribution")),
105-
// noWrap: true
106-
// })),
103+
MpnW: fixAttribution(tileLayer("https://www.freietonne.de/seekarte-2.0/tah.openstreetmap.org/Tiles/TileCache.php?z={z}&x={x}&y={y}.png", {
104+
...fmName(() => getI18n().t("layers.mpnw-name")),
105+
...attribution(() => getI18n().t("layers.mpnw-attribution")),
106+
noWrap: true
107+
})),
107108
},
108109
overlays: {
109110
OPTM: fixAttribution(tileLayer("https://pt.facilmap.org/tile/{z}/{x}/{y}.png", {
@@ -173,12 +174,12 @@ export function createDefaultLayers(): Layers & { fallbackLayer: string | undefi
173174
noWrap: true
174175
}),
175176

176-
// FrTo: fixAttribution(new FreieTonne({
177-
// ...fmName(() => getI18n().t("layers.frto-name")),
178-
// ...attribution(() => getI18n().t("layers.frto-attribution")),
179-
// zIndex: 300,
180-
// noWrap: true
181-
// }))
177+
FrTo: fixAttribution(new FreieTonne({
178+
...fmName(() => getI18n().t("layers.frto-name")),
179+
...attribution(() => getI18n().t("layers.frto-attribution")),
180+
zIndex: 300,
181+
noWrap: true
182+
}))
182183
},
183184
fallbackLayer: 'Mpnk'
184185
};

server/src/search.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async function _loadUrl(url: string): Promise<string> {
5050

5151
const body = new TextDecoder().decode(stripBomBuf(bodyBuf));
5252

53-
if(url.match(/^https?:\/\/www\.freietonne\.de\/seekarte\/getOpenLayerPois\.php\?/))
53+
if(url.match(/^https?:\/\/www\.freietonne\.de\/seekarte(-[0-9.]+)?\/getOpenLayerPois\.php\?/))
5454
return body;
5555
else if(body.match(/^\s*</)) {
5656
const $ = load(body, { xmlMode: true });

yarn.lock

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4147,6 +4147,7 @@ __metadata:
41474147
leaflet-doubletapdrag: ^0.1.2
41484148
leaflet-doubletapdragzoom: ^0.3.2
41494149
leaflet-draggable-lines: ^3.2.1
4150+
leaflet-freie-tonne: ^2.1.2
41504151
leaflet-mouse-position: ^1.2.0
41514152
leaflet.heightgraph: ^1.4.0
41524153
leaflet.locatecontrol: ^0.83.1
@@ -4223,7 +4224,7 @@ __metadata:
42234224
happy-dom: ^17.1.8
42244225
leaflet-auto-graticule: ^2.0.0
42254226
leaflet-draggable-lines: ^3.2.1
4226-
leaflet-freie-tonne: ^2.0.1
4227+
leaflet-freie-tonne: ^2.1.2
42274228
leaflet-highlightable-layers: ^4.0.4
42284229
leaflet.markercluster: ^1.5.3
42294230
lodash-es: ^4.17.21
@@ -5785,12 +5786,12 @@ __metadata:
57855786
languageName: node
57865787
linkType: hard
57875788

5788-
"leaflet-freie-tonne@npm:^2.0.1":
5789-
version: 2.0.1
5790-
resolution: "leaflet-freie-tonne@npm:2.0.1"
5789+
"leaflet-freie-tonne@npm:^2.1.2":
5790+
version: 2.1.2
5791+
resolution: "leaflet-freie-tonne@npm:2.1.2"
57915792
peerDependencies:
57925793
leaflet: x
5793-
checksum: d9f7d7c6bf62d7d4421933b295d9226d01bc314e1c5bbe33421f6e9eda16cf3d5bf3a8c5a6e573f3b2e44b55b483fed5c2717dd4c73cbc4a431f7ac5ba093323
5794+
checksum: b18dd958a74b10dd4f90a1287ef62ef73e2ee3172ab8f378faa31f05eed496e86b2497186e335679d4d69855987fc69133a2919e6eff6f65d4ccf279db348004
57945795
languageName: node
57955796
linkType: hard
57965797

0 commit comments

Comments
 (0)