A Leaflet plugin to add AfriGIS basemaps to your web map.
A TypeScript library for adding AfriGIS basemap layers to Leaflet maps. Supports multiple basemap types, attribution, and easy switching.
> ⚠️ Important:
> The LeafletAfrigisBasemaps instance will set the projection (CRS) of your Leaflet map to L.CRS.EPSG4326.
> Ensure your map and any custom layers are compatible with this projection.
``sh`
npm install @afrigis/leaflet-afrigis-basemaps
`typescript
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();
`
`javascript
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();
`
#### Constructor
`typescript`
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
Switches the basemap type and updates attribution.
- 'Vector''Hybrid'
- 'Imagery'
- 'Vector-black'
- 'Vector-grey'
- 'Hybrid-maxar'
- 'Hybrid-google'
- 'Imagery-maxar'
- 'Imagery-google'
- 'None'
-
- Leaflet v1.7+
- AfriGIS API key
`sh``
npm install
npm run dev
npm run test:unit
Open an issue in this repository or contact AfriGIS support.
MIT License
Developed by AfriGIS. Thanks to the Leaflet and open source community.