Skip to content

Commit d46cad3

Browse files
author
Peter Hegman
committed
cleaning up documentation a bit
1 parent b027e2f commit d46cad3

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

dist/Mapbox.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,8 @@ exports.default = {
397397
});
398398
},
399399
addControls: function addControls(map) {
400+
var _this2 = this;
401+
400402
//Nav Control
401403
if (this.navControl.show) {
402404
var nav = new mapboxgl.NavigationControl();
@@ -407,6 +409,22 @@ exports.default = {
407409
if (this.geolocateControl.show) {
408410
var geolocate = new mapboxgl.GeolocateControl(this.geolocateControl.options);
409411
map.addControl(geolocate, this.geolocateControl.position);
412+
413+
geolocate.on('geolocate', function (position) {
414+
_this2.$emit('geolocate-geolocate', geolocate, position);
415+
});
416+
417+
geolocate.on('trackuserlocationstart', function () {
418+
_this2.$emit('geolocate-trackuserlocationstart', geolocate);
419+
});
420+
421+
geolocate.on('trackuserlocationend', function () {
422+
_this2.$emit('geolocate-trackuserlocationend', geolocate);
423+
});
424+
425+
geolocate.on('error', function (positionError) {
426+
_this2.$emit('geolocate-error', geolocate, positionError);
427+
});
410428
}
411429

412430
//Scale Control

dist/app.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,8 @@ exports.default = {
440440
});
441441
},
442442
addControls: function addControls(map) {
443+
var _this2 = this;
444+
443445
//Nav Control
444446
if (this.navControl.show) {
445447
var nav = new mapboxgl.NavigationControl();
@@ -450,6 +452,22 @@ exports.default = {
450452
if (this.geolocateControl.show) {
451453
var geolocate = new mapboxgl.GeolocateControl(this.geolocateControl.options);
452454
map.addControl(geolocate, this.geolocateControl.position);
455+
456+
geolocate.on('geolocate', function (position) {
457+
_this2.$emit('geolocate-geolocate', geolocate, position);
458+
});
459+
460+
geolocate.on('trackuserlocationstart', function () {
461+
_this2.$emit('geolocate-trackuserlocationstart', geolocate);
462+
});
463+
464+
geolocate.on('trackuserlocationend', function () {
465+
_this2.$emit('geolocate-trackuserlocationend', geolocate);
466+
});
467+
468+
geolocate.on('error', function (positionError) {
469+
_this2.$emit('geolocate-error', geolocate, positionError);
470+
});
453471
}
454472

455473
//Scale Control
@@ -539,6 +557,18 @@ var app = new Vue({
539557
var features = map.queryRenderedFeatures(e.point, { layers: ['points'] });
540558
map.getCanvas().style.cursor = features.length ? 'pointer' : '';
541559
},
560+
geolocate: function geolocate(control, position) {
561+
console.log('User position: ' + position.coords.latitude + ', ' + position.coords.longitude);
562+
},
563+
geolocateError: function geolocateError(control, positionError) {
564+
console.log(positionError);
565+
},
566+
geolocateStart: function geolocateStart(control) {
567+
console.log('geolocate started');
568+
},
569+
geolocateEnd: function geolocateEnd(control) {
570+
console.log('geolocate ended');
571+
},
542572
addPopUp: function addPopUp(map, e) {
543573
var features = map.queryRenderedFeatures(e.point, { layers: ['points'] });
544574
if (!features.length) {

readme.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,14 @@ All Mapbox GL JS events are available for use. For a list of events look here: [
172172

173173
Map and control events can be used by adding a prefix introduced in the following table to the beginning of the Mapbox event name.
174174

175-
| Object | prefix |
175+
| Object | Prefix |
176176
| ----- | ------ |
177177
| Map | `map-` |
178178
| GeolocateControl | `geolocate-` |
179179

180180
For example for the Mapbox Map `click` event `@map-click` can be used and for the GeolocateControl geolocate event `@geolocate-geolocate` can be used.
181181

182-
All events are passed the `map` or `control` object and the event if it has one.
182+
All events are passed the `map` or `control` object and the event or position object if it has one.
183183

184184

185185
Example:
@@ -192,6 +192,7 @@ HTML File:
192192
@map-load="mapLoaded"
193193
@map-click="mapClicked"
194194
@geolocate-error="geolocateError"
195+
@geolocate-geolocate="geolocate"
195196
>
196197
</mapbox>
197198
</div>
@@ -248,7 +249,10 @@ const app = new Vue({
248249
alert('Map Clicked!');
249250
},
250251
geolocateError(control, positionError) {
251-
alert('Error in locating:' + positionError);
252+
console.log(positionError);
253+
},
254+
geolocate(control, position) {
255+
console.log(`User position: ${position.coords.latitude}, ${position.coords.longitude}`);
252256
}
253257
}
254258
});

src/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ const app = new Vue({
5757
map.getCanvas().style.cursor = (features.length) ? 'pointer' : '';
5858
},
5959
geolocate(control, position) {
60-
console.log('User position:' + position);
60+
console.log(`User position: ${position.coords.latitude}, ${position.coords.longitude}`);
6161
},
6262
geolocateError(control, positionError) {
63-
console.log('Position Error:' + positionError);
63+
console.log(positionError);
6464
},
6565
geolocateStart(control) {
6666
console.log('geolocate started');

0 commit comments

Comments
 (0)