Skip to content

Add bounds to mapbox subplot #6339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/plots/mapbox/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,35 @@ var attrs = module.exports = overrideAll({
].join(' ')
},

westbound: {
valType: 'number',
description: [
'Sets the minimum longitude of the map (in degrees East)',
'if `eastbound`, `southbound` and `northbound` are declared.'
].join(' ')
},
eastbound: {
valType: 'number',
description: [
'Sets the maximum longitude of the map (in degrees East)',
'if `westbound`, `southbound` and `northbound` are declared.'
].join(' ')
},
southbound: {
valType: 'number',
description: [
'Sets the minimum latitude of the map (in degrees North)',
'if `eastbound`, `westbound` and `northbound` are declared.'
].join(' ')
},
northbound: {
valType: 'number',
description: [
'Sets the maximum latitude of the map (in degrees North)',
'if `eastbound`, `westbound` and `southbound` are declared.'
].join(' ')
},

layers: templatedArray('layer', {
visible: {
valType: 'boolean',
Expand Down
16 changes: 16 additions & 0 deletions src/plots/mapbox/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ function handleDefaults(containerIn, containerOut, coerce, opts) {
coerce('bearing');
coerce('pitch');

var westbound = coerce('westbound');
var eastbound = coerce('eastbound');
var southbound = coerce('southbound');
var northbound = coerce('northbound');
if(
westbound === undefined ||
eastbound === undefined ||
southbound === undefined ||
northbound === undefined
) {
delete containerOut.westbound;
delete containerOut.eastbound;
delete containerOut.southbound;
delete containerOut.northbound;
}

handleArrayContainerDefaults(containerIn, containerOut, {
name: 'layers',
handleItemDefaults: handleLayerDefaults
Expand Down
14 changes: 14 additions & 0 deletions src/plots/mapbox/mapbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ proto.createMap = function(calcData, fullLayout, resolve, reject) {
// store access token associated with this map
self.accessToken = opts.accesstoken;

var westbound = opts.westbound;
var eastbound = opts.eastbound;
var southbound = opts.southbound;
var northbound = opts.northbound;
var maxBounds = (
/*
westbound !== undefined &&
eastbound !== undefined &&
southbound !== undefined &&
*/
northbound !== undefined
) ? [[westbound, southbound], [eastbound, northbound]] : null;

// create the map!
var map = self.map = new mapboxgl.Map({
container: self.div,
Expand All @@ -100,6 +113,7 @@ proto.createMap = function(calcData, fullLayout, resolve, reject) {
zoom: opts.zoom,
bearing: opts.bearing,
pitch: opts.pitch,
maxBounds: maxBounds,

interactive: !self.isStatic,
preserveDrawingBuffer: self.isStatic,
Expand Down
Binary file modified test/image/baselines/mapbox_bubbles-text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions test/image/mocks/mapbox_bubbles-text.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
],
"layout": {
"mapbox": {
"westbound": -60,
"eastbound": 60,
"southbound": -30,
"northbound": 30,
"style": "light",
"zoom": 2.5,
"center": {
Expand Down
6 changes: 6 additions & 0 deletions test/jasmine/tests/select_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1862,6 +1862,12 @@ describe('Test select box and lasso per trace:', function() {
fig.data[0].lat.push(null);

fig.layout.dragmode = 'select';

delete fig.layout.mapbox.eastbound;
delete fig.layout.mapbox.westbound;
delete fig.layout.mapbox.southbound;
delete fig.layout.mapbox.northbound;

fig.config = {
mapboxAccessToken: require('@build/credentials.json').MAPBOX_ACCESS_TOKEN
};
Expand Down
20 changes: 20 additions & 0 deletions test/plot-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3086,6 +3086,11 @@
"valType": "info_array"
}
},
"eastbound": {
"description": "Sets the maximum longitude of the map (in degrees East) if `westbound`, `southbound` and `northbound` are declared.",
"editType": "plot",
"valType": "number"
},
"editType": "plot",
"layers": {
"items": {
Expand Down Expand Up @@ -3306,13 +3311,23 @@
},
"role": "object"
},
"northbound": {
"description": "Sets the maximum latitude of the map (in degrees North) if `eastbound`, `westbound` and `southbound` are declared.",
"editType": "plot",
"valType": "number"
},
"pitch": {
"description": "Sets the pitch angle of the map (in degrees, where *0* means perpendicular to the surface of the map) (mapbox.pitch).",
"dflt": 0,
"editType": "plot",
"valType": "number"
},
"role": "object",
"southbound": {
"description": "Sets the minimum latitude of the map (in degrees North) if `eastbound`, `westbound` and `northbound` are declared.",
"editType": "plot",
"valType": "number"
},
"style": {
"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>",
"dflt": "basic",
Expand Down Expand Up @@ -3340,6 +3355,11 @@
"editType": "none",
"valType": "any"
},
"westbound": {
"description": "Sets the minimum longitude of the map (in degrees East) if `eastbound`, `southbound` and `northbound` are declared.",
"editType": "plot",
"valType": "number"
},
"zoom": {
"description": "Sets the zoom level of the map (mapbox.zoom).",
"dflt": 1,
Expand Down