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

docs: Viewport elevation control #9313

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

charlieforward9
Copy link

@charlieforward9 charlieforward9 commented Dec 20, 2024

Closes #9273
Linked to visgl/loaders.gl#3178

Background

I could not figure out how to control the view state when rendering Tile3dLayers in Montana, well above sea level. When I filed a report, I was told:

Does position: [0, 0, elevation]; work for you?

The MapViewState.position documentation did not specify elevation, leading me to overlooking it and ultimately filing this bug.

Adding some docs and using a stricter type would enhance DX.

Change List

  • MapViewState.position: number[] to [number, number, number]
  • ... TODO

@charlieforward9
Copy link
Author

With this out of the way, can someone please help me figure out why the triplayer doesnt update properly #9260

modules/core/src/views/map-view.ts Show resolved Hide resolved
@charlieforward9
Copy link
Author

@felixpalmer I see you rebased but may have forgotten to rerun the checks?

@felixpalmer
Copy link
Collaborator

The "new merge experience" helpfully hides that button 🙄

@felixpalmer
Copy link
Collaborator

@charlieforward9 can you run yarn test browser locally?

@charlieforward9
Copy link
Author

charlieforward9 commented Jan 8, 2025

@felixpalmer I can, I get strange results though.

A bunch of Errors occur to unrelated modules in the repo, and it stops running at jupyter-widget Render Test Jupyter#ScatterplotLayer, logging: Failed to load url /modules/jupyter-widget/dist/index.js (resolved id: /modules/jupyter-widget/dist/index.js). Does the file exist?. When I try to build the jupyter widgets module, I get more problems.

I am able to find the remaining build errors much easier by running yarn run build

@felixpalmer
Copy link
Collaborator

Yes, the local test runs can sometimes throw up spurious errors. In general, if the CI isn't failing, but locally it is, then as a first step you can disable the test by commenting it out. Obviously if you can find the root cause, even better - but don't let it derail this PR

@@ -241,7 +241,7 @@ export default class Tile3DLayer<DataT = any, ExtraPropsT extends {} = {}> exten
return;
}

// eslint-disable-next-line @typescript-eslint/no-floating-promises
//@ts-expect-error Type 'Vector3' is not assignable to type '[number, number, number]'
Copy link
Author

Choose a reason for hiding this comment

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

Got this error and didnt want to go down the rabbit hole of enforcing only [number, number, number]. What do you advise? @felixpalmer

Copy link
Author

Choose a reason for hiding this comment

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

Furthermore, there was a type mismatch error between the viewport defined here and a viewport type defined in @loaders.gl, since the project/unproject method signatures are changing from number[] to [number, number, number]. Seems like a PR needs to be made in the @loaders.gl repo as well.

Copy link
Author

@charlieforward9 charlieforward9 Jan 8, 2025

Choose a reason for hiding this comment

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

I believe to have broken something cause now the test hangs on the Tile3DLayer initial load step and I do not get an error message... meanwhile, yarn run build completes successfully.

Copy link
Author

Choose a reason for hiding this comment

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

Opened visgl/loaders.gl#3178 to address this.

Copy link
Collaborator

@chrisgervang chrisgervang left a comment

Choose a reason for hiding this comment

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

Thank you for your continued work around auditing these types. It looks like the proposal has expanded a bit to include some API changes, which could mean waiting to release this PR in the next major version just so that we're not surprising users with a breaking change in a minor release.

For a patch or minor release, you could consider how to split out the doc and type changes into their our PR.

Thanks for understanding. Any sub-set of these improvements will be widely appreciated.

docs/upgrade-guide.md Outdated Show resolved Hide resolved
return xyz.length === 2 ? [x, y] : [x, y, z];
return [x, y, z];
Copy link
Collaborator

Choose a reason for hiding this comment

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

I consider this a breaking API change. Could xyz be typed as [number, number] | [number, number, number]?

Not saying yet that we can't make this API change, but generally we'll tradeoff type safety to preserve the API, and not the other way around.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Even that will be breaking change as many people out there are likely passing a number[] and will need to add a cast. I would suggest using a function overload, something like:

function project(xyz: [number, number]): [number, number];
function project(xyz: [number, number, number]): [number, number, number];
function project(xyz: Vector2Or3): Vector2Or3 {

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also we haven't got around to using them everywhere yet, but we have helper types like NumberArray2 that you could use here

modules/core/src/viewports/globe-viewport.ts Outdated Show resolved Hide resolved
@charlieforward9
Copy link
Author

@chrisgervang I adjusted most of the review comments. I will not be able to commit to dividing this PR. However, I'd love to become a contributor to this repo, and am patient to wait to see this land till the next major release. In the meantime, I am more than willing to fortify the current changes to be as clear as possible for when it does land.

Thank you for the review!

@charlieforward9 charlieforward9 changed the title docs: elevation control in MapViewState docs: Viewport elevation control Jan 8, 2025
charlieforward9 added a commit to NEW-HEAT/loaders.gl that referenced this pull request Jan 8, 2025
return xyz.length === 2 ? [x, y] : [x, y, z];
return [x, y, z];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Even that will be breaking change as many people out there are likely passing a number[] and will need to add a cast. I would suggest using a function overload, something like:

function project(xyz: [number, number]): [number, number];
function project(xyz: [number, number, number]): [number, number, number];
function project(xyz: Vector2Or3): Vector2Or3 {

@@ -143,7 +143,7 @@ export default class GridLayer<DataT = any, ExtraPropsT extends {} = {}> extends
getValue: ({positions}: {positions: number[]}, index: number, opts: BinOptions) => {
const viewport = this.state.aggregatorViewport;
// project to common space
const p = viewport.projectPosition(positions);
const p = viewport.projectPosition([positions[0], positions[1], positions[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.

The original motivation for this PR is to improve the types, so I would avoid changing the implementation. Adding type casts or better types is great, but you should avoid anything that will modify the behavior at runtime as there is a risk of introducing bugs

@@ -272,7 +275,7 @@ export default class GridLayer<DataT = any, ExtraPropsT extends {} = {}> extends
binIdRange = getBinIdRange({
dataBounds: bounds,
getBinId: (p: number[]) => {
const positionCommon = viewport.projectFlat(p);
const positionCommon = viewport.projectFlat([p[0], p[1]]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment as above, better to do p as NumberArray2

return xyz.length === 2 ? [x, y] : [x, y, z];
return [x, y, z];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also we haven't got around to using them everywhere yet, but we have helper types like NumberArray2 that you could use here

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.

[Feat] elevation field in MapViewState
4 participants