mapbox / mapbox/mapbox-maps-flutter

MyPoint extends Point does not return values

Aperta
#151 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Dart
Stelle
380
Fork
204
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia ispezionando MyPoint.toJson e MyPoint.fromJson nella classe mostrata, quindi confrontali con la serializzazione generata da utils.g.dart. Segui i punti di ingresso della creazione di PointAnnotation e di AnnotationClickListener.onPointAnnotationClick e verifica che pointid e trailspointid sopravvivano alla serializzazione e siano disponibili dopo il clic.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
dart, flutter
Ambito
mobile
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.