mapbox / mapbox/mapbox-maps-flutter

Tapped layer color change using layer's id within properties

Open
#654 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Dart
Stars
380
Forks
204
PR merge metrics
No merged PRs in 30d

Description

I am trying to change the tapped layer color only using pond_id inside my layer response.. when i tap the feature state returns true but the color is not changing "#E27E1E", my featuredata of tapped layer id :

> Tapped feature ID: {type: Feature, id: 22, geometry: {type: Polygon, coordinates: [[[81.4860383, 16.5046304], [81.4888948, 16.5045532], [81.4888412, 16.5036197], [81.4868027, 16.5036557], [81.4862716, 16.5036248], [81.4860383, 16.5046304]]]}, properties: {pond_id: 16108c29-e6eb-4ee6-94a1-56c8a16cc167}}

`await mapboxMap?.style.addLayer(
FillLayer(
id: 'pond_boundary_tile1_fill',
sourceId: 'pond_boundary_tile1_source',
sourceLayer: 'ponds_WG_b2-2ttlya',
fillColorExpression: [
'case',
[
'boolean',
['feature-state', 'selected'],
false
],
"#E27E1E",
[
"in",
["get", "pond_id"],
["literal", allPondIds]
],
"#004fbb",
"#DBDBDB",
],
),
);

Future onTapListener(MapContentGestureContext context,
Function(bool) onFeatureSelected) async {
final touchPosition = context.touchPosition;
// print("Coordinates: (${touchPosition.x}, ${touchPosition.y})");

final List features =
await mapboxMap!.queryRenderedFeatures(
RenderedQueryGeometry(
value: jsonEncode(touchPosition.encode()),
type: Type.SCREEN_COORDINATE,
),
RenderedQueryOptions(
layerIds: ['pond_boundary_tile1_fill'], filter: null),
);

if (features.isNotEmpty) {
final QueriedFeature selectedFeature = features.first!.queriedFeature;
final featureData = selectedFeature.feature;

final featureModel = FeatureModel.fromJson(
Map.from(featureData),
);

isLoading.value = true;

final pondId = featureModel.tappedId;

print("Tapped feature properties ID: $pondId");

featureId.value = selectedFeature.feature['id'].toString();

print("Tapped feature ID: $featureData");

appController.setFeatureId = submittedId;

// selectedFeatureId = featureId.value;

if (selectedFeatureId != null && selectedFeatureId != pondId) {
mapboxMap?.setFeatureState(
'pond_boundary_tile1_source',
'ponds_WG_b2-2ttlya',
selectedFeatureId!,
jsonEncode({'selected': false}),
);
}
print("Setting feature state for pondId: $pondId");
mapboxMap?.setFeatureState(
'pond_boundary_tile1_source',
'ponds_WG_b2-2ttlya',
pondId,
jsonEncode({'selected': true}),
);

final featureState = await mapboxMap?.getFeatureState(
'pond_boundary_tile1_source',
'ponds_WG_b2-2ttlya',
pondId,
);

print("Updated Feature state: $featureState");


}
}
}`

please help me to fix asap.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the onTapListener entry point and trace the FillLayer fillColorExpression together with the setFeatureState calls for pond_boundary_tile1_source and ponds_WG_b2-2ttlya. Verify that the tapped feature identifier used for state matches the identifier expected by the layer, then confirm the selected pond changes to #E27E1E while other ponds retain their colors.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.