phegman / vue-mapbox-gl

A Vue.js component for Mapbox GL JS
GNU General Public License v3.0
270 stars 33 forks source link

Is there a way to trigger() geolocation programmatically? #74

Closed gathrlabs closed 4 years ago

gathrlabs commented 4 years ago

Thanks for your work on this package.

https://github.com/mapbox/mapbox-gl-js/issues/5464#issuecomment-426890317

How would I go about getting access to geoLocateControl and then using the trigger function which is apparently available?

https://docs.mapbox.com/mapbox-gl-js/api/#geolocatecontrol#trigger

Many thanks!

gathrlabs commented 4 years ago

Never-mind, I worked it out.

You can just:

const geolocate = new mapboxgl.GeolocateControl(); map.addControl(geolocate, this.geolocateControl.position);

Make sure the controls have been loaded and then simply call: geolocate.trigger();

Do that instead of adding as a prop to mapbox, ensuring that you have configured this.geolocateControl with all of the required options.