mapbox / mapbox/mapbox-maps-flutter

MyPoint extends Point does not return values

Offen
#151 0 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Dart
Sterne
380
Forks
204
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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<double>? 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<String, dynamic> json) => _$MyPointFromJson(json);

  @override
  Map<String, dynamic> 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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginnen Sie mit der Untersuchung von MyPoint.toJson und MyPoint.fromJson in der gezeigten Klasse und vergleichen Sie sie anschließend mit der von utils.g.dart generierten Serialisierung. Verfolgen Sie die Einstiegspunkte für die Erstellung von PointAnnotation und für AnnotationClickListener.onPointAnnotationClick, und überprüfen Sie, dass pointid und trailspointid die Serialisierung überstehen und nach dem Klick verfügbar sind.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
dart, flutter
Bereich
mobile
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.