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

dynamically finding crs nodes from xml if matching with preferred crs. if not but has nodes then take first available node from xml. if none apply take our first preferred crs #416

Merged
merged 3 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Assets/_BuildingBlocks/OGCWebServices/Shared/BaseRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ protected string GetInnerTextForNode(XmlNode layerNode, string nodeName, bool se
}
}

//protected XmlNodeList GetNodesByName(XmlNode layerNode, string nodeName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Overbodige code?

//{
// var queryForNode = $"*[local-name()='{nodeName}']";
// return layerNode.SelectNodes($".//{queryForNode}", namespaceManager);
//}

protected XmlNodeList GetNodesByName(XmlNode layerNode, string nodeName)
{
var queryForNode = $"//*[local-name()='{nodeName}' or @*='{nodeName}']";
return layerNode.SelectNodes(queryForNode, namespaceManager);
}

protected XmlNode GetSingleNodeByName(XmlNode layerNode, string nodeName, bool searchInParents = false)
{
// Base query that will attempt to find the node; but we need more ...
Expand Down
34 changes: 27 additions & 7 deletions Assets/_Functionalities/Wms/Scripts/WmsGetCapabilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class WmsGetCapabilities : BaseRequest, IGetCapabilities
{
public Uri GetCapabilitiesUri => Url;
public const string DefaultFallbackVersion = "1.3.0";
private string[] preferredCRS = { "EPSG:28992", "EPSG:4326", "CRS:84" };

public ServiceType ServiceType => ServiceType.Wms;
protected override Dictionary<string, string> defaultNameSpaces => new()
Expand Down Expand Up @@ -184,13 +185,32 @@ public List<MapFilters> GetMaps(int width, int height, bool transparent)
// Extract styles for the layer
var styles = ExtractStyles(mapNode);

// CRS/SRS may be defined in the current MapNode, but can also inherit from a parent if it is not
// specified the flag at the end of this function will check the current node and its parents
var spatialReference = GetInnerTextForNode(mapNode, mapTemplate.spatialReferenceType, true);

// TODO: Really ugly fix to deal issues around EPSG:4326. So we fixate on CRS:84 now, hoping that will
// work in all situations
spatialReference = "CRS:84";
string spatialReference = null;
var spatialReferenceType = MapFilters.SpatialReferenceTypeFromVersion(new Version(mapTemplate.version));
XmlNodeList crsNodes = GetNodesByName(mapNode, spatialReferenceType);
if (crsNodes.Count > 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Als je dit in een methode plaatst dan kan dat leesbaarder en kan je het gebruik van GOTO vermijden omdat je op die plek een return kan doen. Tevens kan het nesting niveau omlaag door het gebruik van early return


{
for (int i = 0; i < preferredCRS.Length; i++)
{
foreach (XmlNode crsNode in crsNodes)
{
if (preferredCRS[i] == crsNode.InnerText)
{
spatialReference = crsNode.InnerText;
goto referenceFound;
}
}
}
if (string.IsNullOrEmpty(spatialReference))
{
spatialReference = crsNodes[0].InnerText;
Copy link
Contributor

Choose a reason for hiding this comment

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

Dit geeft niet de eerste ondersteunde CRS terug maar de eerste in de set crsNodes, zie AC 3. Dit kan een ongeldige situatie opleveren

}
}
if(string.IsNullOrEmpty(spatialReference))
{
spatialReference = preferredCRS[0];
}
referenceFound:

var map = new MapFilters()
{
Expand Down
Loading