parseCampusMapLayers function
- String source
Parses indoor layers from a WFS capabilities document, independent of prefix.
Throws FormatException if the server returned an exception document or no indoor layers. Unrelated GIS layers are ignored.
Implementation
List<CampusMapLayerDto> parseCampusMapLayers(String source) {
final document = XmlDocument.parse(source);
final layers = <CampusMapLayerDto>[];
for (final element in document.descendants.whereType<XmlElement>()) {
if (element.name.local != 'FeatureType') continue;
final name = element.childElements
.where((child) => child.name.local == 'Name')
.firstOrNull
?.innerText
.trim();
if (name == null) continue;
if (campusMapLayerPattern.firstMatch(name) case final match?) {
layers.add((name: name, buildingCode: match[1]!, floor: match[2]!));
}
}
if (layers.isEmpty) throw const FormatException('No indoor WFS layers');
return layers;
}