I found some interesting issue today that breaks behavior of GeoJSONFeature.fromMap(...)
The issue is happening because empty map like {} has type _InternalLinkedHashMap and not Map (like maps from JSON converting) and so feature with empty map in "properties" field creates this error:
Unhandled exception:
type '_InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'Map<String, dynamic>?'
#0 new GeoJSONFeature.fromMap package:geojson_vi/…/classes/feature.dart:51
but map like <String, dynamic>{} works well because it has type Map<String, dynamic> and it is ok. Omitting "properties" field and non empty maps works well too.
Issue also happens with GeoJSONFeatureCollection.fromMap(...) since it uses GeoJSONFeature.fromMap(...).
It can be fixed quite easily with explicit map casting using Map.castFrom(...) so empty "properties" map will work well too, so I made this fix in this pull request: In file lib/src/classes/feature.dart in line 51 I changed map['properties'] to Map.castFrom(map['properties']) so it always will be converted to Map<String, dynamic> before passing into GeoJSONFeature constructor.
About the issue
I found some interesting issue today that breaks behavior of
GeoJSONFeature.fromMap(...)
The issue is happening because empty map like{}
has type_InternalLinkedHashMap
and notMap
(like maps from JSON converting) and so feature with empty map in "properties" field creates this error:but map like
<String, dynamic>{}
works well because it has typeMap<String, dynamic>
and it is ok. Omitting "properties" field and non empty maps works well too.Issue also happens with
GeoJSONFeatureCollection.fromMap(...)
since it usesGeoJSONFeature.fromMap(...)
.Example
Way to fix it
It can be fixed quite easily with explicit map casting using
Map.castFrom(...)
so empty "properties" map will work well too, so I made this fix in this pull request: In file lib/src/classes/feature.dart in line 51 I changedmap['properties']
toMap.castFrom(map['properties'])
so it always will be converted toMap<String, dynamic>
before passing intoGeoJSONFeature
constructor.