Programmatically retrieve the center lat/long when building map markers

Hi everyone,

I'm looking for a way to retrieve the center lat/long of the drawn shape in the Flutter map.
In the examples they do have an example in which they pass these via data, however I want to receive it programmatically instead of having to pass this via my own models.

class Model {
const Model(this.country, this.latitude, this.longitude);

final String country;
final double latitude;
final double longitude;
}

_data = const [
Model('Brazil', -14.235004, -51.92528),
Model('Germany', 51.16569, 10.451526),
Model('Australia', -25.274398, 133.775136),
Model('India', 20.593684, 78.96288),
Model('Russia', 61.52401, 105.318756)
];

MapShapeLayer(
source: _dataSource,
markerBuilder: (BuildContext context, int index) {
return MapMarker(
latitude: _data[index].latitude,
longitude: _data[index].longitude,
iconColor: Colors.blue,
);
})

I see come sort of trick is done to find the center for drawing label text, see: https://github.com/syncfusion/flutter-widgets/blob/master/packages/syncfusion_flutter_maps/lib/src/elements/data_label.dart on line 256

I tried: context.state.shapeFileData.decodedJsonData in the markerbuilder, but at that point it is still null

Thanks for helping me out.

3 Replies

LR Lakshmi Radha Krishnan Syncfusion Team April 14, 2021 01:13 PM UTC

Hi Tim,

 

Greetings from Syncfusion.

 

Currently there are no option to find the center point of the each shape. We have logged this as a feature request and this option will be provided in any of our upcoming releases.

 

Feedback: https://www.syncfusion.com/feedback/24301/option-for-finding-the-center-point-of-each-shape

 

If you have any more specification/suggestions to the feature request, you can add it as a comment in the portal.

 

Regards,

Lakshmi R.



TI Tim April 14, 2021 08:05 PM UTC

Hi Lakshmi R,

Thank you very much for your answer and creating a feature request for finding the center.
Do you know a way to get all the shapes which are being rendered?
The exact data I need in my own Flutter widget is the _ShapeFileData in the _GeoJSONLayerState but it's private.
I spend half day to figure out how to get the data, but so far I can only view it via the debugger.
I have tried to extend current classes but that will become a mess.

See image: https://pasteboard.co/JXkX2Up.png

Thank you so much!

Kind regards.




LR Lakshmi Radha Krishnan Syncfusion Team April 15, 2021 12:00 PM UTC

Hi Tim, 

 

Thanks for your update. 

 

Similar to the previous request, this is also currently not possible since these fields are maintained for our internal purposes. However, if you can let us know the list of items you will need regarding the shape file details and the need for it in your application if possible, it will be helpful for us to check and consider exposing them along with the previously requested “center point value of each shape”. 

 

Regards, 

Lakshmi R. 


Loader.
Up arrow icon