Skip to content

Commit

Permalink
fix-first-where-style
Browse files Browse the repository at this point in the history
  • Loading branch information
cledson.junior committed Nov 21, 2024
1 parent a0dfd63 commit b01ab48
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/src/kml_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ class KmlReader {
return metadata;
}

String _convertHtmlToText(String input) {
input = input.replaceAll(RegExp(r'<br\s*/?>', caseSensitive: false), '\n');

final htmlTagRegex = RegExp(r'<[^>]*>');
return input.replaceAll(htmlTagRegex, '').trim();
}

Future<GeoObject> _readPlacemark(
StreamIterator<XmlEvent> iterator, String tagName, GeoXml geoXml) async {
final item = GeoObject();
Expand All @@ -162,7 +169,8 @@ class KmlReader {
item.name = await _readString(iterator, val.name);
break;
case KmlTag.desc:
item.desc = await _readString(iterator, val.name);
final rawDesc = await _readString(iterator, val.name);
item.desc = rawDesc != null ? _convertHtmlToText(rawDesc) : null;
break;
case GpxTag.desc:
item.desc = await _readString(iterator, val.name);
Expand Down Expand Up @@ -229,8 +237,10 @@ class KmlReader {
styleUrl = styleUrl.substring(1);
}

style = geoXml.styles
.firstWhere((element) => element.id == styleUrl);
style = geoXml.styles.firstWhere(
(element) => element.id == styleUrl,
orElse: GeoStyle.new,
);
}
break;
}
Expand Down

0 comments on commit b01ab48

Please sign in to comment.