|
36 | 36 | data,
|
37 | 37 | customPallet,
|
38 | 38 | setCustomPallet,
|
| 39 | + interactive, |
39 | 40 | cooperativeGestures = true,
|
40 | 41 | standardControls = true,
|
41 | 42 | navigationControl,
|
|
114 | 115 | mapHeight?: number;
|
115 | 116 | setCustomPallet?: boolean;
|
116 | 117 | customBreaks?: number[];
|
117 |
| - interative: boolean; |
| 118 | + interactive: boolean; |
118 | 119 | } = $props();
|
119 | 120 |
|
120 | 121 | let styleLookup = {
|
|
125 | 126 | };
|
126 | 127 | let style = $derived(styleLookup[styleSheet] ?? styleSheet);
|
127 | 128 |
|
128 |
| - $inspect(customBreaks); |
129 |
| -
|
130 | 129 | let breakCount = $derived(
|
131 | 130 | breaksType == "custom" ? customBreaks.length : numberOfBreaks,
|
132 | 131 | );
|
133 |
| - $inspect(breakCount); |
134 | 132 |
|
135 | 133 | let mapData = $derived(data?.filter((d) => d["year"] == year)[0]?.data);
|
136 | 134 |
|
|
230 | 228 |
|
231 | 229 | let merged = $derived(joinData(filteredGeoJsonData, dataWithColor));
|
232 | 230 |
|
233 |
| - $inspect(merged); |
234 |
| -
|
235 | 231 | let hoveredArea = $state();
|
236 | 232 | let hoveredAreaData = $state();
|
237 | 233 | let currentMousePosition = $state();
|
|
289 | 285 | let bounds = $derived(
|
290 | 286 | setMaxBounds ? convertToLngLatBounds(maxBoundsCoords) : undefined,
|
291 | 287 | );
|
292 |
| -
|
293 |
| - // let displayBounds = $derived(bounds.map((b) => b.toFixed(4)).join(", ")); |
294 |
| - // $inspect(displayBounds); |
295 | 288 | </script>
|
296 | 289 |
|
297 | 290 | <div style="height: {mapHeight}px;">
|
|
303 | 296 | {zoom}
|
304 | 297 | {maxZoom}
|
305 | 298 | {minZoom}
|
306 |
| - {standardControls} |
| 299 | + standardControls={interactive && standardControls} |
307 | 300 | {hash}
|
308 | 301 | {updateHash}
|
| 302 | + {interactive} |
309 | 303 | class="map"
|
310 | 304 | >
|
311 |
| - {#if !standardControls} |
| 305 | + {#if interactive && !standardControls} |
312 | 306 | <NonStandardControls
|
313 | 307 | {navigationControl}
|
314 | 308 | {navigationControlPosition}
|
|
329 | 323 | center: center,
|
330 | 324 | zoom: zoom,
|
331 | 325 | });
|
332 |
| - }}>Reset view</button |
333 |
| - ></ControlGroup |
334 |
| - > |
| 326 | + }} |
| 327 | + > |
| 328 | + Reset view |
| 329 | + </button> |
| 330 | + </ControlGroup> |
335 | 331 | </Control>
|
336 | 332 | {/if}
|
337 | 333 |
|
338 | 334 | <GeoJSON id="areas" data={merged} promoteId="areanm">
|
339 | 335 | <FillLayer
|
340 | 336 | paint={{
|
341 |
| - //Get the color property of the area, or lightgrey if that's undefined |
342 | 337 | "fill-color": ["coalesce", ["get", "color"], "lightgrey"],
|
343 | 338 | "fill-opacity": changeOpacityOnHover
|
344 |
| - ? hoverStateFilter(fillOpacity, hoverOpacity) //setting the fill-opacity based on whether the area is hovered |
| 339 | + ? hoverStateFilter(fillOpacity, hoverOpacity) |
345 | 340 | : fillOpacity,
|
346 | 341 | }}
|
347 | 342 | beforeLayerType="symbol"
|
348 |
| - manageHoverState |
349 |
| - onclick={(e) => zoomToArea(e)} |
350 |
| - onmousemove={(e) => { |
351 |
| - hoveredArea = e.features[0].id; |
352 |
| - hoveredAreaData = e.features[0].properties.metric; |
353 |
| - currentMousePosition = e.event.point; |
354 |
| - }} |
355 |
| - onmouseleave={(e) => { |
356 |
| - (hoveredArea = null), (hoveredAreaData = null); |
357 |
| - }} |
| 343 | + manageHoverState={interactive} |
| 344 | + onclick={interactive ? (e) => zoomToArea(e) : null} |
| 345 | + onmousemove={interactive |
| 346 | + ? (e) => { |
| 347 | + hoveredArea = e.features[0].id; |
| 348 | + hoveredAreaData = e.features[0].properties.metric; |
| 349 | + currentMousePosition = e.event.point; |
| 350 | + } |
| 351 | + : null} |
| 352 | + onmouseleave={interactive |
| 353 | + ? () => { |
| 354 | + hoveredArea = null; |
| 355 | + hoveredAreaData = null; |
| 356 | + } |
| 357 | + : null} |
358 | 358 | />
|
359 | 359 | {#if showBorder}
|
360 | 360 | <LineLayer
|
361 | 361 | layout={{ "line-cap": "round", "line-join": "round" }}
|
362 | 362 | paint={{
|
363 |
| - "line-color": hoverStateFilter(borderColor, "orange"), //setting the colour based on whether the area is hovered |
364 |
| - "line-width": zoomTransition(3, 0, 12, maxBorderWidth), //setting the line-width based on the zoom level |
| 363 | + "line-color": hoverStateFilter(borderColor, "orange"), |
| 364 | + "line-width": zoomTransition(3, 0, 12, maxBorderWidth), |
365 | 365 | }}
|
366 | 366 | beforeLayerType="symbol"
|
367 | 367 | />
|
368 | 368 | {/if}
|
369 | 369 | </GeoJSON>
|
370 |
| - {#if tooltip} |
| 370 | + |
| 371 | + {#if interactive && tooltip} |
371 | 372 | <Tooltip
|
372 | 373 | {currentMousePosition}
|
373 | 374 | {hoveredArea}
|
|
0 commit comments