Skip to content

Commit 6f1a55b

Browse files
committed
emit plotly_relayout (w/ mocked evt data) on mapbox dblclick
1 parent c95dd4b commit 6f1a55b

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/plots/mapbox/mapbox.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ proto.createMap = function(calcData, fullLayout, resolve, reject) {
193193
map.on('zoomstart', unhover);
194194

195195
map.on('dblclick', function() {
196+
gd.emit('plotly_doubleclick', null);
197+
196198
var viewInitial = self.viewInitial;
197199

198200
map.setCenter(convertCenter(viewInitial.center));
@@ -207,7 +209,7 @@ proto.createMap = function(calcData, fullLayout, resolve, reject) {
207209
opts._input.bearing = opts.bearing = viewNow.bearing;
208210
opts._input.pitch = opts.pitch = viewNow.pitch;
209211

210-
gd.emit('plotly_doubleclick', null);
212+
emitRelayoutFromView(viewNow);
211213
});
212214

213215
function emitRelayoutFromView(view) {

test/jasmine/tests/mapbox_test.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -866,11 +866,11 @@ describe('@noCI, mapbox plots', function() {
866866
it('should respond drag / scroll / double-click interactions', function(done) {
867867
var relayoutCnt = 0;
868868
var doubleClickCnt = 0;
869-
var updateData;
869+
var evtData;
870870

871-
gd.on('plotly_relayout', function(eventData) {
871+
gd.on('plotly_relayout', function(d) {
872872
relayoutCnt++;
873-
updateData = eventData;
873+
evtData = d;
874874
});
875875

876876
gd.on('plotly_doubleclick', function() {
@@ -885,42 +885,46 @@ describe('@noCI, mapbox plots', function() {
885885
});
886886
}
887887

888-
function assertLayout(center, zoom, opts) {
889-
var mapInfo = getMapInfo(gd),
890-
layout = gd.layout.mapbox;
888+
function _assertLayout(center, zoom) {
889+
var mapInfo = getMapInfo(gd);
890+
var layout = gd.layout.mapbox;
891891

892892
expect([mapInfo.center.lng, mapInfo.center.lat]).toBeCloseToArray(center);
893893
expect(mapInfo.zoom).toBeCloseTo(zoom);
894894

895895
expect([layout.center.lon, layout.center.lat]).toBeCloseToArray(center);
896896
expect(layout.zoom).toBeCloseTo(zoom);
897+
}
897898

898-
if(opts && opts.withUpdateData) {
899+
function _assert(center, zoom) {
900+
_assertLayout(center, zoom);
899901

900902
expect([evtData['mapbox.center'].lon, evtData['mapbox.center'].lat]).toBeCloseToArray(center);
901903
expect(evtData['mapbox.zoom']).toBeCloseTo(zoom);
902-
}
903904
}
904905

905-
assertLayout([-4.710, 19.475], 1.234);
906+
_assertLayout([-4.710, 19.475], 1.234);
906907

907908
var p1 = [pointPos[0] + 50, pointPos[1] - 20];
908909

909910
_drag(pointPos, p1, function() {
910-
expect(relayoutCnt).toEqual(1);
911-
assertLayout([-19.651, 13.751], 1.234, {withUpdateData: true});
911+
expect(relayoutCnt).toBe(1, 'relayout cnt');
912+
expect(doubleClickCnt).toBe(0, 'double click cnt');
913+
_assert([-19.651, 13.751], 1.234);
912914

913915
return _doubleClick(p1);
914916
})
915917
.then(function() {
918+
expect(relayoutCnt).toBe(2, 'relayout cnt');
916919
expect(doubleClickCnt).toBe(1, 'double click cnt');
917-
assertLayout([-4.710, 19.475], 1.234);
920+
_assert([-4.710, 19.475], 1.234);
918921

919922
return _scroll(pointPos);
920923
})
921924
.then(function() {
925+
expect(relayoutCnt).toBe(3, 'relayout cnt');
926+
expect(doubleClickCnt).toBe(1, 'double click cnt');
922927
expect(getMapInfo(gd).zoom).toBeGreaterThan(1.234);
923-
expect(relayoutCnt).toBe(2);
924928
})
925929
.catch(failTest)
926930
.then(done);

0 commit comments

Comments
 (0)