Skip to content

Commit 17d82b5

Browse files
committed
feat(plugins): expose external layer groups
1 parent 011bdaa commit 17d82b5

4 files changed

Lines changed: 24 additions & 0 deletions

File tree

apps/geolibre-desktop/src/hooks/usePlugins.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,9 @@ export function createAppAPI(mapControllerRef?: RefObject<MapController | null>)
835835
return state === undefined ? true : manager.applyPluginState(pluginId, api, state);
836836
},
837837
queryOvertureFeatures,
838+
addLayerGroup: (name?: string, layerIds?: string[]) =>
839+
useAppStore.getState().addLayerGroup(name, layerIds),
840+
removeLayerGroup: (id: string) => useAppStore.getState().removeLayerGroup(id),
838841
fitBounds: (bounds: [number, number, number, number]) =>
839842
mapControllerRef?.current?.fitBounds(bounds),
840843
getMap: () => mapControllerRef?.current?.getMap() ?? null,

apps/geolibre-desktop/src/lib/external-native-layer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,6 @@ export function createExternalNativeStoreLayer(
7676
beforeId: registration.beforeId ?? existing?.beforeId,
7777
geojson: registration.geojson ?? existing?.geojson,
7878
sourcePath: registration.sourcePath ?? existing?.sourcePath,
79+
groupId: registration.groupId ?? existing?.groupId,
7980
};
8081
}

packages/plugins/src/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export type GeoLibreBuiltInMapControl =
2626
export interface GeoLibreExternalNativeLayerRegistration {
2727
id: string;
2828
name: string;
29+
/** Optional host layer-group id that should contain this layer. */
30+
groupId?: string;
2931
type?: GeoLibreLayer["type"];
3032
source?: Record<string, unknown>;
3133
geojson?: FeatureCollection;
@@ -427,6 +429,13 @@ export interface GeoLibreAppAPI {
427429
* PMTiles integration. The host enforces tile and feature limits.
428430
*/
429431
queryOvertureFeatures?: (query: GeoLibreOvertureQuery) => Promise<GeoLibreOvertureQueryResult>;
432+
/**
433+
* Create a named Layers-panel group, optionally assigning existing layer ids
434+
* to it, and return the new group id.
435+
*/
436+
addLayerGroup?: (name?: string, layerIds?: string[]) => string;
437+
/** Remove a Layers-panel group without removing its child layers. */
438+
removeLayerGroup?: (id: string) => void;
430439
fitBounds?: (bounds: [number, number, number, number]) => void;
431440
getMap?: () => MapLibreMap | null;
432441
/**

tests/external-native-layer.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,15 @@ describe("createExternalNativeStoreLayer", () => {
159159

160160
assert.equal(layer.visible, false);
161161
});
162+
163+
it("assigns and preserves the requested host layer group", () => {
164+
const grouped = createExternalNativeStoreLayer(baseRegistration({ groupId: "event-imagery" }));
165+
assert.equal(grouped.groupId, "event-imagery");
166+
167+
const updated = createExternalNativeStoreLayer(
168+
baseRegistration({ name: "Updated Plugin Layer" }),
169+
grouped,
170+
);
171+
assert.equal(updated.groupId, "event-imagery");
172+
});
162173
});

0 commit comments

Comments
 (0)