Skip to content

Commit e377c38

Browse files
authored
Merge pull request #6339 from plotly/mapbox-bounds
Add bounds to mapbox subplot
2 parents 5d7a255 + 4329e49 commit e377c38

File tree

8 files changed

+82
-0
lines changed

8 files changed

+82
-0
lines changed

draftlogs/6339_add.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Add bounds to mapbox suplots [[6339](https://github.com/plotly/plotly.js/pull/6339)]

src/plots/mapbox/layout_attributes.js

+31
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,37 @@ var attrs = module.exports = overrideAll({
9595
].join(' ')
9696
},
9797

98+
bounds: {
99+
west: {
100+
valType: 'number',
101+
description: [
102+
'Sets the minimum longitude of the map (in degrees East)',
103+
'if `east`, `south` and `north` are declared.'
104+
].join(' ')
105+
},
106+
east: {
107+
valType: 'number',
108+
description: [
109+
'Sets the maximum longitude of the map (in degrees East)',
110+
'if `west`, `south` and `north` are declared.'
111+
].join(' ')
112+
},
113+
south: {
114+
valType: 'number',
115+
description: [
116+
'Sets the minimum latitude of the map (in degrees North)',
117+
'if `east`, `west` and `north` are declared.'
118+
].join(' ')
119+
},
120+
north: {
121+
valType: 'number',
122+
description: [
123+
'Sets the maximum latitude of the map (in degrees North)',
124+
'if `east`, `west` and `south` are declared.'
125+
].join(' ')
126+
}
127+
},
128+
98129
layers: templatedArray('layer', {
99130
visible: {
100131
valType: 'boolean',

src/plots/mapbox/layout_defaults.js

+13
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ function handleDefaults(containerIn, containerOut, coerce, opts) {
2626
coerce('bearing');
2727
coerce('pitch');
2828

29+
var west = coerce('bounds.west');
30+
var east = coerce('bounds.east');
31+
var south = coerce('bounds.south');
32+
var north = coerce('bounds.north');
33+
if(
34+
west === undefined ||
35+
east === undefined ||
36+
south === undefined ||
37+
north === undefined
38+
) {
39+
delete containerOut.bounds;
40+
}
41+
2942
handleArrayContainerDefaults(containerIn, containerOut, {
3043
name: 'layers',
3144
handleItemDefaults: handleLayerDefaults

src/plots/mapbox/mapbox.js

+4
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ proto.createMap = function(calcData, fullLayout, resolve, reject) {
9191
// store access token associated with this map
9292
self.accessToken = opts.accesstoken;
9393

94+
var bounds = opts.bounds;
95+
var maxBounds = bounds ? [[bounds.west, bounds.south], [bounds.east, bounds.north]] : null;
96+
9497
// create the map!
9598
var map = self.map = new mapboxgl.Map({
9699
container: self.div,
@@ -100,6 +103,7 @@ proto.createMap = function(calcData, fullLayout, resolve, reject) {
100103
zoom: opts.zoom,
101104
bearing: opts.bearing,
102105
pitch: opts.pitch,
106+
maxBounds: maxBounds,
103107

104108
interactive: !self.isStatic,
105109
preserveDrawingBuffer: self.isStatic,
1.75 KB
Loading

test/image/mocks/mapbox_bubbles-text.json

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@
3939
],
4040
"layout": {
4141
"mapbox": {
42+
"bounds": {
43+
"west": -60,
44+
"east": 60,
45+
"south": -30,
46+
"north": 30
47+
},
4248
"style": "light",
4349
"zoom": 2.5,
4450
"center": {

test/jasmine/tests/select_test.js

+3
Original file line numberDiff line numberDiff line change
@@ -1862,6 +1862,9 @@ describe('Test select box and lasso per trace:', function() {
18621862
fig.data[0].lat.push(null);
18631863

18641864
fig.layout.dragmode = 'select';
1865+
1866+
delete fig.layout.mapbox.bounds;
1867+
18651868
fig.config = {
18661869
mapboxAccessToken: require('@build/credentials.json').MAPBOX_ACCESS_TOKEN
18671870
};

test/plot-schema.json

+24
Original file line numberDiff line numberDiff line change
@@ -3006,6 +3006,30 @@
30063006
"editType": "plot",
30073007
"valType": "number"
30083008
},
3009+
"bounds": {
3010+
"east": {
3011+
"description": "Sets the maximum longitude of the map (in degrees East) if `west`, `south` and `north` are declared.",
3012+
"editType": "plot",
3013+
"valType": "number"
3014+
},
3015+
"editType": "plot",
3016+
"north": {
3017+
"description": "Sets the maximum latitude of the map (in degrees North) if `east`, `west` and `south` are declared.",
3018+
"editType": "plot",
3019+
"valType": "number"
3020+
},
3021+
"role": "object",
3022+
"south": {
3023+
"description": "Sets the minimum latitude of the map (in degrees North) if `east`, `west` and `north` are declared.",
3024+
"editType": "plot",
3025+
"valType": "number"
3026+
},
3027+
"west": {
3028+
"description": "Sets the minimum longitude of the map (in degrees East) if `east`, `south` and `north` are declared.",
3029+
"editType": "plot",
3030+
"valType": "number"
3031+
}
3032+
},
30093033
"center": {
30103034
"editType": "plot",
30113035
"lat": {

0 commit comments

Comments
 (0)