Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed rendering layers Bubbles + Points #2612

Open
wants to merge 8 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rare-singers-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@evidence-dev/core-components': patch
---

fixed bubbles + points layering issue
5 changes: 5 additions & 0 deletions .changeset/soft-plums-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@evidence-dev/core-components': patch
---

Fixes layering issue and allows for layering control of bubbles and points
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,9 @@
<Points data={la_locations} lat="lat" long="long" color="red" />
</BaseMap>
</Story>
<Story name="Multiple Points">
<BaseMap title="My Map" height="300">
<Points data={la_locations} lat="lat" long="long" color="red" paneType="red Points" z="1" />
<Points data={la_locations} lat="lat" long="long" color="blue" paneType="blue Points" z="2" />
</BaseMap>
</Story>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { initSmoothZoom } from './LeafletSmoothZoom';
import { writable, derived, readonly } from 'svelte/store';
import chroma from 'chroma-js';
import { uiColours } from '@evidence-dev/component-utilities/colours';
import { toNumber } from '../../../utils.js';

/** @template T @typedef {import('svelte/store').Writable<T>} Writable<T> */
/** @template T @typedef {import('svelte/store').Readable<T>} Readable<T> */
Expand Down Expand Up @@ -264,7 +265,28 @@ export class EvidenceMap {
link
) {
if (!Leaflet) throw new Error('Leaflet is not yet available');
const marker = Leaflet.circleMarker(coords, circleOptions).addTo(this.#map);

//other panes start at z-index 400
if (!this.#map.getPane(circleOptions.pane)) {
this.#map.createPane(circleOptions.pane);
if (circleOptions.pane === 'bubbles' && circleOptions.z === undefined) {
this.#map.getPane('bubbles').style.zIndex = 400; // Lower zIndex for bubbles
} else if (circleOptions.pane === 'points' && circleOptions.z === undefined) {
this.#map.getPane('points').style.zIndex = 401; // Higher zIndex for points
} else if (circleOptions.z !== undefined) {
if (toNumber(circleOptions.z)) {
this.#map.getPane(circleOptions.pane).style.zIndex = 400 + toNumber(circleOptions.z);
} else {
this.#map.getPane(circleOptions.pane).style.zIndex = 400;
}
}
}

// Create the marker with the appropriate pane
const marker = Leaflet.circleMarker(coords, circleOptions);

marker.addTo(this.#map);

this.updateMarkerStyle(marker, circleOptions); // Initial style setting and storage

marker.on('click', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
export let size = undefined; // column containing size data
/** @type {number} */
export let opacity = 0.8;
/** @type {'bubble' | 'points' }*/
export let pointStyle = 'bubbles';
/** @type {'categorical' | 'scalar' | undefined} */
export let legendType = undefined;
</script>

<Points sizeCol={size} {opacity} {legendType} {...$$restProps} />
<Points sizeCol={size} {opacity} {pointStyle} {legendType} {...$$restProps} />
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@

let values, colorScale, sizeExtents, maxData, maxSizeSq;

/** @type {'bubble' | 'points' }*/
export let pointStyle = 'points';

/**
* Initialize the component.
* @returns {Promise<void>}
Expand Down Expand Up @@ -284,6 +287,12 @@
});
setInputDefault(item, name);
}

/** @type {'points' | 'bubbles' | 'string'}*/
export let paneType = pointStyle;

/** @type {number | undefined} */
export let z = undefined;
</script>

<!-- Additional data.fetch() included in await to trigger reactivity. Should ideally be handled in init() in the future. -->
Expand All @@ -300,7 +309,10 @@
opacity: opacity,
weight: borderWidth,
color: borderColor,
className: `outline-none ${pointClass}`
className: `outline-none ${pointClass}`,
markerType: pointStyle,
pane: paneType,
z: z
}}
selectedOptions={{
fillColor: selectedColor,
Expand Down
29 changes: 29 additions & 0 deletions sites/docs/pages/components/base-map.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,21 @@ options="column name"
Column containing the names/labels of the points - by default, this is shown as the title of the tooltip.
</PropListing>

<PropListing
name="paneType"
options="text"
>
Specifies the type of pane where the points will be rendered.
</PropListing>

<PropListing
name="z"
options="number"
>
Represents the z-index value for the pane, controlling its stacking order relative to other panes (higher values are on top, e.g., z=2 is above z=1).
</PropListing>


### Bubbles
Use the `<Bubbles/>` component to add an area layer

Expand Down Expand Up @@ -461,6 +476,20 @@ options="column name"
Column containing the names/labels of the points - by default, this is shown as the title of the tooltip.
</PropListing>

<PropListing
name="paneType"
options="text"
>
Specifies the type of pane where the bubbles will be rendered.
</PropListing>

<PropListing
name="z"
options="number"
>
Represents the z-index value for the pane, controlling its stacking order relative to other panes (higher values are on top, e.g., z=2 is above z=1).
</PropListing>

### Common Layer Options

#### Color Scale
Expand Down