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

How do you access Geolocation (or similar) events? #39

Closed
toadkicker opened this issue May 14, 2018 · 6 comments
Closed

How do you access Geolocation (or similar) events? #39

toadkicker opened this issue May 14, 2018 · 6 comments

Comments

@toadkicker
Copy link

It's not clear how one would access the geolocation control's events through Vue. (https://www.mapbox.com/mapbox-gl-js/api/#geolocatecontrol.event:geolocate) I thought it would be as simple as doing @map-geolocate, @map-trackuserlocationend but neither bubbled up.

@toadkicker
Copy link
Author

Also tried:

const geo = this.map.addControl(new mapboxgl.GeolocateControl({ show: true, position: 'top-left', positionOptions: { enableHighAccuracy: true }}));
geo.on('geolocate', this.setAddress);

@LKajan
Copy link
Contributor

LKajan commented May 14, 2018

Control events are not currently implemented yet. There is a pull request #38 for that though.

@toadkicker
Copy link
Author

Ok great I will pull that branch and try it out

@phegman
Copy link
Owner

phegman commented May 14, 2018

Thanks to @LKajan control events have now been implemented. If you pull down the latest NPM package you should be able to use them. Documentation has also been updated to explain how.

@phegman phegman closed this as completed May 14, 2018
@toadkicker
Copy link
Author

toadkicker commented May 18, 2018

I upgraded but it doesn't look like it is working properly. Looking at the pull request, it doesn't look like $emit is implemented correctly. According to the docs the second argument is a callback. In PR #38 it is passing this.$emit('geolocate-geolocate', geolocate, position). Instead we would want to probably pass this.$emit('geolocate-geolocate', {event: geolocate, position: position}) so that position isn't dropped from the callback. Maybe I'm just not that familiar with $emit, so if there is something I am missing here please let me know.

Also in this example the final event is called result, but clearly that isn't documented in the control.

@phegman
Copy link
Owner

phegman commented May 18, 2018

Hi Todd,

It looks like the example you sent is referring to the Geocoder control which is actually not built into the main Mapbox library so is not implemented in this Vue component. The Geolocation events are working for me. The Vue $emit event uses the Rest Parameter to allow you to define additional arguments that are passed into the listener’s callback function. This allows you to do this.$emit('geolocate-geolocate', geolocate, position). If you take a look at app.js and index.html you can see an example of how the Geolocation control works. If you want to use the Geocoder control you can listen for the result event in the Mapbox load event.

Hope that is helpful!
Pete

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

No branches or pull requests

3 participants