Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation to include examples of ES6-style imports (import * as .... from 'esri-leaflet-geocoder') #293

Open
TannerJuby1 opened this issue Apr 5, 2022 · 8 comments

Comments

@TannerJuby1
Copy link

I installed this project via npm as well as it's types for my Gatsby (react) project, but I am unable to use it thru the leaflet package as the documentation suggests.

I ran npm i esri-leaflet-geocoder --save and npm i @types/esri-leaflet-geocoder --save which installed properly, but when I go to use the geocode like the documentation suggests:

L.esri.Geocoder.reverseGeocode(...

I get a runtime error that Geocoder is undefined.

I can get around this by importing the package directly:

import * as ELG from 'esri-leaflet-geocoder'

ELG.reverseGeocode(....

However, when I do it this way. I run into issues with the api key that I've opened another issue about

@gavinr
Copy link
Contributor

gavinr commented Apr 5, 2022

Hi, I think that import style is correct when using ES6 import style.

@TannerJuby1
Copy link
Author

Import style works, but the way the documentation shows to use it does not.

@gavinr
Copy link
Contributor

gavinr commented Apr 6, 2022

Hi, thanks for the feedback. Which documentation are you referring to?

@TannerJuby1
Copy link
Author

TannerJuby1 commented Apr 7, 2022

Under the API Reference section of this repo's README, it shows to use L.esri.Geocoding. indicating it extends the L import of Leaflet, but it does not. You have to import it and use it separately

@gavinr
Copy link
Contributor

gavinr commented Apr 7, 2022

Thanks...

  1. if you import using the script tag (for example, <script src="https://unpkg.com/esri-leaflet-geocoder"></script>), then you access via L.esri.Geocoding....
  2. if you import using the newer import * as .... from 'esri-leaflet-geocoder' then you'd refer to it directly using the imported name.

Either are valid, but the documentation focuses on number 1 since that is the pattern that most Leaflet users are following. I think your confusion is that number 2 is not really mentioned in the documentation, and that's a fair critique, as more people start to use the import... style. I'll rename this issue so that we can tackle that documentation update. PRs welcome!

@gavinr gavinr changed the title npm packages (typescript) do not properly extend Leaflet Update documentation to include examples of ES6-style imports (import * as .... from 'esri-leaflet-geocoder') Apr 7, 2022
@gavinr-maps
Copy link
Contributor

gavinr-maps commented Aug 20, 2024

Note that before we document using this library with ESM, we'll need to get the other Esri Leaflet libraries working with ESM here: Esri/esri-leaflet#1386

So if anyone has time to look into that one ^ it would be much appreciated.

@shakyad

This comment was marked as off-topic.

@gavinr-maps

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants