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 MaplibreGeocoderPlaceResults type definition #163

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tomhuze
Copy link

@tomhuze tomhuze commented Sep 25, 2024

Fix MaplibreGeocoderPlaceResults type definition and update documentation in code to reflect expected return of searchByPlaceId function. Fixes #162

  • briefly describe the changes in this PR

MaplibreGeocoderPlaceResults should return a single place feature.
Moved GeoAPI example of getSuggestions and getPlaceById from 'getItemValue' attribute documentation to geocoder's addTo documentation with other GeoAPI functions.
@@ -166,16 +166,6 @@ export type MaplibreGeocoderOptions = {
proximityMinZoom?: number;
/**
* A function that specifies how the selected result should be rendered in the search bar. HTML tags in the output string will not be rendered. Defaults to `(item) => item.place_name`.
* @example
Copy link
Collaborator

Choose a reason for hiding this comment

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

This was probably incorrectly placed here, I would suggest to move it above the maplibregeocoder class, where there is a short comment.

Copy link
Author

Choose a reason for hiding this comment

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

I think it makes sense to leave this removed, and perhaps there is no need to show getSuggestions and getPlaceById in examples as they are well defined in the types?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Type definition and examples are different things... I would prefer to have even more than one example to indicate how to use something. Type definition are important but less helpful in my experience...

lib/index.ts Outdated
@@ -237,7 +227,7 @@ export type MaplibreGeocoderApiConfig = {

export type MaplibreGeocoderFeatureResults = { type: "FeatureCollection", features: CarmenGeojsonFeature[]};
export type MaplibreGeocoderSuggestionResults = { suggestions: { text: string, placeId?: string }[] };
export type MaplibreGeocoderPlaceResults = { place: CarmenGeojsonFeature[] };
export type MaplibreGeocoderPlaceResults = { place: CarmenGeojsonFeature };
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this improve the types in the code to avoid "as any" somewhere? Why doesn't this solve or break anything?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I see that this broke the MaplibreGeocoderResults used by _handleGeocodeResponse which is expecting all of the geocoder function results to return arrays either directly or as the value of a property of the returned object.
I've reverted that and fixed the original issue by removing the array that was wrapped around getPlacebyId's place array on line . The extra array caused _handleGeocodeResponse to throw an error and the map to never zoom on the selected place.

lib/index.ts Outdated
@@ -384,6 +375,8 @@ export default class MaplibreGeocoder {
* const GeoApi = {
* forwardGeocode: (config) => { return { features: [] } },
* reverseGeocode: (config) => { return { features: [] } }
* getSuggestions: (config) => { return { suggestions: {text: string, placeId?: string}[] }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

The example here is an "actual" example, there should be something like place: "my-place",... I think.

Copy link
Author

Choose a reason for hiding this comment

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

I removed this as I think including these optional functions does not help the goal of showing how to attach the geocoder to a container element.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would recommend adding a "simple" example and "complicated" example.

@HarelM
Copy link
Collaborator

HarelM commented Sep 25, 2024

Thanks for taking the time to solve this issue!!
I've added a few minor comments.

@HarelM
Copy link
Collaborator

HarelM commented Oct 15, 2024

Any updates on this?

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.

Conforming searchByPlaceId to return type MaplibreGeocoderPlaceResults causes error
2 participants