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

fix: drawGeojsonData should accept "Feature" and "FeatureCollection" data since introducing drawMany #491

Merged
merged 2 commits into from
Sep 2, 2024

Conversation

jessicamcinchak
Copy link
Member

@jessicamcinchak jessicamcinchak commented Sep 2, 2024

Required to make drawing data "go back-able" in Planx when drawMany is true.

This was missed when introducing drawMany prop - drawGeojsonData was only accepting/processing a single "Feature" and would fail if the passed in prop was a GeoJSON "FeatureCollection" - now account for either, same as geojsonData

Copy link

netlify bot commented Sep 2, 2024

Deploy Preview for oslmap ready!

Name Link
🔨 Latest commit ab6ecc5
🔍 Latest deploy log https://app.netlify.com/sites/oslmap/deploys/66d5a38050f846000882d01c
😎 Deploy Preview https://deploy-preview-491--oslmap.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@jessicamcinchak jessicamcinchak marked this pull request as ready for review September 2, 2024 11:40
@jessicamcinchak jessicamcinchak requested a review from a team September 2, 2024 11:40
Copy link
Contributor

@RODO94 RODO94 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 to me to switch from pulling in a feature to using a FeatureCollection like in geoJsonData prop.

Only had one question relating to adding a Feature or Features, mostly curious about the structuring of the code.

const geojsonSource = new VectorSource();

if (this.geojsonData.type === "FeatureCollection") {
let features = new GeoJSON().readFeatures(this.geojsonData, {
featureProjection: "EPSG:3857",
});
geojsonSource.addFeatures(features);
geojsonSource.setAttributions(this.geojsonDataCopyright);
} else if (this.geojsonData.type === "Feature") {
let feature = new GeoJSON().readFeature(this.geojsonData, {
featureProjection: "EPSG:3857",
});
geojsonSource.addFeature(feature);
Copy link
Contributor

Choose a reason for hiding this comment

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

Took me a second to realise the differences between these parts. Is the need for two different functions relate to one accessing the Features array of a FeatureCollection and the other just taking the Feature as an object, or is there another reason for having two different functions / if clauses?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes exactly OpenLayers provides different methods depending if GeoJSON is single Feature or a FeatureCollection, and we want to keep our public-facing prop flexible to accepting eithe, therefore we do this conditional check !

@jessicamcinchak jessicamcinchak merged commit fbf0373 into main Sep 2, 2024
5 checks passed
@jessicamcinchak jessicamcinchak deleted the jess/fix-drawGeojsonData branch September 2, 2024 15:35
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.

2 participants