mapbox / mapbox/mapbox-maps-flutter
MyPoint extends Point does not return values
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Dart
- Estrellas
- 380
- Forks
- 204
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza inspeccionando MyPoint.toJson y MyPoint.fromJson en la clase mostrada y, a continuación, compáralos con la serialización generada por utils.g.dart. Sigue los puntos de entrada de creación de PointAnnotation y de AnnotationClickListener.onPointAnnotationClick, y verifica que pointid y trailspointid sobrevivan a la serialización y estén disponibles después del clic.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- dart, flutter
- Área
- mobile
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100