Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
add modebar buttons zoomInMapbox and zoomOutMapbox
- use scalar value 1.3, which gives a smaller zoom increment
  than for geo and cartesian subplots. I personally prefer
  this behaviour for the vector-tiled mapbox subplots.
  • Loading branch information
etpinard committed Nov 29, 2019
commit 26376dd32672cc7c1bcb526e7cd9f246392071da
36 changes: 36 additions & 0 deletions src/components/modebar/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,42 @@ modeBarButtons.resetViewMapbox = {
}
};

modeBarButtons.zoomInMapbox = {
name: 'zoomInMapbox',
title: function(gd) { return _(gd, 'Zoom in'); },
attr: 'zoom',
val: 'in',
icon: Icons.zoom_plus,
click: handleMapboxZoom
};

modeBarButtons.zoomOutMapbox = {
name: 'zoomOutMapbox',
title: function(gd) { return _(gd, 'Zoom out'); },
attr: 'zoom',
val: 'out',
icon: Icons.zoom_minus,
click: handleMapboxZoom
};

function handleMapboxZoom(gd, ev) {
var button = ev.currentTarget;
var val = button.getAttribute('data-val');
var fullLayout = gd._fullLayout;
var subplotIds = fullLayout._subplots.mapbox || [];
var scalar = 1.3;
var aObj = {};

for(var i = 0; i < subplotIds.length; i++) {
var id = subplotIds[i];
var current = fullLayout[id].zoom;
var next = (val === 'in') ? scalar * current : current / scalar;
aObj[id + '.zoom'] = next;
}

Registry.call('_guiRelayout', gd, aObj);
}

function resetView(gd, subplotType) {
var fullLayout = gd._fullLayout;
var subplotIds = fullLayout._subplots[subplotType] || [];
Expand Down
1 change: 1 addition & 0 deletions src/components/modebar/manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ function getButtonGroups(gd) {
hoverGroup = ['hoverClosest3d'];
resetGroup = ['resetCameraDefault3d', 'resetCameraLastSave3d'];
} else if(hasMapbox) {
zoomGroup = ['zoomInMapbox', 'zoomOutMapbox'];
hoverGroup = ['toggleHover'];
resetGroup = ['resetViewMapbox'];
} else if(hasGL2D) {
Expand Down
4 changes: 2 additions & 2 deletions test/jasmine/tests/modebar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ describe('ModeBar', function() {
var buttons = getButtons([
['toImage'],
['pan2d'],
['resetViewMapbox'],
['zoomInMapbox', 'zoomOutMapbox', 'resetViewMapbox'],
['toggleHover']
]);

Expand All @@ -502,7 +502,7 @@ describe('ModeBar', function() {
var buttons = getButtons([
['toImage'],
['pan2d', 'select2d', 'lasso2d'],
['resetViewMapbox'],
['zoomInMapbox', 'zoomOutMapbox', 'resetViewMapbox'],
['toggleHover']
]);

Expand Down