mapbox / mapbox/mapbox-maps-flutter
MyPoint extends Point does not return values
Nobody has claimed this yet.
- Dominant language
- Dart
- Stars
- 380
- Forks
- 204
- PR merge metrics
- No merged PRs in 30d
Description
Hi all
As there is no active discussionsomewhere I ask my question here, event it is not the place to do.
I need to Extend Points with a PointID to be able to load data of this point later in the code
This is how I initialise Points
```
pointAnnotationManager?.create(PointAnnotationOptions(
geometry: **MyPoint(
coordinates: Position(
double.parse(place.attributes!.longitude.toString()),
double.parse(place.attributes!.latitude.toString()),
),
pinNumber: place.id,
trailPinNumber: place.id,
).toJson(),**
textField: "${place.id}",
///ToDo Set textOpacity to 0 when no text should be displayed
textOpacity: 1,
textOffset: [0.0, -4.0],
iconOpacity: 0.5,
iconSize: 0.75,
iconOffset: [0.0, -30.0],
symbolSortKey: 10,
image: selectedImageData,
));
```
The next step is reading a point when Clicked
```
class AnnotationClickListener extends OnPointAnnotationClickListener {
_MapBoxMapScreenState mapState;
Animation? animation;
AnimationController? controller;
AnnotationClickListener(this.mapState);
@override
void onPointAnnotationClick(PointAnnotation selectedannotation) async {
if (await mapState.mapboxMap.style.styleSourceExists("source")) {
await mapState.mapboxMap.style.removeStyleLayer("layer");
await mapState.mapboxMap.style.removeStyleSource("source");
}
// build route from puck position to the clicked annotation
final start = await mapState.mapboxMap.style.getPuckPosition();
**final end = MyPoint.fromJson((selectedannotation.geometry)!.cast());**
final coordinates = await fetchRouteCoordinates(start, end.coordinates, ZadaApp.mapboxAccessToken);
final selectedpinNumber = end.pointid;
final selectedtrailPinNumber = end.trailspointid;
**print('PinInformation: ${end.pointid}');**
**print('TrailPintInformation: ${end.trailspointid}');**
}
}
```
here is the toJson and fromJson Funcion to serialise end deserialise
```
part 'utils.g.dart';
@JsonSerializable(explicitToJson: true)
class MyPoint extends Point {
int? pointid;
int? trailspointid;
MyPoint({
super.bbox,
required super.coordinates,
this.pointid,
this.trailspointid
});
@override
factory MyPoint.fromJson(Map json) => _$MyPointFromJson(json);
@override
Map toJson() => super.serialize(_$MyPointToJson(this));
@override
MyPoint clone() => MyPoint(coordinates: coordinates.clone(), bbox: bbox?.clone(), pointid: pointid, trailspointid: trailspointid);
@override
int get hashCode => Object.hashAll([
type,
...coordinates,
if (bbox != null) ...bbox!,
if (pointid != null) pointid!,
if (trailspointid != null) trailspointid!,
]);
@override
bool operator == (Object other) => other is MyPoint
? coordinates == other.coordinates
: false;
}
```
The output of end.pointid is always empty in the code
**print('PinInformation: ${end.pointid}');**
**print('TrailPintInformation: ${end.trailspointid}');**
Any hit are welcome many thanks for your help
Roman
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 by inspecting MyPoint.toJson and MyPoint.fromJson in the class shown, then compare them with the generated utils.g.dart serialization. Trace the PointAnnotation creation and AnnotationClickListener.onPointAnnotationClick entry points, and verify that pointid and trailspointid survive serialization and are available after the click.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, flutter
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100