Skip to content

Commit

Permalink
add esri-leaflet-geocoder
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinr-maps committed Aug 27, 2024
1 parent 707884a commit b4b78a4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"dependencies": {
"@types/leaflet": "^1.9.12",
"esri-leaflet": "^3.0.12",
"esri-leaflet-geocoder": "^3.1.4",
"esri-leaflet-vector": "^4.2.5",
"leaflet": "^1.9.4",
"react": "^18.3.1",
Expand Down
12 changes: 12 additions & 0 deletions src/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { useEffect, useRef } from "react";
import { Map as LeafletMap, Icon, Marker } from "leaflet";
import { FeatureLayer } from "esri-leaflet";
import { vectorBasemapLayer } from "esri-leaflet-vector";
import { geosearch, arcgisOnlineProvider } from "esri-leaflet-geocoder";
import "leaflet/dist/leaflet.css";
import "esri-leaflet-geocoder/dist/esri-leaflet-geocoder.css";

import icon from "leaflet/dist/images/marker-icon.png";
import iconShadow from "leaflet/dist/images/marker-shadow.png";
Expand Down Expand Up @@ -46,6 +48,16 @@ function Map() {
return `<p><strong>${layer.feature.properties.CITY_NAME
}</strong><br /> Population: ${layer.feature.properties.POP.toLocaleString("en")}</p>`;
});

// add the geocoder
geosearch({
providers: [
arcgisOnlineProvider({
// API Key to be passed to the ArcGIS Online Geocoding Service
apikey: import.meta.env.VITE_ARCGIS_API_KEY, // https://developers.arcgis.com
})
]
}).addTo(map);
}

return () => {
Expand Down

0 comments on commit b4b78a4

Please sign in to comment.