Skip to content

Commit 4980e24

Browse files
committed
return correct latitude and longitude from mapbox p2c
- fix choroplethmapbox hover and remove scattermapbox hack
1 parent 0117b41 commit 4980e24

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

src/plots/mapbox/mapbox.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -451,14 +451,15 @@ proto.initFx = function(calcData, fullLayout) {
451451
map.on('mousemove', function(evt) {
452452
var bb = self.div.getBoundingClientRect();
453453

454-
// some hackery to get Fx.hover to work
455-
evt.clientX = evt.point.x + bb.left;
456-
evt.clientY = evt.point.y + bb.top;
457-
458454
evt.target.getBoundingClientRect = function() { return bb; };
459455

460-
self.xaxis.p2c = function() { return evt.lngLat.lng; };
461-
self.yaxis.p2c = function() { return evt.lngLat.lat; };
456+
var xy = [
457+
evt.originalEvent.offsetX,
458+
evt.originalEvent.offsetY
459+
];
460+
461+
self.xaxis.p2c = function() { return map.unproject(xy).lng; };
462+
self.yaxis.p2c = function() { return map.unproject(xy).lat; };
462463

463464
gd._fullLayout._rehover = function() {
464465
if(gd._fullLayout._hoversubplot === self.id && gd._fullLayout[self.id]) {

src/traces/scattermapbox/hover.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ module.exports = function hoverPoints(pointData, xval, yval) {
2222
var ya = pointData.ya;
2323
var subplot = pointData.subplot;
2424

25-
var gd = subplot.gd;
26-
var scaleX = gd._fullLayout._inverseScaleX;
27-
var scaleY = gd._fullLayout._inverseScaleY;
28-
2925
// compute winding number about [-180, 180] globe
3026
var winding = (xval >= 0) ?
3127
Math.floor((xval + 180) / 360) :
@@ -42,8 +38,8 @@ module.exports = function hoverPoints(pointData, xval, yval) {
4238
var lon = Lib.modHalf(lonlat[0], 360);
4339
var lat = lonlat[1];
4440
var pt = subplot.project([lon, lat]);
45-
var dx = pt.x - xa.c2p([xval2, lat]) * scaleX;
46-
var dy = pt.y - ya.c2p([lon, yval]) * scaleY;
41+
var dx = pt.x - xa.c2p([xval2, lat]);
42+
var dy = pt.y - ya.c2p([lon, yval]);
4743
var rad = Math.max(3, d.mrc || 0);
4844

4945
return Math.max(Math.sqrt(dx * dx + dy * dy) - rad, 1 - 3 / rad);
@@ -56,7 +52,6 @@ module.exports = function hoverPoints(pointData, xval, yval) {
5652

5753
var di = cd[pointData.index];
5854
var lonlat = di.lonlat;
59-
6055
var lonlatShifted = [Lib.modHalf(lonlat[0], 360) + lonShift, lonlat[1]];
6156

6257
// shift labels back to original winded globe

0 commit comments

Comments
 (0)