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

feat(mapbox): support Maplibre globe projection #9296

Merged
merged 3 commits into from
Jan 8, 2025

Conversation

Pessimistress
Copy link
Collaborator

For #9199

Note: requires #9295

Tested for overlaid and interleaved modes

Change List

  • MapboxOverlay switches views based on map projection mode

@Pessimistress Pessimistress force-pushed the x/mapbox-overlay-globe branch 2 times, most recently from faa9aed to 90eff32 Compare December 12, 2024 06:01
@coveralls
Copy link

coveralls commented Dec 12, 2024

Coverage Status

coverage: 91.674% (-0.03%) from 91.705%
when pulling d55d144 on x/mapbox-overlay-globe
into 1e8c2b2 on master.

@@ -58,6 +58,10 @@ export type GlobeViewportOptions = {
nearZMultiplier?: number;
/** Scaler for the far plane, 1 unit equals to the distance from the camera to the edge of the screen. Default `1` */
farZMultiplier?: number;
/** Optionally override the near plane position. `nearZMultiplier` is ignored if `nearZ` is supplied. */
Copy link
Collaborator

Choose a reason for hiding this comment

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

A bit nervous about having these overrides, especially as nearZ and nearZMultiplier do the same thing. Should we issue a warning if both are supplied?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree this can be confusing (and wasn't an easy thing to catch when I was first learning it). FWIW, web-mercator-viewport has had these same overrides for a long time.

A warning would be nice.. the multipliers have defaults assigned, so we'd just need to assign those after checking the user-supplied values (or else, they'd always print).

Copy link
Collaborator

Choose a reason for hiding this comment

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

This does look confusing and somewhat intimidating. I think these props were originally intended as a semi-undocumented escape hatch but now I seem to see these being "touched" in every PR...

If not a coincidence, might be good to audit this API with an eye towards making it as fail proof as possible for new (and old) users.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@ibgreen FWIW I was not changing them in my PR, that was just due to github getting confused. See updated PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In deck.gl terms, *ZMultiplier is a ViewProp - you set it to a constant and the effect will be (somewhat) consistent across all camera positions. *Z is a ViewState - the proper value will be derived from zoom, pitch etc.

For example, MapView by default places the far plane at sea level on the top(far) edge of the viewport. In the earth quake example we set farZMultiplier to an arbitrary large number in order to display data points below the ocean surface.

Realistically, users almost never calculate the near/far planes manually. If they want to achieve a non-default effect, they will likely use *ZMultiplier. If they want to match an external camera (from base map, three.js, etc.) they set *Z values from an external source.

modules/mapbox/src/deck-utils.ts Outdated Show resolved Hide resolved
modules/mapbox/src/deck-utils.ts Show resolved Hide resolved

export function getDefaultView(map: Map): GlobeView | MapView {
if (getProjection(map) === 'globe') {
return new GlobeView({id: 'mapbox'});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Detect maplibre and instead call view 'maplibre'? Or choose a common name like 'map-overlay'?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We don't have a reliable way to detect mapbox vs maplibre, given that we also support a wide range of versions of each library.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree it's not the best name. Unfortunately, this is used in some edge cases... @chrisgervang

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it a question of whether this would be a breaking change for the multi-view edge cases?

modules/mapbox/src/mapbox-overlay.ts Show resolved Hide resolved
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.

Exciting support!

There's a lot of branching to support different API versions... at some point it'll be cleaner to maintain (and document) as two modules. But this is probably fine for 9.1

// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

import {MapboxOverlay as DeckOverlay} from '@deck.gl/mapbox';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why rename/alias things? If we are not happy with the name, rename it at export? If trying to make code clearer a longer name might be needed? Any name that mentions either just Deck or Mapbox is going to be confusing

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For legacy reasons we are exporting all integration classes into the global deck namespace. MapboxOverlay and GoogleMapsOverlay were named to differentiate from each other.

The proper naming convention should probably be something like deck.mapbox.DeckOverlay, deck.maplibre.DeckOverlay and deck.googlemaps.DeckOverlay.

I don't like the current state either, but 9.1 is not a good time to make breaking changes like this.

@@ -58,6 +58,10 @@ export type GlobeViewportOptions = {
nearZMultiplier?: number;
/** Scaler for the far plane, 1 unit equals to the distance from the camera to the edge of the screen. Default `1` */
farZMultiplier?: number;
/** Optionally override the near plane position. `nearZMultiplier` is ignored if `nearZ` is supplied. */
Copy link
Collaborator

Choose a reason for hiding this comment

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

This does look confusing and somewhat intimidating. I think these props were originally intended as a semi-undocumented escape hatch but now I seem to see these being "touched" in every PR...

If not a coincidence, might be good to audit this API with an eye towards making it as fail proof as possible for new (and old) users.

This was referenced Dec 13, 2024
@Pessimistress Pessimistress force-pushed the x/mapbox-overlay-globe branch from 6a24007 to d55d144 Compare January 7, 2025 05:40
@Pessimistress Pessimistress merged commit 22b68b0 into master Jan 8, 2025
4 checks passed
@Pessimistress Pessimistress deleted the x/mapbox-overlay-globe branch January 8, 2025 17:18
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.

5 participants