Skip to content

Commit 2b9ce3e

Browse files
authored
Fix midpoint calculation when terrain is enabled (#1039)
1 parent f1fde19 commit 2b9ce3e

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Changelog
22

3+
# 1.2.2
4+
5+
### Bug Fixes:
6+
- Fix midpoint calculation when using mapbox-gl-draw with 3d terrain
7+
38
# 1.2.1
49

510
### Bug Fixes:

src/lib/create_midpoint.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Constants from '../constants';
22

3-
export default function(parent, startVertex, endVertex, map) {
3+
export default function(parent, startVertex, endVertex) {
44
const startCoord = startVertex.geometry.coordinates;
55
const endCoord = endVertex.geometry.coordinates;
66

@@ -13,9 +13,10 @@ export default function(parent, startVertex, endVertex, map) {
1313
return null;
1414
}
1515

16-
const ptA = map.project([ startCoord[0], startCoord[1] ]);
17-
const ptB = map.project([ endCoord[0], endCoord[1] ]);
18-
const mid = map.unproject([ (ptA.x + ptB.x) / 2, (ptA.y + ptB.y) / 2 ]);
16+
const mid = {
17+
lng: (startCoord[0] + endCoord[0]) / 2,
18+
lat: (startCoord[1] + endCoord[1]) / 2
19+
};
1920

2021
return {
2122
type: Constants.geojsonTypes.FEATURE,

src/lib/create_supplementary_points.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function createSupplementaryPoints(geojson, options = {}, basePath = null) {
3434
// vertex before this one. If so, add a midpoint
3535
// between that vertex and this one.
3636
if (options.midpoints && lastVertex) {
37-
const midpoint = createMidpoint(featureId, lastVertex, vertex, options.map);
37+
const midpoint = createMidpoint(featureId, lastVertex, vertex);
3838
if (midpoint) {
3939
supplementaryPoints.push(midpoint);
4040
}

0 commit comments

Comments
 (0)