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

Feature/1099 infoclick parse xml #1256

Merged
merged 9 commits into from
Jan 12, 2023
Merged

Conversation

linusfj
Copy link
Member

@linusfj linusfj commented Dec 15, 2022

Closes #1099.

Parse XML data and use the attributes of the FIELDS element as feature properties.
Parse XML and return an array of features.
In cases where the xml have no FIELDS element, the xml is parsed as gml.
@jacobwod
Copy link
Member

Ready for review and merge @linusfj? In that case, please request a reviewer in the side panel.

@linusfj
Copy link
Member Author

linusfj commented Dec 19, 2022

Yes, it is ready for review, and I've requested reviewers.

@jacobwod jacobwod added the needs testing in rc Indicates extensive and potentially breaking changes that will need an extra attention during RC. label Jan 5, 2023
Copy link
Member

@jacobwod jacobwod left a comment

Choose a reason for hiding this comment

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

A couple of questions follow.

Why do we need a custom XML parser here? Wouldn't the way shown in OL example be sufficient enough? Is the response malformed in some way?

Comment on lines 307 to 326
case "text/xml": {
featurePromises.push(
response.value.requestResponse
.text()
.then((text) => {
if (text !== undefined && text) {
features.push(
...getFeaturesFromXml(response.value, text)
);
}
})
.catch((err) => {
console.error(
"GetFeatureInfo couldn't retrieve correct data for the clicked object.",
err
);
})
);
break;
}
Copy link
Member

Choose a reason for hiding this comment

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

Also, this part looks very much like the next that follows, the only difference being which parser is used depending on XML or GML, i.e. lines 314 and 332. The rest is just the same so consider refactoring.

@linusfj
Copy link
Member Author

linusfj commented Jan 9, 2023

The response from the WMS example in issue #1099 was not displayed correctly in the infoclick dialog. It appears that this issue is specific to WMS layers that use ArcGIS server, and it is still present in the new version of the infoclick function.

linusfj and others added 2 commits January 9, 2023 14:18
- Sorting of features does not mutate the array. Insteand it returns a new array.
- const is used where appropiate
- Minor esthetic changes.
@jacobwod
Copy link
Member

Check it out now and see if it works as intended for you.

@jacobwod
Copy link
Member

Please confirm when you've tested the latest commits @linusfj.

@linusfj
Copy link
Member Author

linusfj commented Jan 10, 2023

It seems to not be working, when clicking on a feature an error message appears:
GetFeatureInfo could not retrieve the correct information for the selected object.

@jacobwod
Copy link
Member

OK, take a look at what it is and try to fix it. I could not reproduce the error you mention on my side.

Fix bug in multiple functions where returned arrays were not sorted in place. Updated code to sort original arrays and return them with expected values.
@linusfj
Copy link
Member Author

linusfj commented Jan 11, 2023

The issue has been fixed and the code can be merged.

@jacobwod
Copy link
Member

OK, good find. Since we're now not using the return value form sortFeatures, could you please remove the return statement in that function?

If you want to make it even nicer, you can rename sortFeatures to something like sortAndMutateFeaturesArray (but that's purely optional of course). 👍

- Changed variables 'parsed' to 'features'.
- Changed function name 'sortFeatures' to 'sortAndMutateFeaturesArray'.
- Used `.map()` function to add the `layer` property to each feature.
- Removed return statements.
- Modified the array `features` to be defined as `let` instead of `const`, since it can be reassigned with new values.
@linusfj linusfj requested a review from jacobwod January 12, 2023 10:34
Copy link
Member

@jacobwod jacobwod 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!

@jacobwod
Copy link
Member

Btw, this is not part of this issue but I'll post it here: as I reviewed the code, it seems to look like the sorting algorithm only takes place in Click.js, while the new implementation in MapClickModel.js doesn't have the same sorting. Have you seen any difference in the results you get when toggling the useNewInfoclick flag in settings? If there is a difference, this will become an issue at some point in time, when those using the "old" infoclick choose to upgrade to the "new" method. If sorting is not implemented by then, the upgrade will have the side-effect of results being sorted differently.

As I said, not part of this PR (it's ready to merge in my opinion). But I wonder what you think of it?

@linusfj
Copy link
Member Author

linusfj commented Jan 12, 2023

I've only tested the new infoclick version using a few layers with different data formats that we initially had problems with, and it was returning the correct results in those cases.

The new implementation in MapClickModel.js seems to be handling it well, but we should do more testing to ensure it works in all cases.

@linusfj
Copy link
Member Author

linusfj commented Jan 12, 2023

Merging pull request.

@linusfj linusfj merged commit fd742bb into develop Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs testing in rc Indicates extensive and potentially breaking changes that will need an extra attention during RC.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants