Skip to content

Commit 8ec1f9e

Browse files
committed
Adding a vector tile layer
1 parent db2f4fb commit 8ec1f9e

File tree

3 files changed

+78
-13
lines changed

3 files changed

+78
-13
lines changed

src/lib/components/data-vis/map/Map.svelte

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import {
33
MapLibre,
44
GeoJSON,
5+
VectorTileSource,
56
FillLayer,
67
LineLayer,
78
zoomTransition,
@@ -163,6 +164,14 @@
163164
: colorbrewer[colorPalette][breakCount],
164165
);
165166
167+
let tooFewColors = $derived(fillColors.length < breakCount);
168+
169+
$effect(() => {
170+
if (tooFewColors) {
171+
console.warn("Too few colours for the number of breaks");
172+
}
173+
});
174+
166175
let borderColor = "#003300";
167176
168177
let map: maplibregl.Map | undefined = $state();
@@ -369,7 +378,7 @@
369378
<ScaleControl position={scaleControlPosition} unit={scaleControlUnit} />
370379
{/if}
371380

372-
<GeoJSON id="areas" data={merged} promoteId="areanm">
381+
<!-- <GeoJSON id="areas" data={merged} promoteId="areanm">
373382
<FillLayer
374383
paint={{
375384
"fill-color": ["coalesce", ["get", "color"], "lightgrey"],
@@ -404,7 +413,66 @@
404413
beforeLayerType="symbol"
405414
/>
406415
{/if}
407-
</GeoJSON>
416+
</GeoJSON> -->
417+
418+
<!-- <VectorTileSource
419+
tiles={[
420+
"https://tiles.mapillary.com/maps/vtp/mly1_public/2/{z}/{x}/{y}?access_token=MLY|4142433049200173|72206abe5035850d6743b23a49c41333",
421+
]}
422+
> -->
423+
424+
<!-- <VectorTileSource
425+
id={"imdlayer"}
426+
tiles={["https://cdn.ons.gov.uk/maptiles/t18/tiles/{z}/{x}/{y}.pbf"]}
427+
> -->
428+
429+
<VectorTileSource
430+
id={"lsoas"}
431+
promoteId={"LSOA21NM"}
432+
tiles={["http://localhost:8080/{z}/{x}/{y}.pbf"]}
433+
minzoom={6}
434+
maxzoom={14}
435+
>
436+
<FillLayer
437+
paint={{
438+
"fill-color": "#234567",
439+
"fill-opacity": 0.4,
440+
}}
441+
sourceLayer={"LSOA"}
442+
onclick={interactive
443+
? (e) => {
444+
console.log(e);
445+
return zoomToArea(e);
446+
}
447+
: undefined}
448+
onmousemove={interactive
449+
? (e) => {
450+
hoveredArea = e.features[0].id;
451+
hoveredAreaData =
452+
e.features[0].properties[
453+
"Index of Multiple Deprivation (IMD) Rank"
454+
];
455+
currentMousePosition = e.event.point;
456+
}
457+
: undefined}
458+
onmouseleave={interactive
459+
? () => {
460+
hoveredArea = null;
461+
hoveredAreaData = null;
462+
}
463+
: undefined}
464+
></FillLayer>
465+
<LineLayer
466+
layout={{ "line-cap": "round", "line-join": "round" }}
467+
paint={{
468+
"line-color": hoverStateFilter(borderColor, "orange"),
469+
"line-width": zoomTransition(3, 0, 12, maxBorderWidth),
470+
}}
471+
beforeLayerType="symbol"
472+
sourceLayer={"LSOA"}
473+
/>
474+
</VectorTileSource>
475+
<!-- Important note: sourceLayer must match `-l` value from tippecanoe -->
408476

409477
{#if interactive && tooltip}
410478
<Tooltip

src/lib/components/data-vis/map/Tooltip.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
$props();
44
let tooltipHeight = $state();
55
let tooltipWidth = $state();
6+
$inspect(hoveredAreaData);
67
// $inspect(tooltipHeight, tooltipWidth, currentMousePosition);
78
</script>
89

@@ -15,8 +16,7 @@
1516
>
1617
<p>{hoveredArea}</p>
1718
<p class="detail">
18-
{year}
19-
{metric}: {isNaN(hoveredAreaData) ? "No data" : hoveredAreaData}
19+
2019 IMD rank: {hoveredAreaData ?? "No data"}
2020
</p>
2121
</div>
2222
{/if}

src/wrappers/components/data-vis/map/MapWrapper.svelte

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,20 +189,16 @@
189189
{
190190
name: "maxZoom",
191191
isProp: true,
192-
description:
193-
"Add zoom in and out, and 'reset bearing to north' buttons",
194-
value: 10,
195-
category: "UI",
196-
visible: { name: "standardControls", value: false },
192+
description: "The maximum zoom level, up to 22",
193+
value: 15,
194+
category: "View",
197195
},
198196
{
199197
name: "minZoom",
200198
isProp: true,
201-
description:
202-
"Add zoom in and out, and 'reset bearing to north' buttons",
199+
description: "The minimum zoom level, at least 0",
203200
value: 0,
204-
category: "UI",
205-
visible: { name: "standardControls", value: false },
201+
category: "View",
206202
},
207203
{
208204
name: "navigationControlPosition",
@@ -307,6 +303,7 @@
307303
options: [
308304
"Carto-light",
309305
"Carto-dark",
306+
"https://raw.githubusercontent.com/fryford/imdmap/refs/heads/master/data/style.json",
310307
"https://raw.githubusercontent.com/ONSvisual/svelte-maps/refs/heads/main/dist/data/style-ons-light.json",
311308
{ version: 8, sources: {}, layers: [] },
312309
],

0 commit comments

Comments
 (0)