-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added getSourceIds to the controller (#197)
Added getSourceIds to the controller with the android (tested) and ios (no ability to test here sorry). Not implemented on the web as getLayerIds in not implemented too I made the controller method returning a list of strings (`Future<List<String>>`) to have an explicit `String` list unlike `getLayerIds` who have a `Future<List<dynamic>>`
- Loading branch information
Showing
8 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:maplibre_gl/mapbox_gl.dart'; | ||
|
||
import 'page.dart'; | ||
|
||
class GetMapInfoPage extends ExamplePage { | ||
GetMapInfoPage() : super(const Icon(Icons.info), 'Get map state'); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return GetMapInfoBody(); | ||
} | ||
} | ||
|
||
class GetMapInfoBody extends StatefulWidget { | ||
const GetMapInfoBody(); | ||
|
||
@override | ||
State<GetMapInfoBody> createState() => _GetMapInfoBodyState(); | ||
} | ||
|
||
class _GetMapInfoBodyState extends State<GetMapInfoBody> { | ||
MaplibreMapController? controller; | ||
String data = ''; | ||
|
||
void onMapCreated(MaplibreMapController controller) { | ||
setState(() { | ||
this.controller = controller; | ||
}); | ||
} | ||
|
||
void displaySources() async { | ||
if (controller == null) { | ||
return; | ||
} | ||
List<String> sources = await controller!.getSourceIds(); | ||
setState(() { | ||
data = 'Sources: ${sources.map((e) => '"$e"').join(', ')}'; | ||
}); | ||
} | ||
|
||
void displayLayers() async { | ||
if (controller == null) { | ||
return; | ||
} | ||
List<String> layers = (await controller!.getLayerIds()).cast<String>(); | ||
setState(() { | ||
data = 'Layers: ${layers.map((e) => '"$e"').join(', ')}'; | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | ||
crossAxisAlignment: CrossAxisAlignment.stretch, | ||
children: [ | ||
Center( | ||
child: SizedBox( | ||
width: 300.0, | ||
height: 200.0, | ||
child: MaplibreMap( | ||
initialCameraPosition: const CameraPosition( | ||
target: LatLng(-33.852, 151.211), | ||
zoom: 11.0, | ||
), | ||
onMapCreated: onMapCreated, | ||
compassEnabled: false, | ||
annotationOrder: [], | ||
myLocationEnabled: false, | ||
styleString: '''{ | ||
"version": 8, | ||
"sources": { | ||
"OSM": { | ||
"type": "raster", | ||
"tiles": [ | ||
"https://a.tile.openstreetmap.org/{z}/{x}/{y}.png", | ||
"https://b.tile.openstreetmap.org/{z}/{x}/{y}.png", | ||
"https://c.tile.openstreetmap.org/{z}/{x}/{y}.png" | ||
], | ||
"tileSize": 256, | ||
"attribution": "© OpenStreetMap contributors", | ||
"maxzoom": 18 | ||
} | ||
}, | ||
"layers": [ | ||
{ | ||
"id": "OSM-layer", | ||
"source": "OSM", | ||
"type": "raster" | ||
} | ||
] | ||
}''', | ||
), | ||
), | ||
), | ||
Center( | ||
child: const Text('© OpenStreetMap contributors'), | ||
), | ||
Expanded( | ||
child: SingleChildScrollView( | ||
child: Column( | ||
children: [ | ||
SizedBox(height: 30), | ||
Center(child: Text(data)), | ||
SizedBox(height: 30), | ||
ElevatedButton( | ||
onPressed: controller == null ? null : displayLayers, | ||
child: const Text('Get map layers'), | ||
), | ||
ElevatedButton( | ||
onPressed: controller == null ? null : displaySources, | ||
child: const Text('Get map sources'), | ||
) | ||
], | ||
), | ||
)), | ||
], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters