Skip to content

Commit c58196c

Browse files
committed
Added Custom colours, Bounds and zoom functions
1 parent 38d6f5c commit c58196c

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import type { LngLatBoundsLike } from "maplibre-gl";
3535
let {
3636
data,
37+
customPallet,
3738
cooperativeGestures = true,
3839
standardControls = true,
3940
navigationControl,
@@ -70,8 +71,10 @@
7071
},
7172
useInitialHash = true,
7273
mapHeight = 200,
74+
setMaxBounds,
7375
}: {
7476
data: object[];
77+
customPallet: object[] | undefined;
7578
cooperativeGestures?: boolean;
7679
standardControls?: boolean;
7780
navigationControl?: boolean;
@@ -99,9 +102,10 @@
99102
hoverOpacity?: number;
100103
center?: LngLatLike | undefined;
101104
zoom?: number;
102-
minZoom?: number;
103-
maxZoom?: number;
104-
maxBounds: [number, number][];
105+
minZoom?: number | undefined;
106+
maxZoom?: number | undefined;
107+
maxBounds?: [number, number][];
108+
setMaxBounds?: boolean;
105109
hash?: boolean;
106110
updateHash?: (URL) => void;
107111
useInitialHash?: boolean;
@@ -133,7 +137,9 @@
133137
let filteredGeoJsonData = $derived(filterGeo(geojsonData, year));
134138
135139
let fillColors: string[] = $derived(
136-
colorbrewer[colorPalette][numberOfBreaks],
140+
customPallet !== undefined
141+
? customPallet
142+
: colorbrewer[colorPalette][numberOfBreaks],
137143
);
138144
139145
let borderColor = "#003300";
@@ -224,7 +230,9 @@
224230
return bounds;
225231
}
226232
227-
let boundary = convertToLngLatBounds(maxBounds);
233+
if (setMaxBounds) {
234+
let boundary = convertToLngLatBounds(maxBounds);
235+
}
228236
function zoomToArea(e) {
229237
if (clickToZoom) {
230238
let coordArray =
@@ -276,7 +284,7 @@
276284
{zoom}
277285
{maxZoom}
278286
{minZoom}
279-
maxBounds={boundary}
287+
{...setMaxBounds ? { maxBounds: boundary } : {}}
280288
{hash}
281289
{updateHash}
282290
class="map"

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,17 @@
346346
"Set1",
347347
"Set2",
348348
"Set3",
349+
"custom",
349350
],
350351
value: "YlGnBu",
351352
category: "Styling",
352353
},
354+
{
355+
name: "customPallet",
356+
isProp: true,
357+
category: "Styling",
358+
value: [[]],
359+
},
353360
{
354361
name: "showBorder",
355362
isProp: true,
@@ -501,6 +508,9 @@
501508
value: [-2.5, 53],
502509
description: "The initial centre of the map, in [lng, lat] form",
503510
},
511+
512+
{ name: "setMaxBounds", isProp: true, value: false, category: "View" },
513+
504514
{
505515
name: "maxBounds",
506516
isProp: true,
@@ -509,7 +519,8 @@
509519
[-23.899, 47.5943],
510520
[13.421, 59.8988],
511521
],
512-
description: "The initial centre of the map, in [lng, lat] form",
522+
visible: { name: "setMaxBounds", value: true },
523+
description: "Set the max bounds of the map",
513524
},
514525
{
515526
name: "zoom",

0 commit comments

Comments
 (0)