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

Fix geocoder to new 3.x API #151

Merged
merged 1 commit into from
Jan 15, 2025
Merged

Conversation

SevereOverfl0w
Copy link
Contributor

As index.html is using the latest version of leaflet-control-geocoder and the API changed in 3.0.0 with this example:

Migrate from callbacks to Promise

-geocoder.geocode(query, callback);
+geocoder.geocode(query).then(callback);

-geocoder.reverse(latlng, scale, callback);
+geocoder.reverse(latlng, scale).then(callback);

Migrate from callbacks to async-await

-geocoder.geocode(query, callback);
+const results = await geocoder.geocode(query);

-geocoder.reverse(latlng, scale, callback);
+const results = await geocoder.reverse(latlng, scale);

The usage in the map widget also needs updating to correspond.

As index.html is using the latest version of leaflet-control-geocoder
and the API changed in 3.0.0 with this example:

```
Migrate from callbacks to Promise

-geocoder.geocode(query, callback);
+geocoder.geocode(query).then(callback);

-geocoder.reverse(latlng, scale, callback);
+geocoder.reverse(latlng, scale).then(callback);

Migrate from callbacks to async-await

-geocoder.geocode(query, callback);
+const results = await geocoder.geocode(query);

-geocoder.reverse(latlng, scale, callback);
+const results = await geocoder.reverse(latlng, scale);
```

The usage in the map widget also needs updating to correspond.
Copy link

netlify bot commented Jan 12, 2025

Deploy Preview for boisterous-sunburst-a5c941 ready!

Name Link
🔨 Latest commit 189853d
🔍 Latest deploy log https://app.netlify.com/sites/boisterous-sunburst-a5c941/deploys/6783d90a9227bb00083f03dd
😎 Deploy Preview https://deploy-preview-151--boisterous-sunburst-a5c941.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

reject(e);
}
});
const results = await geocoder.geocode(address);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks reasonable, but it seems like the original try-catch should be kept. Why is it no longer needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dropped it because it should just bubble out now due to using await, rather than needing explicit handling to conform it to the promise. But I can reinstate it with the logging out of caution, no problem.

Copy link
Member

@paulfitz paulfitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @SevereOverfl0w ! Dropping the try/catch seems fine.

@paulfitz paulfitz merged commit fec8ade into gristlabs:master Jan 15, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants