diff --git a/docs/API.md b/docs/API.md index 0a2dcce99..1010f0eda 100644 --- a/docs/API.md +++ b/docs/API.md @@ -36,7 +36,7 @@ All of the following options are optional. - `modes`, Object: over ride the default modes with your own. `MapboxDraw.modes` can be used to see the default values. More information on custom modes [can be found here](https://github.com/mapbox/mapbox-gl-draw/blob/main/docs/MODES.md). - `defaultMode`, String (default: `'simple_select'`): the mode (from `modes`) that user will first land in. - `userProperties`, boolean (default: `false`): properties of a feature will also be available for styling and prefixed with `user_`, e.g., `['==', 'user_custom_label', 'Example']` -- `silent`, boolean (default: `true`): Whether or not to emit events when calling Draw API methods. If `false`, events will be emitted. +- `suppressAPIEvents`, boolean (default: `true`): Whether or not to emit events when calling Draw API methods. If `false`, events will be emitted. ## Modes diff --git a/src/api.js b/src/api.js index d2b87d3f8..e65eaeffc 100644 --- a/src/api.js +++ b/src/api.js @@ -24,7 +24,7 @@ export default function(ctx, api) { api.modes = Constants.modes; // API doesn't emit events by default - const silent = ctx.options.silent !== undefined ? !!ctx.options.silent : true; + const silent = ctx.options.suppressAPIEvents !== undefined ? !!ctx.options.suppressAPIEvents : true; api.getFeatureIdsAt = function(point) { const features = featuresAt.click({ point }, null, ctx); diff --git a/src/options.js b/src/options.js index d98642091..8e88928e6 100644 --- a/src/options.js +++ b/src/options.js @@ -15,7 +15,7 @@ const defaultOptions = { modes, controls: {}, userProperties: false, - silent: true + suppressAPIEvents: true }; const showControls = { diff --git a/src/store.js b/src/store.js index bd1f53a4e..ed163a74d 100644 --- a/src/store.js +++ b/src/store.js @@ -87,7 +87,7 @@ Store.prototype.setDirty = function() { Store.prototype.featureCreated = function(featureId, options = {}) { this._changedFeatureIds.add(featureId); - const silent = options.silent != null ? options.silent : this.ctx.options.silent; + const silent = options.silent != null ? options.silent : this.ctx.options.suppressAPIEvents; if (silent !== true) { const feature = this.get(featureId); this.ctx.events.fire(Constants.events.CREATE, { @@ -106,7 +106,7 @@ Store.prototype.featureCreated = function(featureId, options = {}) { Store.prototype.featureChanged = function(featureId, options = {}) { this._changedFeatureIds.add(featureId); - const silent = options.silent != null ? options.silent : this.ctx.options.silent; + const silent = options.silent != null ? options.silent : this.ctx.options.suppressAPIEvents; if (silent !== true) { this.ctx.events.fire(Constants.events.UPDATE, { action: options.action ? options.action : Constants.updateActions.CHANGE_COORDINATES, diff --git a/test/interaction_events.test.js b/test/interaction_events.test.js index 5752b14ab..4a9283940 100644 --- a/test/interaction_events.test.js +++ b/test/interaction_events.test.js @@ -989,8 +989,8 @@ test('ensure API fire right events', async (t) => { const map = createMap({container}); const fireSpy = spy(map, 'fire'); - // Explicitly set silent to false to ensure events are fired - const Draw = new MapboxDraw({ silent: false }); + // Explicitly set `suppressAPIEvents` to false to ensure events are fired + const Draw = new MapboxDraw({ suppressAPIEvents: false }); map.addControl(Draw); await map.on('load'); diff --git a/test/options.test.js b/test/options.test.js index 58e2a39a9..aa2569646 100644 --- a/test/options.test.js +++ b/test/options.test.js @@ -33,7 +33,7 @@ test('Options test', async (t) => { combine_features: true, uncombine_features: true }, - silent: true + suppressAPIEvents: true }; assert.deepEqual(defaultOptions, Draw.options); assert.deepEqual(styleWithSourcesFixture, Draw.options.styles); @@ -60,7 +60,7 @@ test('Options test', async (t) => { combine_features: true, uncombine_features: true }, - silent: true + suppressAPIEvents: true }; assert.deepEqual(defaultOptions, Draw.options); @@ -87,7 +87,7 @@ test('Options test', async (t) => { combine_features: false, uncombine_features: false }, - silent: true + suppressAPIEvents: true }; assert.deepEqual(defaultOptions, Draw.options); }); @@ -113,7 +113,7 @@ test('Options test', async (t) => { combine_features: false, uncombine_features: false }, - silent: true + suppressAPIEvents: true }; assert.deepEqual(defaultOptions, Draw.options); @@ -140,7 +140,7 @@ test('Options test', async (t) => { combine_features: true, uncombine_features: true }, - silent: true + suppressAPIEvents: true }; assert.deepEqual(defaultOptions, Draw.options); @@ -167,7 +167,7 @@ test('Options test', async (t) => { combine_features: true, uncombine_features: true }, - silent: true + suppressAPIEvents: true }; assert.deepEqual(defaultOptions, Draw.options); assert.deepEqual(styleWithSourcesFixture, Draw.options.styles); diff --git a/test/store.test.js b/test/store.test.js index 41e22d956..836f4ea28 100644 --- a/test/store.test.js +++ b/test/store.test.js @@ -10,7 +10,7 @@ import createMap from './utils/create_map.js'; function createStore() { const ctx = { options: { - silent: true + suppressAPIEvents: true }, map: createMap(), events: {