Reputation: 79
I used nominatim OpenStreetMap API to recieve coordinate of london city and try to draw polygon of london city, but cause the number of points is too alot when I use this code
try {
await state.getLocationPolygonByAddress(
state.foundedAddress[index].address);
var foundedSvg = state.foundedSvg;
List<LatLng> list = [];
setState(() {
testPolygon.points.clear();
});
for (int i = 0; i < foundedSvg.length; i++) {
for (int j = 0; j <
foundedSvg[i].geojson.coordinates
.length; j++) {
for (int k =0;k<foundedSvg[i].geojson.coordinates[j].length;k++)
{
for (int z = 0; z <
foundedSvg[i].geojson.coordinates[j][k]
.length; z++) {
/* if(foundedSvg[i].geojson
.coordinates[j][k].first is double &&
foundedSvg[i].geojson
.coordinates[j][k].last is double) {*/
list.add(LatLng(foundedSvg[i].geojson
.coordinates[j][k].first,
foundedSvg[i].geojson
.coordinates[j][k].last));
/* }
else{
print(k);
}*/
}
}
}
}
print(list.length);
state.clearfoundedAddress();
setState(() {
testPolygon.points.addAll(list);
});
print('polyeditor length: ${polyEditor.points.length}');
}catch(e){
print('error :'+e.toString());
}
and when try to add list of points to polygon in this line
testPolygon.points.addAll(list);
app crashed . but it work good If the number of points is small.
this is my FlutterMap layer
late PolyEditor polyEditor;
List<Polygon> polygons = [];
// LatLngBounds boundingBox = LatLngBounds();
var testPolygon = Polygon(
color: Colors.black.withOpacity(0.3),
points: [],
borderColor: Colors.black,
isFilled: true,
borderStrokeWidth: 1.0);
@override
void initState() {
super.initState();
// processData();
polyEditor = PolyEditor(
addClosePathMarker: true,
points: testPolygon.points,
pointIcon: const Icon(
Icons.lens,
size: 10,
color: Colors.black,
),
intermediateIcon: const Icon(Icons.lens, size: 10, color:
Colors.black),
callbackRefresh: () => {setState(() {})},
);
polygons.add(testPolygon);
}
SearchController searchController = Get.put(SearchController());
MapController controller = MapController();
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
alignment: Alignment.center,
children: [
Center(
child: FlutterMap(
mapController: controller,
options: MapOptions(
// bounds: LatLngBounds(),
allowPanningOnScrollingParent: false,
onTap: (_, ll) {
print(ll);
polyEditor.add(testPolygon.points, ll);
},
plugins: [
DragMarkerPlugin(),
],
center: LatLng(32.5231, 51.6765),
zoom: 4.0,
),
layers: [
TileLayerOptions(
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c']),
PolygonLayerOptions(polygons: polygons,polygonCulling:
true),
DragMarkerPluginOptions(markers: polyEditor.edit(),),
],
),
),
the result should be like this result picture
I want a result like this link
Upvotes: 0
Views: 305
Reputation: 79
Yes this problem solved by deleting import ' package:flutter_map_line_editor/polyeditor.dart';
and delete this lines
DragMarkerPluginOptions(markers: polyEditor.edit(),),
polyEditor = PolyEditor(
addClosePathMarker: true,
points: testPolygon.points,
pointIcon: const Icon(
Icons.lens,
size: 10,
color: Colors.black,
),
intermediateIcon: const Icon(Icons.lens, size: 10, color: Colors.black),
callbackRefresh: () => {setState(() {})},
);`
in code @lan say correct answer
Upvotes: 0