Skip to content

Commit

Permalink
Fix midpoint calculation when terrain is enabled (#1039)
Browse files Browse the repository at this point in the history
  • Loading branch information
karimnaaji authored Feb 25, 2021
1 parent f1fde19 commit 2b9ce3e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Changelog

# 1.2.2

### Bug Fixes:
- Fix midpoint calculation when using mapbox-gl-draw with 3d terrain

# 1.2.1

### Bug Fixes:
Expand Down
9 changes: 5 additions & 4 deletions src/lib/create_midpoint.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Constants from '../constants';

export default function(parent, startVertex, endVertex, map) {
export default function(parent, startVertex, endVertex) {
const startCoord = startVertex.geometry.coordinates;
const endCoord = endVertex.geometry.coordinates;

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

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

return {
type: Constants.geojsonTypes.FEATURE,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/create_supplementary_points.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function createSupplementaryPoints(geojson, options = {}, basePath = null) {
// vertex before this one. If so, add a midpoint
// between that vertex and this one.
if (options.midpoints && lastVertex) {
const midpoint = createMidpoint(featureId, lastVertex, vertex, options.map);
const midpoint = createMidpoint(featureId, lastVertex, vertex);
if (midpoint) {
supplementaryPoints.push(midpoint);
}
Expand Down

0 comments on commit 2b9ce3e

Please sign in to comment.