mapbox-maps-flutter
mapbox-maps-flutter copied to clipboard
Unable to set ID on CircleAnnotation
If we are creating annotations on the map based on our own data, how are we supposed to map the created annotation to our data and vice versa? For example, when I tap on a annotation, how can I know what data that annotation is tied to?
Had a similar issue, tried to modify the library to allow myself to store an ID value in the annotation along with its other style parameters and location, got the structures working but caused a problem when it requested from mapbox because there wasn't an element designed to take the value.
Eventually I gave up and just added a custom array to temporarily store my annotation IDs as they are created on the map. it works if the map info is static, but as soon as i try to upload new information in real time etc it has issues.
So yeah this feature would be amazing, because I'd far prefer to link into mapbox for storing the ID value than have to create my own secondary storage.
Yeah, similar here. Storing them inside a map. I guess this works fine, but still kind of frustrating we need to supply our own structure. Here is what I am doing:
Future<void> addPoints(List<Chat> chats) async {
final ByteData bytes = await rootBundle.load('assets/symbol.png');
final Uint8List list = bytes.buffer.asUint8List();
for (Chat chat in chats) {
if (chat.position != null && !addedPoints.contains(chat.id)) {
addedPoints.add(chat.id);
var opt = PointAnnotationOptions(
geometry: Point(coordinates: Position(chat.position!.longitude, chat.position!.latitude)).toJson(),
image: list,
);
var annotation = await pointAnnotationManager?.create(opt);
if (annotation != null) {
annotationGroupMap[annotation.id] = chat;
}
}
}
pointAnnotationManager?.addOnPointAnnotationClickListener(AnnotationClickListener(annotationGroupMap, context));
}
@henryssunday can you explain how you're adding the id's in a map and retrieving them?
@Joshokelola For sure. I have a list of Things
that have an ID field, when you add a point by using a PointAnnotationManager
I just store the ID of the returned PointAnnotation
in a map of <String(ID of the created point), Thing>
. Pass this map to your onClick listener, and when a point receives a tap/click just look up which specific Thing
that point corresponds to. The code I pasted above illustrates this.