Skip to content

Commit

Permalink
Patch map.fire to format arguments passed to it.
Browse files Browse the repository at this point in the history
  • Loading branch information
tristen committed May 2, 2018
1 parent 85f39bf commit cf3da55
Show file tree
Hide file tree
Showing 5 changed files with 2,073 additions and 156 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Install dependencies, build the source files and crank up a server via:
```
git clone [email protected]:mapbox/mapbox-gl-draw.git
npm install
npm start & open http://localhost:9966/debug/?access_token=<token>
npm start & open http://localhost:9967/debug/?access_token=<token>
```

### Testing
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"unassertify": "^2.0.3"
},
"peerDependencies": {
"mapbox-gl": ">=0.27.0 <=0.41.0"
"mapbox-gl": ">=0.27.0 <=0.45.0"
},
"dependencies": {
"@mapbox/geojson-area": "^0.2.1",
Expand Down
15 changes: 15 additions & 0 deletions src/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const events = require('./events');
const Store = require('./store');
const ui = require('./ui');
const Constants = require('./constants');
const xtend = require('xtend');

module.exports = function(ctx) {

Expand Down Expand Up @@ -35,6 +36,20 @@ module.exports = function(ctx) {
ctx.events.addEventListeners();
},
onAdd: function(map) {

// Monkey patch to resolve breaking change to `fire` introduced by
// mapbox-gl-js. See mapbox/mapbox-gl-draw/issues/766.
const _fire = map.fire;
map.fire = function(type, event) {
let args = arguments;

if (_fire.length === 1 && arguments.length !== 1) {
args = [xtend({}, { type: type }, event)];
}

return _fire.apply(map, args);
};

ctx.map = map;
ctx.events = events(ctx);
ctx.ui = ui(ctx);
Expand Down
2 changes: 1 addition & 1 deletion src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ Store.prototype.restoreMapConfig = function() {
/**
* Returns the initial state of an interaction setting.
* @param {string} interaction
* @return {boolean} `true` if the interaction is enabled, `false` if not.
* @return {boolean} `true` if the interaction is enabled, `false` if not.
* Defaults to `true`. (Todo: include defaults.)
*/
Store.prototype.getInitialConfigValue = function(interaction) {
Expand Down
Loading

0 comments on commit cf3da55

Please sign in to comment.