From 71dfcba7b6876e7596b056c8b4f38ebd29b9c392 Mon Sep 17 00:00:00 2001 From: "Zhang Ch. N" Date: Mon, 9 Jan 2023 18:18:26 +0800 Subject: [PATCH 1/3] Keep midpoint on the line With the average of Mercator coordinates of the two endpoints, the middle points were drawn off from the line. By project/unproject the Mercator latitudes to and from screen space, the screen location for midpoints would be fixed onto the line. --- src/lib/create_midpoint.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib/create_midpoint.js b/src/lib/create_midpoint.js index 766eb854..ecdcbb29 100644 --- a/src/lib/create_midpoint.js +++ b/src/lib/create_midpoint.js @@ -12,10 +12,16 @@ export default function(parent, startVertex, endVertex) { endCoord[1] < Constants.LAT_RENDERED_MIN) { return null; } - + function mercatorYfromLat(lat) { + return (180 - 180 / Math.PI * Math.log(Math.tan(Math.PI / 4 + lat * Math.PI / 360))) / 360; + } + function latFromMercatorY(y) { + const y2 = 180 - y * 360; + return 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90; + } const mid = { lng: (startCoord[0] + endCoord[0]) / 2, - lat: (startCoord[1] + endCoord[1]) / 2 + lat: latFromMercatorY((mercatorYfromLat(startCoord[1]) + mercatorYfromLat(endCoord[1])) / 2) }; return { From 0cb279f460df350ad67a1d3d99ac793cffa679d7 Mon Sep 17 00:00:00 2001 From: "Zhang Ch. N" Date: Thu, 12 Jan 2023 15:56:03 +0800 Subject: [PATCH 2/3] Adding rank value for MultiLineString As simple_select sometimes renders lines as `MultiLineString` geometry, sort ranking should handle this type or midpoint click would not work. --- src/lib/sort_features.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/sort_features.js b/src/lib/sort_features.js index 47d20bfc..80ab010f 100644 --- a/src/lib/sort_features.js +++ b/src/lib/sort_features.js @@ -4,6 +4,7 @@ import * as Constants from '../constants'; const FEATURE_SORT_RANKS = { Point: 0, LineString: 1, + MultiLineString: 1, Polygon: 2 }; From 881483e643715abfd2e98e8c165344566ac657f8 Mon Sep 17 00:00:00 2001 From: Zhang Chen Date: Thu, 12 Jan 2023 16:17:58 +0800 Subject: [PATCH 3/3] Adding rank value for MultiLineString As simple_select sometimes renders lines as `MultiLineString` geometry, sort ranking should handle this type or midpoint clicking would fail. --- src/lib/sort_features.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/sort_features.js b/src/lib/sort_features.js index 47d20bfc..80ab010f 100644 --- a/src/lib/sort_features.js +++ b/src/lib/sort_features.js @@ -4,6 +4,7 @@ import * as Constants from '../constants'; const FEATURE_SORT_RANKS = { Point: 0, LineString: 1, + MultiLineString: 1, Polygon: 2 };