Skip to content

Commit b2102a5

Browse files
authored
Merge pull request #4398 from plotly/mapbox-zoom-inout-modebar-buttons
Add modebar buttons zoomInMapbox and zoomOutMapbox
2 parents c75c3ec + 03f9ab3 commit b2102a5

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

src/components/modebar/buttons.js

+36
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,42 @@ modeBarButtons.resetViewMapbox = {
618618
}
619619
};
620620

621+
modeBarButtons.zoomInMapbox = {
622+
name: 'zoomInMapbox',
623+
title: function(gd) { return _(gd, 'Zoom in'); },
624+
attr: 'zoom',
625+
val: 'in',
626+
icon: Icons.zoom_plus,
627+
click: handleMapboxZoom
628+
};
629+
630+
modeBarButtons.zoomOutMapbox = {
631+
name: 'zoomOutMapbox',
632+
title: function(gd) { return _(gd, 'Zoom out'); },
633+
attr: 'zoom',
634+
val: 'out',
635+
icon: Icons.zoom_minus,
636+
click: handleMapboxZoom
637+
};
638+
639+
function handleMapboxZoom(gd, ev) {
640+
var button = ev.currentTarget;
641+
var val = button.getAttribute('data-val');
642+
var fullLayout = gd._fullLayout;
643+
var subplotIds = fullLayout._subplots.mapbox || [];
644+
var scalar = 1.05;
645+
var aObj = {};
646+
647+
for(var i = 0; i < subplotIds.length; i++) {
648+
var id = subplotIds[i];
649+
var current = fullLayout[id].zoom;
650+
var next = (val === 'in') ? scalar * current : current / scalar;
651+
aObj[id + '.zoom'] = next;
652+
}
653+
654+
Registry.call('_guiRelayout', gd, aObj);
655+
}
656+
621657
function resetView(gd, subplotType) {
622658
var fullLayout = gd._fullLayout;
623659
var subplotIds = fullLayout._subplots[subplotType] || [];

src/components/modebar/manage.js

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ function getButtonGroups(gd) {
126126
hoverGroup = ['hoverClosest3d'];
127127
resetGroup = ['resetCameraDefault3d', 'resetCameraLastSave3d'];
128128
} else if(hasMapbox) {
129+
zoomGroup = ['zoomInMapbox', 'zoomOutMapbox'];
129130
hoverGroup = ['toggleHover'];
130131
resetGroup = ['resetViewMapbox'];
131132
} else if(hasGL2D) {

test/jasmine/tests/modebar_test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ describe('ModeBar', function() {
484484
var buttons = getButtons([
485485
['toImage'],
486486
['pan2d'],
487-
['resetViewMapbox'],
487+
['zoomInMapbox', 'zoomOutMapbox', 'resetViewMapbox'],
488488
['toggleHover']
489489
]);
490490

@@ -502,7 +502,7 @@ describe('ModeBar', function() {
502502
var buttons = getButtons([
503503
['toImage'],
504504
['pan2d', 'select2d', 'lasso2d'],
505-
['resetViewMapbox'],
505+
['zoomInMapbox', 'zoomOutMapbox', 'resetViewMapbox'],
506506
['toggleHover']
507507
]);
508508

0 commit comments

Comments
 (0)