-
Notifications
You must be signed in to change notification settings - Fork 180
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
Map marker on selected result #219
Conversation
This bumps the bundle size up a nontrivial amount:
We should make sure we're comfortable with such an increase before merging. \cc @andrewharvey -- what are your thoughts on about the tradeoff here? |
Is that because it's now including the whole mapbox-gl in the geocoder bundle? If that's the case, I think we should try to find a way avoid that. |
To get around an explicit mapboxgl dependency, you could set mapbox gl as a peer dependency in package.json, and make the geocoder take mapboxgl as an argument on initialization. |
I haven't tested, so not what the current behaviour is, but if someone clears the geocoder, should the marker be removed? I'm think, yes it should be removed, but what do you think? |
I wonder should this work like the new flyTo option, where you can pass true, false, or an options object? Simplifying the two options into a single |
Thanks for the feedback @andrewharvey!
Good catch. I agree, and added this behavior in f454c4d.
I think this simplifies the API and, as you point out, makes the behavior more like the existing options. I added this behavior in e730470 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works beautifully! I left you two minor comments
package.json
Outdated
@@ -47,17 +47,19 @@ | |||
"insert-css": "2.0.0", | |||
"lint-staged": "^8.1.5", | |||
"lodash.once": "^4.0.0", | |||
"mapbox-gl": "^0.27.0", | |||
"mapbox-gl": "^0.53.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To confirm, do we want mapbox-gl as a devDep and peerDep? I'm not well versed on how peerDep work so just want to gut check in case this was in error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we want it to be both. During regular use, we want it as a peer dependency because we expect the plugin to be used in conjunction with a mapbox-gl map. However, during development we want it as a dev dependency so we can use it in tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is v0.53.0 the minimum requirement? I think if possible we should try to set this to the minimum version required for everything to work in gl-geocoder.
Not essential, just a nice to have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one more thing I noticed, any Marker automatically added here should also be removed from the map inside the onRemove method.
// clean up any old marker that might be present | ||
this._removeMarker(); | ||
var defaultMarkerOptions = { | ||
color: '#4668F2' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this feature was only added to mapbox-gl-js in v0.45.0, I think we should add a note to the changelog about the new minimum gl-js version requirement for mapbox-gl-geocoder v4, like was done for v2 https://github.com/mapbox/mapbox-gl-geocoder/blob/master/CHANGELOG.md#v200
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So smooth!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
this is working pretty well for me, but how do i get it to move an existing marker, that i'm using as a default before the user enters a location in the geocoder? can i pass the |
This PR handles #213 by adding a mapboxgl#Marker to the map after the user has selected a result. it exposes two additional constructor options:
addToMap
: a boolean field indicating whether the marker should be added. Optional, defaulttrue
.markerOptions
: an optional object specify the marker options to be passed to the marker constructor.Note: this requires a more recent version of mapbox-gl-js (v0.53.0) so there may be compatibility issues. Also, the existing tests need some massaging to get to work with the newer version of mapbox-gl.
master
heading before merging\cc @katydecorah @yuletide