10000 [Example] Remove layer before adding layer if layer is added in place source example by Chaoba · Pull Request #766 · flutter-mapbox-gl/maps · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[Example] Remove layer before adding layer if layer is added in place source example #766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
10000 Loading
Diff view
Diff view
100 changes: 52 additions & 48 deletions example/lib/place_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class PlaceSymbolBodyState extends State<PlaceSymbolBody> {
static const LAYER_ID = 'sydney_layer';

bool sourceAdded = false;
bool layerAdded = false;
late MapboxMapController controller;

void _onMapCreated(MapboxMapController controller) {
Expand Down Expand Up @@ -68,16 +69,24 @@ class PlaceSymbolBodyState extends State<PlaceSymbolBody> {
}

Future<void> addLayer(String imageLayerId, String imageSourceId) {
if(layerAdded) {
removeLayer(imageLayerId);
}
setState(() => layerAdded = true);
return controller.addImageLayer(imageLayerId, imageSourceId);
}

Future<void> addLayerBelow(
String imageLayerId, String imageSourceId, String belowLayerId) {
return controller.addImageLayerBelow(
imageLayerId, imageSourceId, belowLayerId);
if(layerAdded) {
removeLayer(imageLayerId);
}
setState(() => layerAdded = true);
return controller.addImageLayerBelow(imageLayerId, imageSourceId, belowLayerId);
}

Future<void> removeLayer(String imageLayerId) {
setState(() => layerAdded = false);
return controller.removeLayer(imageLayerId);
}

Expand Down Expand Up @@ -106,55 +115,50 @@ class PlaceSymbolBodyState extends State<PlaceSymbolBody> {
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Row(
Column(
children: <Widget>[
Column(
children: <Widget>[
TextButton(
child: const Text('Add source (asset image)'),
onPressed: sourceAdded
? null
: () {
addImageSourceFromAsset(
SOURCE_ID, 'assets/sydney.png')
.then((value) {
setState(() => sourceAdded = true);
});
},
),
TextButton(
child: const Text('Remove source (asset image)'),
onPressed: sourceAdded
? () async {
await removeLayer(LAYER_ID);
removeImageSource(SOURCE_ID).then((value) {
setState(() => sourceAdded = false);
});
}
: null,
),
TextButton(
child: const Text('Show layer'),
onPressed: sourceAdded
? () => addLayer(LAYER_ID, SOURCE_ID)
: null,
),
TextButton(
child: const Text('Show layer below water'),
onPressed: sourceAdded
? () =>
addLayerBelow(LAYER_ID, SOURCE_ID, 'water')
: null,
),
TextButton(
child: const Text('Hide layer'),
onPressed:
sourceAdded ? () => removeLayer(LAYER_ID) : null,
),
],
TextButton(
child: const Text('Add source (asset image)'),
onPressed: sourceAdded
? null
: () {
addImageSourceFromAsset(
SOURCE_ID, 'assets/sydney.png')
.then((value) {
setState(() => sourceAdded = true);
});
},
),
TextButton(
child: const Text('Remove source (asset image)'),
onPressed: sourceAdded
? () async {
await removeLayer(LAYER_ID);
removeImageSource(SOURCE_ID).then((value) {
setState(() => sourceAdded = false);
});
}
: null,
),
TextButton(
child: const Text('Show layer'),
onPressed: sourceAdded
? () => addLayer(LAYER_ID, SOURCE_ID)
: null,
),
TextButton(
child: const Text('Show layer below water'),
onPressed: sourceAdded
? () => addLayerBelow(LAYER_ID, SOURCE_ID, 'water')
: null,
),
TextButton(
child: const Text('Hide layer'),
onPressed:
sourceAdded ? () => removeLayer(LAYER_ID) : null,
),
],
)
),
],
),
),
Expand Down
0