@afrigis/leaflet-afrigis-basemaps
v0.2.0
Published
A Leaflet plugin to add AfriGIS basemaps to your web map.
Readme
Leaflet AfriGIS Basemaps
A TypeScript library for adding AfriGIS basemap layers to Leaflet maps. Supports multiple basemap types, attribution, and easy switching.
⚠️ Important:
TheLeafletAfrigisBasemapsinstance will set the projection (CRS) of your Leaflet map toL.CRS.EPSG4326.
Ensure your map and any custom layers are compatible with this projection.
Features
- Add AfriGIS basemaps to Leaflet maps
- Supports types: Vector, Hybrid, Imagery, Vector-black, Vector-grey, Hybrid-maxar, Hybrid-google, Imagery-maxar, Imagery-google, None
- Attribution control integration
- Switch basemap types at runtime
- TypeScript types for basemap options
Installation
npm install @afrigis/leaflet-afrigis-basemapsUsage
ES Modules (TypeScript/Modern JavaScript)
import * as L from 'leaflet';
import { LeafletAfrigisBasemaps } from '@afrigis/leaflet-afrigis-basemaps';
import type { AfrigisBasemapType } from '@afrigis/leaflet-afrigis-basemaps';
const map = L
.map('map')
.setView([-25.746, 28.188], 10);
// Initialize with default basemap (Vector)
const basemap = new LeafletAfrigisBasemaps(map, 'YOUR_AFRIGIS_API_KEY');
// Switch basemap type
await basemap.switchTo('Hybrid'); // or any AfrigisBasemapType
// Get available basemap types
const types = basemap.getAvailableBaseMaps();CommonJS (Node.js)
const { LeafletAfrigisBasemaps } = require('@afrigis/leaflet-afrigis-basemaps');
const L = require('leaflet');
const map = L
.map('map')
.setView([-25.746, 28.188], 10);
// Initialize with default basemap (Vector)
const basemap = new LeafletAfrigisBasemaps(map, 'YOUR_AFRIGIS_API_KEY');
// Switch basemap type
await basemap.switchTo('Hybrid');
// Get available basemap types
const types = basemap.getAvailableBaseMaps();API
LeafletAfrigisBasemaps
Constructor
new LeafletAfrigisBasemaps(map: L.Map, authKey: string, defaultType?: AfrigisBasemapType)map: Leaflet map instanceauthKey: AfriGIS API keydefaultType: (optional) initial basemap type (default: 'Vector')
Methods
getAvailableBaseMaps(): AfrigisBasemapType[]
Returns all supported basemap types.getCurrentBasemapType(): AfrigisBasemapType
Returns the current basemap type.switchTo(type: AfrigisBasemapType): Promise<void>
Switches the basemap type and updates attribution.
Basemap Types
'Vector''Hybrid''Imagery''Vector-black''Vector-grey''Hybrid-maxar''Hybrid-google''Imagery-maxar''Imagery-google''None'
Requirements
- Leaflet v1.7+
- AfriGIS API key
Development
npm install
npm run dev
npm run test:unitSupport
Open an issue in this repository or contact AfriGIS support.
License
MIT License
Authors & Acknowledgments
Developed by AfriGIS. Thanks to the Leaflet and open source community.
