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: make draganddrop use existing style function for features withou… #1943

Merged
merged 2 commits into from
Mar 11, 2024

Conversation

Grammostola
Copy link
Contributor

@Grammostola Grammostola commented Jan 11, 2024

…t a defined style. Seeks to fix #1935 . (The fix includes attempting to make kml files that from what I gather employ their own style not have the wrong legend. Yes it is a bonus, I was testing my proposed fix with different file formats. It can be removed.)

Creds to @jokd for the idea.

Edit. In contrast to merely extending the list of predefined featureStyles this solution will not provide a layer legend. However since featureStyles will take precedence one needs only to define these for the dragndrop control.

@johnnyblasta
Copy link
Collaborator

Tested with a KML and got a error.
image

Fixed it with this code with a check if geometry exists, on row 128 in draganddrop.js:

            if (feature.getGeometry() !== null) {
				const geometryType = feature.getGeometry().getType();
				if (featureStyles && featureStyles[geometryType]) {
				  if (!types.has(geometryType)) {
					styles.push(...featureStyles[geometryType]);
					types.add(geometryType);
				  }
				} else {
				  getStyleFunction(feature);
				}
            }

@Grammostola
Copy link
Contributor Author

Cheers, I hadn't thought of adding a layer without geometry. What usage scenario are you thinking of? Feel free to push the proposed fix for that anyway.

@johnnyblasta
Copy link
Collaborator

Cheers, I hadn't thought of adding a layer without geometry. What usage scenario are you thinking of? Feel free to push the proposed fix for that anyway.

I had a KML which was exported from Autocad which apparently had some placemark without geometry. Don't know why that is, but would be nice if it can handle empty geometry without crashing.

@johnnyblasta
Copy link
Collaborator

@Grammostola made a commit in your branch.

Copy link
Collaborator

@johnnyblasta johnnyblasta left a comment

Choose a reason for hiding this comment

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

LGTM

@johnnyblasta johnnyblasta added the PR approved To highlight approved PR:s as it is not shown in list which are approved. label Mar 11, 2024
@Grammostola
Copy link
Contributor Author

I had a KML which was exported from Autocad which apparently had some placemark without geometry. Don't know why that is, but would be nice if it can handle empty geometry without crashing.

Indeed, nice testing!

@Grammostola Grammostola merged commit e72afe3 into master Mar 11, 2024
4 checks passed
@Grammostola Grammostola deleted the dragdrop_style_fix branch March 11, 2024 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR approved To highlight approved PR:s as it is not shown in list which are approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Drag and drop styles for more geometry types would be a boon
2 participants