-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: main
Are you sure you want to change the base?
Conversation
- 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.
There was a problem hiding this 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))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about?
if (geometry && ((geometry instanceof Object && typeof geometry === 'object') || geometry(feature))) { | |
if (geometry && ((typeof geometry === 'object') || typeof geometry === 'function')) { |
There was a problem hiding this comment.
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.
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.