Skip to content
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

Fix accuracy circle turf geojson #5543

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

geekdenz
Copy link
Contributor

@geekdenz geekdenz commented Feb 24, 2025

This PR takes up some of the work that was already done here:
#5440

The goal not finalised yet, is to get to a mergable PR.

Launch Checklist

  • Confirm your changes do not include backports from Mapbox projects (unless with compliant license) - if you are not sure about this, please ask!
  • Briefly describe the changes in this PR.
  • Link to related issues.
  • Include before/after visuals or gifs if this PR includes visual changes.
  • Write tests for all new functionality.
  • Document any changes to public APIs.
  • Add an entry to CHANGELOG.md under the ## main section.

Copy link

codecov bot commented Feb 25, 2025

Codecov Report

Attention: Patch coverage is 32.33083% with 180 lines in your changes missing coverage. Please review.

Project coverage is 69.35%. Comparing base (18beec0) to head (778a418).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/util/turf-helpers.ts 21.31% 88 Missing and 8 partials ⚠️
src/util/destination.ts 26.31% 28 Missing ⚠️
src/util/invariant.ts 21.21% 26 Missing ⚠️
src/util/circle.ts 10.71% 24 Missing and 1 partial ⚠️
src/ui/control/geolocate_control.ts 88.88% 5 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (18beec0) and HEAD (778a418). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (18beec0) HEAD (778a418)
9 8
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #5543       +/-   ##
===========================================
- Coverage   91.96%   69.35%   -22.62%     
===========================================
  Files         282      286        +4     
  Lines       39077    39317      +240     
  Branches     6873     1359     -5514     
===========================================
- Hits        35939    27268     -8671     
- Misses       3010    11398     +8388     
- Partials      128      651      +523     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@geekdenz
Copy link
Contributor Author

geekdenz commented Feb 25, 2025

@HarelM @zhangyiatmicrosoft

Is it reasonable to increase the bundle size with the small turfjs library?

expected 912743 to be less than 910819
It's about 2kb.

Later we may want to introduce parts of proj4js as well. I am wondering if it is a good way forward to accept small parts of other libraries in the build.

CHANGELOG.md Outdated
@@ -15,6 +15,7 @@
- Avoid setting marker opacity twice. ([#5441](https://github.com/maplibre/maplibre-gl-js/pull/5441))

### 🐞 Bug fixes
- Fix location accuracy circle radius when moving view ([#5543](https://github.com/maplibre/maplibre-gl-js/pull/5543))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be here, but upwards instead...

package.json Outdated
@@ -55,6 +55,8 @@
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^12.1.2",
"@stylistic/eslint-plugin-ts": "^4.0.1",
"@turf/circle": "^7.2.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be under dependencies instead of here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking the same but it works and you cannot access turf outside of the build. But I will change it anyway. Maybe something to think about.

@@ -610,6 +588,11 @@ describe('GeolocateControl with no options', () => {
map.addControl(geolocateControl);
// adding and removing to verify there is no race condition, and it is just added once
map.removeControl(geolocateControl);
await map.once('loaded', async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use:

await map.once('loaded');
const accuracyElementsOnPage = ...

@@ -265,7 +267,7 @@ export class GeolocateControl extends Evented implements IControl {
_watchState: 'OFF' | 'ACTIVE_LOCK' | 'WAITING_ACTIVE' | 'ACTIVE_ERROR' | 'BACKGROUND' | 'BACKGROUND_ERROR';
_lastKnownPosition: any;
_userLocationDotMarker: Marker;
_accuracyCircleMarker: Marker;
_accuracyCirclePolygon: any;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why any?

@@ -38,7 +38,7 @@ describe('test min build', () => {
const decreaseQuota = 4096;

// feel free to update this value after you've checked that it has changed on purpose :-)
const expectedBytes = 909795;
const expectedBytes = 912743;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to think this is an overkill for such a small fix.
While the package size does grow over time, I'm not sure this component (which can be easily replaced by any app that requires better control over the UX) should cause this kind of change.
Can we write something simpler that doesn't require all the complexity of turf circle?
We did the same for simple ruler for example, where we took only the relevant functionality to reduce bundle increase...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn' t this the way this fix was intended though. I am not sure if it should have turf in the title if it is not a fix using turf.

Should there maybe be an entirely new PR then?

Also, I don't know how to easily achieve a circle without turf. But I can look into it if that is what is best and desired now. Please let me know what you decide. I would recommend we accept the small increase but I wouldn't insist if bundle size is this important.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having thought about it again, I believe this just creates a Feature for you. I can think of how to do that directly with GeoJSON.

@geekdenz geekdenz force-pushed the fix-accuracy-circle-turf-geojson branch from 4613fac to d28b3f7 Compare March 1, 2025 05:05
@geekdenz geekdenz force-pushed the fix-accuracy-circle-turf-geojson branch from 43f32d6 to c8c1d5e Compare March 1, 2025 05:35
@geekdenz geekdenz force-pushed the fix-accuracy-circle-turf-geojson branch from 7cd4798 to 778a418 Compare March 2, 2025 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants