GeoLibre Plugin API
Interface
import type { FeatureCollection } from "geojson";
import type { IControl } from "maplibre-gl";
export type GeoLibreMapControlPosition =
| "top-left"
| "top-right"
| "bottom-left"
| "bottom-right";
export type GeoLibreBuiltInMapControl =
| "navigation"
| "fullscreen"
| "geolocate"
| "globe"
| "terrain"
| "scale"
| "attribution"
| "logo"
| "layer-control";
export interface GeoLibrePlugin {
id: string;
name: string;
version: string;
activeByDefault?: boolean;
activate: (app: GeoLibreAppAPI) => boolean | void;
deactivate: (app: GeoLibreAppAPI) => void;
getMapControlPosition?: () => GeoLibreMapControlPosition;
setMapControlPosition?: (
app: GeoLibreAppAPI,
position: GeoLibreMapControlPosition,
) => boolean | void;
}
export interface GeoLibreAppAPI {
setBasemap: (styleUrl: string) => void;
addGeoJsonLayer: (
name: string,
data: FeatureCollection,
sourcePath?: string,
) => void;
getActiveBasemap: () => string;
onBasemapChange: (callback: (styleUrl: string) => void) => () => void;
addMapControl: (
control: IControl,
position?: GeoLibreMapControlPosition,
) => boolean;
removeMapControl: (control: IControl) => void;
setBuiltInMapControlVisible: (
control: GeoLibreBuiltInMapControl,
visible: boolean,
) => boolean;
getBuiltInMapControlPosition: (
control: GeoLibreBuiltInMapControl,
) => GeoLibreMapControlPosition;
setBuiltInMapControlPosition: (
control: GeoLibreBuiltInMapControl,
position: GeoLibreMapControlPosition,
) => boolean;
}
Register a plugin
import { PluginManager } from "@geolibre/plugins";
const manager = new PluginManager();
manager.register(myPlugin);
manager.activate("my-plugin", appApi);
Built-in plugins
| ID |
Description |
osm-basemap |
OpenFreeMap Liberty style |
carto-light |
CARTO Positron GL style |
sample-geojson |
Loads sample-data/sample.geojson |
maplibre-gl-basemap-control |
Adds a MapLibre basemap picker |
maplibre-gl-geo-editor |
Adds GeoEditor drawing controls |
maplibre-gl-geoagent |
Adds GeoAgent map assistant controls |
maplibre-gl-lidar |
Adds lidar controls |
maplibre-gl-streetview |
Adds street view controls |
maplibre-gl-swipe |
Adds map swipe controls |
Example plugin
import type { GeoLibreAppAPI, GeoLibrePlugin } from "@geolibre/plugins";
export const myPlugin: GeoLibrePlugin = {
id: "my-plugin",
name: "My Plugin",
version: "0.1.0",
activate(app: GeoLibreAppAPI) {
app.setBasemap("https://example.com/style.json");
},
deactivate() {
// Clean up controls, listeners, and plugin state here.
},
};
Roadmap (v0.6)
- Dynamic plugin loading from
plugins/ directory
- Plugin manifest (
plugin.json)
- Sandboxed worker plugins