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

Added geoJSON source getBounds method #5403

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

Conversation

AbelVM
Copy link

@AbelVM AbelVM commented Jan 24, 2025

Resolves #5394

Signed-off-by: Abel Vázquez Montoro <abel.vm@gmail.com>
@HarelM
Copy link
Collaborator

HarelM commented Jan 24, 2025

There are problems with transpiling the code, and some nitpicking, but otherwise this looks good, thanks!

dependabot bot and others added 7 commits January 27, 2025 03:31
Bumps [dependabot/fetch-metadata](https://github.com/dependabot/fetch-metadata) from 2.2.0 to 2.3.0.
- [Release notes](https://github.com/dependabot/fetch-metadata/releases)
- [Commits](dependabot/fetch-metadata@v2.2.0...v2.3.0)

---
updated-dependencies:
- dependency-name: dependabot/fetch-metadata
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [stylelint](https://github.com/stylelint/stylelint) from 16.13.2 to 16.14.0.
- [Release notes](https://github.com/stylelint/stylelint/releases)
- [Changelog](https://github.com/stylelint/stylelint/blob/main/CHANGELOG.md)
- [Commits](stylelint/stylelint@16.13.2...16.14.0)

---
updated-dependencies:
- dependency-name: stylelint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [@vitest/ui](https://github.com/vitest-dev/vitest/tree/HEAD/packages/ui) from 3.0.3 to 3.0.4.
- [Release notes](https://github.com/vitest-dev/vitest/releases)
- [Commits](https://github.com/vitest-dev/vitest/commits/v3.0.4/packages/ui)

---
updated-dependencies:
- dependency-name: "@vitest/ui"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@AbelVM
Copy link
Author

AbelVM commented Jan 27, 2025

Changes committed and changelog message added 🤓

@AbelVM AbelVM changed the title [DRAFT] added geoJSON source getBounds method Added geoJSON source getBounds method Jan 27, 2025
package.json Outdated Show resolved Hide resolved
@AbelVM
Copy link
Author

AbelVM commented Jan 27, 2025

Ok, something is weird here. It looks like getData() is coded to return GeoJSON.GeoJSON but it's returning GeoJSON<Geometry, { [name: string]: any; }> instead, breaking the tests.

Any help is welcome

@HarelM
Copy link
Collaborator

HarelM commented Jan 27, 2025

GeoJson.Geojson is both feature collection and feature. You need to check which one you received and act accordingly.

Copy link

codecov bot commented Jan 27, 2025

Codecov Report

Attention: Patch coverage is 8.10811% with 34 lines in your changes missing coverage. Please review.

Project coverage is 91.86%. Comparing base (bedcb86) to head (99a7b9e).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
src/source/geojson_source.ts 8.10% 34 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5403      +/-   ##
==========================================
- Coverage   91.94%   91.86%   -0.09%     
==========================================
  Files         282      282              
  Lines       39039    39076      +37     
  Branches     6849     6849              
==========================================
+ Hits        35896    35897       +1     
- Misses       3016     3051      +35     
- Partials      127      128       +1     

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

@AbelVM
Copy link
Author

AbelVM commented Jan 27, 2025

Ok, it looks fine now

@HarelM
Copy link
Collaborator

HarelM commented Jan 28, 2025

Try adding a test to the browser.test.ts (integration tests) instead of unit test, it might be easier...

@AbelVM
Copy link
Author

AbelVM commented Jan 28, 2025

Same results

@HarelM
Copy link
Collaborator

HarelM commented Jan 28, 2025

Can't help with a code I can't see, try checking it in so that I can take a look...

@AbelVM
Copy link
Author

AbelVM commented Jan 28, 2025

Sorry, I tested it locally. Now its uploaded

@AbelVM
Copy link
Author

AbelVM commented Jan 28, 2025

Ok, now everything related to this feature is working as expected 🎉

Coverage is low because there's no unit test as they're run as integration tests. I have no idea how to improve that, as getData() doesn't work within unit tests

center: [10, 10],
zoom: 10
});
map.on('load', () => {
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 once(...) to make less indentation and make sure the test waits from the map to load.

Copy link
Author

Choose a reason for hiding this comment

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

done

Copy link
Author

Choose a reason for hiding this comment

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

It looks like await map.once('load'); doesn't work as expected.

I need to move back to map.on('load' =>{...})

(and we might need to change the behavior of once() to reflect the one of on())

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure what you are talking about, the unit tests are filled with await once('load');, here's one for example:

await map.once('load');

Copy link
Author

@AbelVM AbelVM Jan 28, 2025

Choose a reason for hiding this comment

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

I'm just posting the errors the tests gave me (commit 6db23408202feea1a9967c083fb07a06b0a9b8db) in a human-readable way.

I've gone to check that weirdness in the documentation, and those in my message above are the links 🤷

Copy link
Collaborator

Choose a reason for hiding this comment

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

on amd once are different...
Using await on(...) shouldn't work as it's not designed to work this way.
Regarding the tests failures after the once change, the error message indicate that the expected object is "{}" which I find odd, regardless of the test failure. I would advise to try and run this code is a jsbin and see how it works, and after it works as expected, copy it to this file...

Copy link
Collaborator

Choose a reason for hiding this comment

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

getData is using messages to communicate with workers, so it you want to use that, you'll need to mock the workers communication since it's running in node environment and not in the browser.
When running things in the browser I expect it to just work, like it does in the examples we have in the docs, which uses this kind of await once code...

Copy link
Author

Choose a reason for hiding this comment

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

Both bounds and testbounds are being used with their default values because await map.once() is not working as expected and... just doesn't wait 😅 So the flow reaches the assessment but the code to get the bounds has not run

The problem I found with the tests is that running them locally or even building sample code, behaves differently than within the contexts that Jenkins/GH Actions/Whatever uses. I get different errors, messages, and so on. That's why I'm sending too many commits, to getting actionable information from the online tests that I don't get locally

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not resolved.
Please try and use codespaces if you can't reproduce the issue locally...

Copy link
Author

Choose a reason for hiding this comment

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

Any help is welcome, I wasn't able to make the integration tests work using await map.once().

In that very same file, the pattern is map.once('load', callback) (even when load event is not supported, as per the docs, by map.once)

map.once('load', () => resolve());

'properties': {},
'geometry': {
'type': 'LineString',
'coordinates': [
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can the geometry be simplified (2-3 points)?

Copy link
Author

Choose a reason for hiding this comment

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

Sure, but I've just reused the data in the unit tests

Copy link
Collaborator

Choose a reason for hiding this comment

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

Then the data there probably needs simplification as well...

Copy link
Author

Choose a reason for hiding this comment

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

Done

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see it... Did you forget to push?

Copy link
Author

Choose a reason for hiding this comment

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

const bounds: LngLatBounds = new LngLatBounds();
const data: GeoJSON.GeoJSON = await this.getData();
let coordinates: number[];
if (!!data) return bounds;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure this is what I would expect as a return value...

Copy link
Author

@AbelVM AbelVM Jan 30, 2025

Choose a reason for hiding this comment

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

IMHO, if the source has no data, its bounding box should be empty

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.

Add getBounds() method to geoJSON sources
2 participants