Skip to content

Commit

Permalink
Fix mapboxgl.GeoJSONSource deprecation and map.load race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Aug 16, 2016
1 parent ec283ee commit 5af10a2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 4 additions & 3 deletions dist/mapbox-gl-directions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6680,7 +6680,7 @@ var Directions = function () {
if (controls.instructions) this.container.appendChild(directionsEl);

this.subscribedActions();
this._map.on('style.load', function () {
if (this._map.loaded()) this.mapState();else this._map.on('load', function () {
return _this.mapState();
});
}
Expand Down Expand Up @@ -6713,12 +6713,13 @@ var Directions = function () {

this.actions.eventEmit('profile', { profile: profile });

var geojson = new mapboxgl.GeoJSONSource({
var geojson = {
type: 'geojson',
data: {
type: 'FeatureCollection',
features: []
}
});
};

// Add and set data theme layer/style
this._map.addSource('directions', geojson);
Expand Down
8 changes: 5 additions & 3 deletions src/directions.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ export default class Directions {
if (controls.instructions) this.container.appendChild(directionsEl);

this.subscribedActions();
this._map.on('style.load', () => this.mapState());
if (this._map.loaded()) this.mapState()
else this._map.on('load', () => this.mapState());
}

/**
Expand All @@ -90,12 +91,13 @@ export default class Directions {
// Emit any default or option set config
this.actions.eventEmit('profile', { profile });

const geojson = new mapboxgl.GeoJSONSource({
const geojson = {
type: 'geojson',
data: {
type: 'FeatureCollection',
features: []
}
});
};

// Add and set data theme layer/style
this._map.addSource('directions', geojson);
Expand Down

0 comments on commit 5af10a2

Please sign in to comment.