mapbox / mapbox/mapbox-maps-flutter
Update an icon of a feature when selected
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Dart
- Sterne
- 380
- Forks
- 204
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
I'm a bit lost with the poor documentation regarding the feature-state so I don't know if it's a bug or a wrong implementation.
I have this function that does set the feature-state
Future<void> _changeSelectedMarker({ExtendedActivity? previousSelection, ExtendedActivity? newSelection}) async {
if (previousSelection != null) {
LoggingService.instance.debug('Deselecting marker with ID: ${previousSelection.activity.firebaseId}');
map.setFeatureState(
"activity-source",
null,
previousSelection.activity.firebaseId,
jsonEncode({"selected": false}),
);
}
if (newSelection != null) {
LoggingService.instance.debug('Selecting marker with ID: ${newSelection.activity.firebaseId}');
map.setFeatureState(
"activity-source",
null,
newSelection.activity.firebaseId,
jsonEncode({"selected": true}),
);
}
}
My layer is init like that
Future<void> _initSymbolLayer() async {
await map.style.addStyleSource(
"activity-source",
jsonEncode({
'type': 'geojson',
'data': {
'type': 'FeatureCollection',
'features': [],
},
}));
await map.style.addStyleLayer(
jsonEncode(
{
'id': "activity-layer",
'type': 'symbol',
'source': "activity-source",
'layout': {
'text-field': ['get', 'title'],
'text-size': OGDims.dim4,
'text-variable-anchor': ['left', 'top', 'right'],
'text-radial-offset': 1,
'text-offset': [2, 0],
'icon-image': [
'case',
[
'boolean',
['feature-state', 'selected'],
false
],
['get', 'selectedIcon'],
['get', 'icon'],
],
'icon-size': 7,
'icon-allow-overlap': true,
'icon-ignore-placement': true,
'text-allow-overlap': false,
'text-ignore-placement': false,
'text-justify': "auto",
},
'paint': {
'text-color': "#000000",
'text-halo-color': "#FFFFFF",
'text-halo-width': 1.75,
'icon-opacity': [
'coalesce',
['feature-state', 'opacity'],
0.0
]
}
},
),
LayerPosition(at: 0),
);
addMarkerImagesToMap();
}
But I can't make it works. Is it a bad implementation or a bug?
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne im Issue mit _changeSelectedMarker und _initSymbolLayer und prüfe anschließend die Flutter Mapbox setFeatureState API sowie die Unterstützung von feature-state für symbol-layer icon-image expressions. Reproduziere den Auswahl- und Abwahlablauf mit der bereitgestellten Activity-Quelle und Layer-Konfiguration. Als erledigt gilt, festzustellen, ob der Zustand angewendet wird und sich das Symbol ändert, oder einen bestätigten SDK-Bug mit der entsprechenden Reproduktion zu dokumentieren.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- dart, flutter
- Bereich
- mobile
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100