loadData method
Implementation
@override
FutureOr<Map<String, dynamic>> loadData() async {
String content;
try {
final uri = Uri.base.resolve(url);
final request = await _httpClient.getUrl(uri);
headers.forEach((k, v) {
request.headers.add(k, v);
});
final response = await request.close();
if (response.statusCode != HttpStatus.ok) {
await response.drain([]);
throw GeoJsonLoadException(
"Error requesting GeoJSON from $url: HTTP ${response.statusCode}");
}
content = await response.transform(utf8.decoder).join();
} on Exception catch (e) {
if (e is GeoJsonLoadException) rethrow;
throw GeoJsonLoadException("Error downloading GeoJSON from $url: $e");
}
dynamic data;
try {
data = json.decode(content);
} on Exception catch (e) {
throw GeoJsonLoadException("Error parsing GeoJSON: $e");
}
_validateGeoJson(data);
return data;
}