-
-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inbetween point of a line not quite accurate on low zooms. #35
Comments
I just came across the package geodesy that might have this functionality: LatLng midpoint = geodesy.midPointBetweenTwoGeoPoints(l1, l2); It i inactive since a long time but it has a MIT license so the functionality could be copied over. |
Thanks, I don't think the problem is the mid point of the latlng, but the fact we want the screen position of the midpoint of the line in screen coordinates (I may be wrong), so I think what we probably want to do is get the screen coords of both points, then calculate a simple halfway of those, and convert that back to latlng. There may be a simpler way, but I "think" that makes sense (I think flutter_map can do latlngtoscreenpos) |
I had a look on this, and made an attempt using turf midpoint, but it visually got worse than the current lat/lng midpoint formula. I think @ibrierley is right that it a change to screen coordinate projection is necessary here. I looked around a bit and found some answers:
It looks like we need the current zoom level to use |
@Leffe108 @ibrierley Hey guys, I also played around bit and found a working solution using the geobase package, which in my opinion flies a bit under the radar, I used thew midpoint on the rhumbline (loxodrome) which from my testing seems to work correctly. here are is what I tested: import 'package:geobase/geobase.dart';
// ....
List<DragMarker> edit() {
List<DragMarker> dragMarkers = [];
for (var c = 0; c < points.length; c++) {
final indexClosure = c;
dragMarkers.add(DragMarker(
point: points[c],
size: pointIconSize,
builder: (_, __, ___) => pointIcon,
onDragStart: (_, __) => _markerToUpdate = indexClosure,
onDragUpdate: updateMarker,
onLongPress: (ll) => remove(indexClosure),
));
}
for (var c = 0; c < points.length - 1; c++) {
final polyPoint = points[c];
final polyPoint2 = points[c + 1];
if (intermediateIcon != null) {
final indexClosure = c;
// point on Rhumbline
final mid =
Geographic.create(x: polyPoint.longitude, y: polyPoint.latitude)
.rhumb
.midPointTo(Geographic.create(
x: polyPoint2.longitude, y: polyPoint2.latitude));
final intermediatePoint = LatLng(mid.lat, mid.lon);
dragMarkers.add(DragMarker(
point: intermediatePoint,
size: intermediateIconSize,
builder: (_, __, ___) => intermediateIcon!,
onDragStart: (details, point) {
points.insert(indexClosure + 1, intermediatePoint);
_markerToUpdate = indexClosure + 1;
},
onDragUpdate: updateMarker,
));
}
} maybe you can test it and confirm it, I can create a MR if you like the solution. |
There's a quirk when using this on low zoom levels (I guess most people use a high zoom level for this) which I've never been quite happy with, and I feel like it should get fixed properly at some point.
Mid point markers can be offset slightly from their visual center. I suspect this is because of projections and a midway point of a LatLng isn't actually quite what we need. Again, we'll probably only notice this at low zoom levels where the effect is more pronounced.
I've tried a LatLngBounds.center, but actually I think this still has the same issue. What I suspect we need is actually to get the projection in pixels, so we have the screen space, then take the mid point, then unproject back into a LatLng.
If anyone fancies a challenge, it may be interesting to have a stab. This may need a bit more of a fundamental rejig, as I "think" it may need access to flutter_maps internals for the crs projection there, and original it was written to not need that.
The text was updated successfully, but these errors were encountered: