react-esri-leaflet
quickly and easily bring esri-leaflet components into your react-leaflet application
👀 Demo 👀
Requirements
Requires react^18, react-leaflet^4, and esri-leaflet^3.
Installation
To use these components you must install certain dependencies yourself:
npm i react react-dom leaflet react-leaflet esri-leaflet
with all of your underlying packages installed,
npm i react-esri-leaflet
Components
react-esri-leaflet offers the following components:
Native Components:
- <BasemapLayer />
- <FeatureLayer />
- <TiledMapLayer />
- <ImageMapLayer />
- <DynamicMapLayer />
Plugins:
- <EsriLeafletGeoSearch />
- <HeatmapLayer />
- <ClusterLayer />
- <VectorBasemapLayer />
- <VectorTileLayer />
Use
Import any of the components and use them in a <MapContainer />
:
import React from "react";
import { MapContainer } from "react-leaflet";
import { BasemapLayer, FeatureLayer } from "react-esri-leaflet";
import EsriLeafletGeoSearch from "react-esri-leaflet/plugins/GeoSearch";
const Map = () => {
return (
<MapContainer zoom={zoom} center={center}>
<BasemapLayer name="DarkGray" />
<FeatureLayer url={featureLayerURL} />
<EsriLeafletGeoSearch useMapBounds={false} position="topright" />
</MapContainer>
);
};
Using esri-leaflet Plugins
If you want to use any of the esri-leaflet plugins, you must first install their underlying packages and any associated css. Each plugin has its own requirements, which you can find in the esri-leaflet docs. Plugins are imported not from the main package, but from the /plugins/<PluginName>
subfolder, like this:
import EsriLeafletGeoSearch from "react-esri-leaflet/plugins/EsriLeafletGeoSearch";
EsriLeafletGeoSearch
You must first install the underlying esri-leaflet-geocoder
:
npm i esri-leaflet-geocoder
You will also need to include the css in your html header, as explained in the esri-leaflet-geocoder documentation. You can then use the <EsriLeafletGeoSearch />
component. See the Use section for examples.
HeatmapLayer
First install the underlying dependencies:
npm i leaflet.heat esri-leaflet-heatmap
You can then use the <HeatmapLayer />
component.
ClusterLayer
First install the underlying dependencies:
npm i leaflet.markercluster esri-leaflet-cluster
You can then use the <ClusterLayer />
component.
VectorBasemapLayer and VectorTileLayer
First install the underlying dependencies:
npm i esri-leaflet-vector
You can then use the <VectorBasemapLayer />
and <VectorTileLater />
components.
Props
All react-esri-leaflet components inherit their props from the underlying esri-leaflet component options. You can find the options for each esri-leaflet layer in their documentation. However, certain options are available or necessary for react-esri-leaflet components:
component | prop | type | description | required |
BasemapLayer | name | string | one of the esri accepted baselayer names | yes |
VectorBasemapLayer | name | string | one of the esri accepted vector basemap names | yes |
VectorTileLayer | url | string | the url of the vector tile layer service | yes |
EsriLeafletGeoSearch | onResult | function(results) | fires when geosearch returns results, takes the results event as an argument | no |
EsriLeafletGeoSearch | providers | object | An object defining the providers to be used for the geosearch component. The object keys are the names of one of the possible providers, and the values are objects containing the options to configure that provider. See below for an example. | yes |
<EsriLeafletGeoSearch
providers={{
arcgisOnlineProvider: {
token: your_token,
label: "ArcGIS Online Results",
maxResults: 10
},
featureLayerProvider: {
url: feature_layer_url,
label: 'Featurelayer Provider Results'
bufferRadius: 5000
}
}}
/>; |