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

Merged
merged 3 commits into from
Nov 4, 2024
Merged

Support function in geometries: #40

merged 3 commits into from
Nov 4, 2024

Conversation

ltkum
Copy link
Contributor

@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

src/VectorEncoder.ts Outdated Show resolved Hide resolved
'We make the check a tiny bit more torough to avoid some potential crashes down the line
@ltkum ltkum requested a review from gberaudo October 28, 2024 10:24
@gberaudo
Copy link
Contributor

Hi @ltkum ,

I propose this rewrite:

      if (typeof geometry === 'function') {
          geometry = geometry(feature);
     }
     if (typeof geometry === 'object') {
        const styledFeature = feature.clone();
        styledFeature.setGeometry(geometry);
        geojsonFeature = this.geojsonFormat.writeFeatureObject(styledFeature);
        geojsonFeatures.push(geojsonFeature);
      } else {

@gberaudo gberaudo merged commit d306253 into geoblocks:main Nov 4, 2024
@gberaudo
Copy link
Contributor

gberaudo commented Nov 4, 2024

Thanks @ltkum !

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