diff --git a/src/ui/map.js b/src/ui/map.js index 277df72dc83..e7f8868a7f2 100755 --- a/src/ui/map.js +++ b/src/ui/map.js @@ -197,6 +197,7 @@ const defaultOptions = { * @param {number} [options.bearing=0] The initial bearing (rotation) of the map, measured in degrees counter-clockwise from north. If `bearing` is not specified in the constructor options, Mapbox GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`. * @param {number} [options.pitch=0] The initial pitch (tilt) of the map, measured in degrees away from the plane of the screen (0-60). If `pitch` is not specified in the constructor options, Mapbox GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`. * @param {LngLatBoundsLike} [options.bounds] The initial bounds of the map. If `bounds` is specified, it overrides `center` and `zoom` constructor options. + * @param {Object} [options.fitBoundsOptions] A [`fitBounds`](#Map#fitBounds) options object to use when fitting the initial bounds provided above. * @param {boolean} [options.renderWorldCopies=true] If `true`, multiple copies of the world will be rendered, when zoomed out. * @param {number} [options.maxTileCacheSize=null] The maximum number of tiles stored in the tile cache for a given source. If omitted, the cache will be dynamically sized based on the current viewport. * @param {string} [options.localIdeographFontFamily=null] If specified, defines a CSS font-family @@ -381,7 +382,7 @@ class Map extends Camera { if (options.bounds) { this.resize(); - this.fitBounds(options.bounds, { duration: 0 }); + this.fitBounds(options.bounds, extend({}, options.fitBoundsOptions, { duration: 0 })); } } diff --git a/test/unit/ui/map.test.js b/test/unit/ui/map.test.js index 7b0dc2fdb12..21caf8b7143 100755 --- a/test/unit/ui/map.test.js +++ b/test/unit/ui/map.test.js @@ -67,6 +67,24 @@ test('Map', (t) => { t.end(); }); + t.test('initial bounds options in constructor options', (t) => { + const bounds = [[-133, 16], [-68, 50]]; + + const map = (fitBoundsOptions) => { + const container = window.document.createElement('div'); + Object.defineProperty(container, 'offsetWidth', {value: 512}); + Object.defineProperty(container, 'offsetHeight', {value: 512}); + return createMap(t, { container, bounds, fitBoundsOptions }); + }; + + const unpadded = map(); + const padded = map({ padding: 100 }); + + t.ok(unpadded.getZoom() > padded.getZoom()); + + t.end(); + }); + t.test('disables handlers', (t) => { t.test('disables all handlers', (t) => { const map = createMap(t, {interactive: false});