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

Map marker on selected result #219

Merged
merged 15 commits into from
Mar 22, 2019
Merged

Map marker on selected result #219

merged 15 commits into from
Mar 22, 2019

Conversation

scottsfarley93
Copy link

@scottsfarley93 scottsfarley93 commented Mar 19, 2019

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, default true.
  • 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.

  • briefly describe the changes in this PR
  • write tests for all new functionality
  • update CHANGELOG.md with changes under master heading before merging
  • Make sure tests work with more recent mapbox-gl-js version

\cc @katydecorah @yuletide

@scottsfarley93 scottsfarley93 added this to the v4.0.0 milestone Mar 19, 2019
@scottsfarley93 scottsfarley93 changed the title [WIP] Map marker on selected result Map marker on selected result Mar 19, 2019
@scottsfarley93
Copy link
Author

This bumps the bundle size up a nontrivial amount:

5194 mapbox-gl-geocoder.css
711473 mapbox-gl-geocoder.min.js

We should make sure we're comfortable with such an increase before merging.

\cc @andrewharvey -- what are your thoughts on about the tradeoff here?

@andrewharvey
Copy link
Collaborator

This bumps the bundle size up a nontrivial amount:

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.

@samanpwbb
Copy link
Contributor

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.

API.md Outdated Show resolved Hide resolved
API.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@andrewharvey
Copy link
Collaborator

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?

@andrewharvey
Copy link
Collaborator

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 marker option which can be true, false or an options object?

@scottsfarley93
Copy link
Author

scottsfarley93 commented Mar 20, 2019

Thanks for the feedback @andrewharvey!

if someone clears the geocoder, should the marker be removed?

Good catch. I agree, and added this behavior in f454c4d.

Simplifying the two options into a single marker option which can be true, false or an options object

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

Copy link
Contributor

@katydecorah katydecorah left a 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

lib/index.js Outdated Show resolved Hide resolved
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",
Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Collaborator

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.

@scottsfarley93 scottsfarley93 mentioned this pull request Mar 20, 2019
4 tasks
lib/index.js Outdated Show resolved Hide resolved
Copy link
Collaborator

@andrewharvey andrewharvey left a 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.

lib/index.js Outdated Show resolved Hide resolved
// clean up any old marker that might be present
this._removeMarker();
var defaultMarkerOptions = {
color: '#4668F2'
Copy link
Collaborator

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

Copy link
Contributor

@katydecorah katydecorah left a comment

Choose a reason for hiding this comment

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

So smooth!

Copy link
Collaborator

@andrewharvey andrewharvey left a comment

Choose a reason for hiding this comment

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

👍

@scottsfarley93 scottsfarley93 merged commit 41dc4f9 into version4 Mar 22, 2019
@scottsfarley93 scottsfarley93 deleted the map-marker branch March 22, 2019 22:51
@jayenashar
Copy link

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 marker option an existing marker?

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.

5 participants