Leaflet Maps
@adminjs/leaflet
The Leaflet feature (@adminjs/leaflet) integrates Leaflet (https://leafletjs.com/) into AdminJS allowing you to visualize your maps and markers.
Installation
$ yarn add @adminjs/leaflet # or: npm install @adminjs/leafletUsage
@adminjs/leaflet package exports two features that you should use based on your use case.
leafletSingleMarkerMapFeatureshould be used when your resource is theMarkeritself, and you only want to display a single marker on the rendered map. This should be used when, for example, you'd like to change a specific marker's location without displaying all your markers on a map.

leafletMultipleMarkersMapFeatureshould be used when your resource is a collection ofMarkers. An example could be aMapresource withMarkerbeing a separate resource. This feature will allow you to manage all associated markers.
leafletMultipleMarkersMapFeature will not display the map when creating a new Map record due to dynamic management of markers. Whenever you drag, edit, create or delete a Marker, the change takes effect immediately which relies on your Map to had been created before. If you want to manage your Map markers, create the Map first and you can manage them via edit action.

The usage tutorial will be split into two sections related to the feature you're using but there are some common steps you must take to get the features working.
First of all, you have to import getLeafletDist from @adminjs/leaflet. Leaflet library has it's own CSS which is required for the maps to display properly but AdminJS core does not let you import CSS files directly into React components (as of version 6). As a workaround, @adminjs/leaflet exports getLeafletDist utility function which resolves a path to Leaflet dist files in your node_modules. These dist files have to be exposed by your server framework. The example below shows how you can do it with express.
Alternatively, you can provide a CDN link to leaflet.css in styles.
In the example above, we also instantiated a ComponentLoader. Take note of that, as it will be used by Leaflet features later.
leafletSingleMarkerMapFeature
The AdminJS configuration described above should be extended with your Marker resource.
The feature goes inside features in your resource specification. Take a look at the example below which includes comments on how you can configure the feature.
leafletMultipleMarkersMapFeature
The AdminJS configuration described above should be extended with your MapEntity resource.
The feature goes inside features in your resource specification. Take a look at the example below which includes comments on how you can configure the feature.
Example
An example application can be found in @adminjs/leaflet GitHub repository.
Installation
Issues & Ideas
@adminjs/leaflet is still in its early development phase. If you have any ideas on how to improve it, add new features or if you find any bugs, please create an issue in its GitHub repository.
Last updated