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

Support function in geometries: #40

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

ltkum
Copy link

@ltkum ltkum commented Oct 17, 2024

  • Issue : in some cases, the style.getGeometry() function would return a function rather than an object, causing issues when trying to set the geometry later in the code as we were calling geometry(undefined) instead of geometry(feature).

  • Fix : we check that the geometry is either an object, or a function which returns a non-null / non-undefined value, and we also use the function the geometry contains when it's not an Object.

- Issue : in some cases, the style.getGeometry() function would return a function rather than an object, causing issues when trying to set the geometry later in the code as we were calling geometry(undefined) instead of geometry(feature).

- Fix : we check that the geometry is either an object, or a function which returns a non-null / non-undefined value, and we also use the function the geometry contains when it's not an Object.
Copy link
Member

@ger-benjamin ger-benjamin left a comment

Choose a reason for hiding this comment

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

Looks good, thanks

// In some cases, the geometries are objects, in other cases they're features.
// We need to make sure that either the geometry is an object, or that the feature it contains returns
// a non-null / non-undefined value.
if (geometry && ((geometry instanceof Object && typeof geometry === 'object') || geometry(feature))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What about?

Suggested change
if (geometry && ((geometry instanceof Object && typeof geometry === 'object') || geometry(feature))) {
if (geometry && ((typeof geometry === 'object') || typeof geometry === 'function')) {

Copy link
Author

Choose a reason for hiding this comment

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

That would optimize a bit this check, but wouldn't ensure that the geometry the function returns is defined, which would cause issues a bit further. I would however mix them together like so :
if (geometry && ((typeof geometry === 'object' && geometry instanceof Object) || (typeof geometry === 'function' && geometry(feature)))

this would ensure that we ensure both that it is a function and that its result is defined.

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