Skip to content

Add modebar buttons zoomInMapbox and zoomOutMapbox #4398

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 2 commits into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
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.05;
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