Skip to content

Commit 88d2eb2

Browse files
committed
mapbox coords: get canvas size from style, not attributes
The width and height attributes are expanded by devicePixelRatio, but the style width and height are in css pixels.
1 parent 4eb9a28 commit 88d2eb2

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

src/plots/mapbox/mapbox.js

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -727,23 +727,8 @@ proto.getView = function() {
727727
var center = { lon: lon, lat: lat };
728728

729729
var canvas = map.getCanvas();
730-
var width = canvas.width;
731-
var height = canvas.height;
732-
733-
var p00, p10, p11, p01;
734-
735-
// attempt finding correct scale for Retina display
736-
for(var scale = 2; scale > 0; scale--) {
737-
var w = width / scale;
738-
var h = height / scale;
739-
740-
p00 = map.unproject([0, 0]).toArray();
741-
p10 = map.unproject([w, 0]).toArray();
742-
p11 = map.unproject([w, h]).toArray();
743-
p01 = map.unproject([0, h]).toArray();
744-
745-
if(Math.abs(lon - (p00[0] + p11[0]) / 2) < 0.0001) break;
746-
}
730+
var w = parseInt(canvas.style.width);
731+
var h = parseInt(canvas.style.height);
747732

748733
return {
749734
center: center,
@@ -752,10 +737,10 @@ proto.getView = function() {
752737
pitch: map.getPitch(),
753738
_derived: {
754739
coordinates: [
755-
p00,
756-
p10,
757-
p11,
758-
p01
740+
map.unproject([0, 0]).toArray(),
741+
map.unproject([w, 0]).toArray(),
742+
map.unproject([w, h]).toArray(),
743+
map.unproject([0, h]).toArray()
759744
]
760745
}
761746
};

0 commit comments

Comments
 (0)