mapbox / mapbox-maps-flutter

Interactive, thoroughly customizable maps for Flutter powered by Mapbox Maps SDK
https://www.mapbox.com/mobile-maps-sdk
Other
282 stars 116 forks source link

getGeoJsonClusterLeaves and getGeoJsonClusterChildren methods throw an Exception #69

Open efenocchi opened 1 year ago

efenocchi commented 1 year ago

Hi, I run into a bug when I try to access the Future\ after calling the getGeoJsonClusterChildren or getGeoJsonClusterLeaves methods in the lib/src/pigeons/map_interfaces.dart file.

The following exception is thrown: Exception Unhandled Exception type '_InternalLinkedHashMapObject, Object' is not a subtype of type 'MapString, Object' in type cast.

I found the same error, which I think has been fixed, as a comment in the coordinatesForPixels method, could you fix the same bug in the methods listed above?

Thank you.

efenocchi commented 1 year ago

With the above PR the casting bug for the functions "getGeoJsonClusterLeaves", "getGeoJsonClusterChildren", "getGeoJsonClusterExpansionZoom" has been fixed.

KabaDH commented 1 year ago

Hi! Bug is still here. It is critical for working with clusters =( Some random text fields are broken depending on data. Here are examples for getGeoJsonClusterLeaves FeatureExtensionValue.featureCollection

E/flutter (26820): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type '_Map<Object?, Object?>' is not a subtype of type 'Map<String?, Object?>?' in type cast E/flutter (26820): #0 _CastListBase.[] (dart:_internal/cast.dart:99:46) E/flutter (26820): #1 ListMixin.first (dart:collection/list.dart:100:16) E/flutter (26820): #2 StyleClustersPageBodyState.build.<anonymous closure> (package:mapbox_maps_example/cluster.dart:221:54)

For https://docs.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson getGeoJsonClusterLeaves has broken Id { "type":"Feature", "geometry":{ "type":"Point", "coordinates":[ -27.4466, -60.0959 ] }, "properties":{ "id":us2000b0hn, "time":1506314791590, "mag":4.2, "tsunami":0 } }

For https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_110m_populated_places_simple.geojson Broken featureclass and ls_name. { "type":"Feature", "geometry":{ "type":"Point", "coordinates":[ -71.6229595, -33.0458186 ] }, "properties":{ "adm0cap":0, "natscale":110, "nameascii":"Valparaiso", "labelrank":3, "adm1name":"Valparaíso", "name":"Valparaiso", "namealt":"Valparaíso", "megacity":1, "pop_min":15938, "capalt":1, "adm0name":"Chile", "capin":"Legislative cap", "worldcity":0, "diffascii":0, "iso_a2":"CL", "namediff":0, "sov0name":"Chile", "ls_match":1, "sov_a3":"CHL", "adm0_a3":"CHL", "scalerank":3, "latitude":-33.0477644666, "longitude":-71.6210136329, "pop_other":130815, "changed":4, "diffnote":"Changed scale rank.", "pop_max":854000, "rank_max":11, "rank_min":6, "featureclass":Admin-0 capital alt, "geonameid":3445575, "meganame":"Valparaíso", "ls_name":Valparaiso2, "checkme":0 } }

efenocchi commented 1 year ago

Yes because the pr is not approved yet. Try replacing the code in the original library with what I wrote (see: https://github.com/mapbox/mapbox-maps-flutter/pull/84/commits/68f2c645464218fa817ed8cabb6e7d4b8c41e31e). Let me know if it works. It should fix the bug "Unhandled Exception: type '_Map<Object?, Object?>' is not a subtype of type 'Map<String?, Object?>?'".

KabaDH commented 1 year ago

It doesn't look like a casting problem. I think the issue is with the data we're receiving from the MessageChannel.

BenKfm commented 1 year ago

Another solution would be this (adapted from map_interfaces:2348 coordinatesForPixels): replace the featureCollection from pigeonMap part (map_interfaces:1028) with:

before: return FeatureExtensionValue( value: pigeonMap['value'] as String?, featureCollection: (pigeonMap['featureCollection'] as List<Object?>?) ?.cast<Map<String?, Object?>?>(), );

after: return FeatureExtensionValue( value: pigeonMap['value'] as String?, featureCollection: pigeonMap["featureCollection"] != null ? (pigeonMap['featureCollection'] as List<Object?>?)!.map((e) => Map<String?, Object?>.from(e as Map<dynamic, dynamic>)).toList() : []);

This has the benefit to preserve types so you dont have to change your code to accomodate your new solution

@yunikkk Sorry to yank you in here, is there some timeframe when a fix will be officially included, so we dont have to manually do this when upgrading versions?

VuillaumeGautier commented 1 year ago

Any insight on why the PR hasn't been validated ? We're facing the issue currently, and would prefer to avoid forking the project...

evil159 commented 1 year ago

Should be fixed in https://github.com/mapbox/mapbox-maps-flutter/pull/249