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

getFlatLayersArray() throws error #974

Closed
silvester-pari opened this issue May 21, 2024 · 3 comments
Closed

getFlatLayersArray() throws error #974

silvester-pari opened this issue May 21, 2024 · 3 comments
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request map

Comments

@silvester-pari
Copy link
Collaborator

The helper function getFlatLayersArray() sometimes fails since layers sometimes seems to be undefined and therefore can't be spread at:

flatLayers.push(...layers);

Uncaught (in promise) TypeError: layers is not iterable (cannot read property undefined)
@silvester-pari silvester-pari added bug Something isn't working map labels May 21, 2024
@RobertOrthofer RobertOrthofer self-assigned this Jul 2, 2024
@RobertOrthofer
Copy link
Contributor

The doc of the method is wrong, the getFlatLayersArray is meant as a convenience-functionality to flatten the given layers, not all layers of the map.

To get all layers of the map, the correct syntax would be

eoxMap.getFlatLayersArray(eoxMap.map.getAllLayers())

@silvester-pari silvester-pari added this to the [eox-map] v1.10.x milestone Jul 17, 2024
@silvester-pari
Copy link
Collaborator Author

silvester-pari commented Jul 17, 2024

Aah, that explains it! In that case, I'd propose to offer this functionality in a different way, since it probably doesn't make too much sense offering it as a property of the eox-map.

I propose to export it in the main file (e.g. export { getFlatLayersArray }) and expand the description in layer.ts to:

/**
 * Returns a flat array of provided layers, including groups
 * To get all layers without groups, you can use the native
 * OL `getAllLayers` method on the map itself:
 * https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html#getAllLayers
 * 
 * @param layers layers Array
 * @example getFlatLayersArray(eoxMap.map.getAllLayers())
 */

This needs adaptations in e.g. tests and is generally a breaking change, so moving this to v2 milestone.

Although we could add this now in an v1.x update, and deprecate the property with v2.

@silvester-pari silvester-pari added documentation Improvements or additions to documentation enhancement New feature or request and removed bug Something isn't working labels Jul 17, 2024
@silvester-pari
Copy link
Collaborator Author

The docs have been updated (a053bbb); for the general topic about exporting convenience functions, a new issue has been created: #1177

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request map
Projects
None yet
Development

No branches or pull requests

2 participants