mapbox / mapbox/mapbox-maps-flutter
source error for point annotations
Nobody has claimed this yet.
- Dominant language
- Dart
- Stars
- 380
- Forks
- 204
- PR merge metrics
- No merged PRs in 30d
Description
Source check error: PlatformException(0, Source d6253eb4-f435-4b80-8b81-8ac16daa3a2b is not in style, null, null)
[MapScreen] Processing layer: da59e513-e21d-4296-81e6-9dc59a851796, Grid Points
Adding as SymbolLayer
Future<void> _addPointLayerAsSymbol(
Map<String, dynamic> geoJsonMap, MapLayer layer) async {
try {
Uint8List list;
String iconId = layer.id;
if (layer.iconPath != null && layer.iconPath.isNotEmpty) {
final file = File(layer.iconPath);
if (await file.exists()) {
list = await file.readAsBytes();
list = await _resizeIcon(list, 12, 12);
} else {
developer.log('Icon file does not exist: ${layer.iconPath}',
name: 'MapScreen');
final ByteData bytes =
await rootBundle.load('assets/icons/plus-12.png');
list = bytes.buffer.asUint8List();
list = await _resizeIcon(list, 12, 12);
iconId = 'default-icon';
}
} else {
final ByteData bytes = await rootBundle.load('assets/icons/plus-12.png');
list = bytes.buffer.asUint8List();
list = await _resizeIcon(list, 12, 12);
iconId = 'default-icon';
}
if (!_addedImages.contains(iconId)) {
await _mapboxMap.style.addStyleImage(iconId, 1.0,
MbxImage(width: 12, height: 12, data: list), true, [], [], null);
_addedImages.add(iconId);
}
for (var feature in geoJsonMap["features"]) {
final geometry = feature["geometry"]["coordinates"];
final longitude = geometry[0];
final latitude = geometry[1];
final id = feature["id"].toString();
await _mapboxMap.style.addLayer(SymbolLayer(
id: '${layer.id}_symbol_$id',
sourceId: layer.id,
iconImage: iconId,
iconSize: 1.0,
iconOffset: const [0.0, -6.0],
filter: [
'==',
['id'],
id
],
));
}
} catch (e) {
developer.log('Error adding point layer: $e', name: 'MapScreen');
}
}
Adding using PointAnnotationsManager
Future<void> _addPointLayerWithAnnotations(
Map<String, dynamic> geoJsonMap, MapLayer layer) async {
try {
Uint8List list;
String iconId = layer.id;
if (layer.iconPath != null && layer.iconPath.isNotEmpty) {
final file = File(layer.iconPath);
if (await file.exists()) {
list = await file.readAsBytes();
list = await _resizeIcon(list, 12, 12);
} else {
final ByteData bytes =
await rootBundle.load('assets/icons/plus-24.png');
list = bytes.buffer.asUint8List();
list = await _resizeIcon(list, 12, 12);
iconId = 'default-icon';
}
} else {
final ByteData bytes = await rootBundle.load('assets/icons/plus-24.png');
list = bytes.buffer.asUint8List();
list = await _resizeIcon(list, 12, 12);
iconId = 'default-icon';
}
if (!_addedImages.contains(iconId)) {
await _mapboxMap.style.addStyleImage(iconId, 1.0,
MbxImage(width: 12, height: 12, data: list), true, [], [], null);
_addedImages.add(iconId);
}
var pointAnnotationManager =
await _mapboxMap.annotations.createPointAnnotationManager();
_annotationManagers[pointAnnotationManager] = [];
for (var feature in geoJsonMap["features"]) {
final properties = feature["properties"];
final geometry = feature["geometry"]["coordinates"];
final longitude = geometry[0];
final latitude = geometry[1];
final annotation =
await pointAnnotationManager.create(PointAnnotationOptions(
geometry: Point(coordinates: Position(longitude, latitude)),
iconImage: iconId,
iconSize: 1.3,
iconOffset: const [0.0, -5.0],
symbolSortKey: 10,
));
_annotationManagers[pointAnnotationManager]?.add(annotation);
annotationProperties[annotation.id] = filterProperties(properties, layer);
}
if (layer.enablePopUp) {
pointAnnotationManager.addOnPointAnnotationClickListener(
CustomAnnotationClickListener(context, (data) {
if (mounted) {
setState(() {
_properties = data.isNotEmpty ? data : null;
});
}
}, annotationProperties),
);
}
if (layer.enableLabel && layer.label.isNotEmpty) {
await _addLabelLayer(
layer.id, layer, layer.label, layer.labelColor, layer.zoomLevel ?? 0);
}
} catch (e) {
developer.log('Error adding point layer: $e', name: 'MapScreen');
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in MapScreen at _addPointLayerAsSymbol and _addPointLayerWithAnnotations, comparing how each path registers sources, style images, layers, and annotations. Reproduce the source check error for source d6253eb4-f435-4b80-8b81-8ac16daa3a2b and determine the project-specific change needed so point annotations no longer reference a source absent from the style.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, flutter
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100