Shape selection on maps stops working if the mapsource is a future

In my MapShapeSublayer, when I update my mapsource property from 

MapShapeSource myMapSource = MapShapeSource.asset(
  'assets/json_data/2_provincias.json',
  shapeDataField: 'Provincia',
  dataCount: provinciaKeys.length,
  primaryValueMapper: (int index) => provinciaKeys.entries.elementAt(index).key,
  shapeColorValueMapper: (int index) =>
      provinciaKeys[provinciaKeys.entries.elementAt(index).key]!.baseColor,
);


to

Future<MapShapeSource> myMapSource() async {
  return MapShapeSource.asset(
    'assets/json_data/2_provincias.json',
    shapeDataField: 'Provincia',
    dataCount: provinciaKeys.length,
    primaryValueMapper: (int index) =>
        provinciaKeys.entries.elementAt(index).key,
    shapeColorValueMapper: (int index) =>
        provinciaKeys[provinciaKeys.entries.elementAt(index).key]!.baseColor,
  );
}

then the select shape functionality seems to go haywire.  Any ideas?  I appreciate that the 2nd code snippet isn't really a future.  But I will make it a proper future once I have resolved this issue. Many thanks!


3 Replies

YG Yuvaraj Gajaraj Syncfusion Team May 27, 2022 01:55 PM UTC

Hi Steve,


Greetings from Syncfusion. We like to let you know that in the map it is already implemented with the FutureBuilder and the given MapShapeSource is converted to Future and for selection we have use the setState() to perform selection, so you do not need to pass the MapShapeSource as a Future. This is the reason the selection is not working. So please try to avoid assigning the source value as Future<MapShapeSource> instead of MapShapeSource.


If you have any further queries, please get back to us.


Regards,

Yuvaraj.



SM Steve Monroe May 27, 2022 02:24 PM UTC

Ok understood - thank you.

What I really want to do is get my MapSource data from my Cloud Firestore database. My understanding is that retrieving data from Firebase always requires a future... so do you know if there any way to achieve this given the restriction you mention?

Many thanks for your help!



YG Yuvaraj Gajaraj Syncfusion Team June 1, 2022 02:07 PM UTC

Hi Steve,


Thanks for your patience. We suggest you fetch the JSON data from the firestore at the initState() itself then assign the JSON data to the MapSource that would be the proper method of fetching data from the firestore. If this is not your case, then please try to provide the data structure of your firestore database and what the values are contained. That would be helpful to us to provide a solution sooner.


Regards,

Yuvaraj.


Loader.
Up arrow icon