Skip to content

Commit 1ac6e9f

Browse files
committed
add bound limits to mapbox subplot
1 parent 1eda36e commit 1ac6e9f

File tree

6 files changed

+66
-0
lines changed

6 files changed

+66
-0
lines changed

src/plots/mapbox/layout_attributes.js

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

98+
westbound: {
99+
valType: 'number',
100+
dflt: null,
101+
description: 'Sets the minimum longitude of the map (in degrees East).'
102+
},
103+
eastbound: {
104+
valType: 'number',
105+
dflt: null,
106+
description: 'Sets the maximum longitude of the map (in degrees East).'
107+
},
108+
southbound: {
109+
valType: 'number',
110+
dflt: null,
111+
description: 'Sets the minimum latitude of the map (in degrees North).'
112+
},
113+
northbound: {
114+
valType: 'number',
115+
dflt: null,
116+
description: 'Sets the maximum latitude of the map (in degrees North).'
117+
},
118+
98119
layers: templatedArray('layer', {
99120
visible: {
100121
valType: 'boolean',

src/plots/mapbox/layout_defaults.js

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

29+
coerce('westbound');
30+
coerce('eastbound');
31+
coerce('southbound');
32+
coerce('northbound');
33+
2934
handleArrayContainerDefaults(containerIn, containerOut, {
3035
name: 'layers',
3136
handleItemDefaults: handleLayerDefaults

src/plots/mapbox/mapbox.js

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

94+
var westbound = opts.westbound;
95+
var eastbound = opts.eastbound;
96+
var southbound = opts.southbound;
97+
var northbound = opts.northbound;
98+
var maxBounds = (
99+
westbound !== undefined &&
100+
eastbound !== undefined &&
101+
southbound !== undefined &&
102+
northbound !== undefined
103+
) ? [[westbound, southbound], [eastbound, northbound]] : null;
104+
94105
// create the map!
95106
var map = self.map = new mapboxgl.Map({
96107
container: self.div,
@@ -100,6 +111,7 @@ proto.createMap = function(calcData, fullLayout, resolve, reject) {
100111
zoom: opts.zoom,
101112
bearing: opts.bearing,
102113
pitch: opts.pitch,
114+
maxBounds: maxBounds,
103115

104116
interactive: !self.isStatic,
105117
preserveDrawingBuffer: self.isStatic,
1.75 KB
Loading

test/image/mocks/mapbox_bubbles-text.json

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
],
4040
"layout": {
4141
"mapbox": {
42+
"westbound": -60,
43+
"eastbound": 60,
44+
"southbound": -30,
45+
"northbound": 30,
4246
"style": "light",
4347
"zoom": 2.5,
4448
"center": {

test/plot-schema.json

+24
Original file line numberDiff line numberDiff line change
@@ -3086,6 +3086,12 @@
30863086
"valType": "info_array"
30873087
}
30883088
},
3089+
"eastbound": {
3090+
"description": "Sets the maximum longitude of the map (in degrees East).",
3091+
"dflt": null,
3092+
"editType": "plot",
3093+
"valType": "number"
3094+
},
30893095
"editType": "plot",
30903096
"layers": {
30913097
"items": {
@@ -3306,13 +3312,25 @@
33063312
},
33073313
"role": "object"
33083314
},
3315+
"northbound": {
3316+
"description": "Sets the maximum latitude of the map (in degrees North).",
3317+
"dflt": null,
3318+
"editType": "plot",
3319+
"valType": "number"
3320+
},
33093321
"pitch": {
33103322
"description": "Sets the pitch angle of the map (in degrees, where *0* means perpendicular to the surface of the map) (mapbox.pitch).",
33113323
"dflt": 0,
33123324
"editType": "plot",
33133325
"valType": "number"
33143326
},
33153327
"role": "object",
3328+
"southbound": {
3329+
"description": "Sets the minimum latitude of the map (in degrees North).",
3330+
"dflt": null,
3331+
"editType": "plot",
3332+
"valType": "number"
3333+
},
33163334
"style": {
33173335
"description": "Defines the map layers that are rendered by default below the trace layers defined in `data`, which are themselves by default rendered below the layers defined in `layout.mapbox.layers`. These layers can be defined either explicitly as a Mapbox Style object which can contain multiple layer definitions that load data from any public or private Tile Map Service (TMS or XYZ) or Web Map Service (WMS) or implicitly by using one of the built-in style objects which use WMSes which do not require any access tokens, or by using a default Mapbox style or custom Mapbox style URL, both of which require a Mapbox access token Note that Mapbox access token can be set in the `accesstoken` attribute or in the `mapboxAccessToken` config option. Mapbox Style objects are of the form described in the Mapbox GL JS documentation available at https://docs.mapbox.com/mapbox-gl-js/style-spec The built-in plotly.js styles objects are: carto-darkmatter, carto-positron, open-street-map, stamen-terrain, stamen-toner, stamen-watercolor, white-bg The built-in Mapbox styles are: basic, streets, outdoors, light, dark, satellite, satellite-streets Mapbox style URLs are of the form: mapbox://mapbox.mapbox-<name>-<version>",
33183336
"dflt": "basic",
@@ -3340,6 +3358,12 @@
33403358
"editType": "none",
33413359
"valType": "any"
33423360
},
3361+
"westbound": {
3362+
"description": "Sets the minimum longitude of the map (in degrees East).",
3363+
"dflt": null,
3364+
"editType": "plot",
3365+
"valType": "number"
3366+
},
33433367
"zoom": {
33443368
"description": "Sets the zoom level of the map (mapbox.zoom).",
33453369
"dflt": 1,

0 commit comments

Comments
 (0)