104 lines
3.4 KiB
Dart
104 lines
3.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_map/flutter_map.dart';
|
|
import 'package:latlong2/latlong.dart';
|
|
import 'package:manager_api_new/api.dart';
|
|
import 'package:mymuseum_visitapp/Models/visitContext.dart';
|
|
import 'package:mymuseum_visitapp/constants.dart';
|
|
|
|
class EventMapFullPage extends StatelessWidget {
|
|
const EventMapFullPage({
|
|
Key? key,
|
|
required this.section,
|
|
required this.visitAppContextIn,
|
|
}) : super(key: key);
|
|
|
|
final SectionEventDTO section;
|
|
final VisitAppContext visitAppContextIn;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final annotations = section.globalMapAnnotations ?? [];
|
|
final lat = double.tryParse(section.latitude ?? '');
|
|
final lng = double.tryParse(section.longitude ?? '');
|
|
final center = (lat != null && lng != null) ? LatLng(lat, lng) : const LatLng(50.85, 4.35);
|
|
|
|
return Scaffold(
|
|
body: Stack(
|
|
children: [
|
|
FlutterMap(
|
|
options: MapOptions(
|
|
initialCenter: center,
|
|
initialZoom: 14,
|
|
),
|
|
children: [
|
|
TileLayer(
|
|
urlTemplate: 'https://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',
|
|
userAgentPackageName: 'be.unov.myinfomate.visitapp',
|
|
),
|
|
if (annotations.isNotEmpty) ...[
|
|
MarkerLayer(markers: _buildMarkers(annotations)),
|
|
PolylineLayer(polylines: _buildPolylines(annotations)),
|
|
],
|
|
],
|
|
),
|
|
Positioned(
|
|
top: MediaQuery.of(context).padding.top + 10,
|
|
left: 10,
|
|
child: GestureDetector(
|
|
onTap: () => Navigator.of(context).pop(),
|
|
child: Container(
|
|
width: 42,
|
|
height: 42,
|
|
decoration: const BoxDecoration(color: kMainColor, shape: BoxShape.circle),
|
|
child: const Icon(Icons.arrow_back, color: Colors.white, size: 20),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
List<Marker> _buildMarkers(List<MapAnnotationDTO> annotations) {
|
|
final markers = <Marker>[];
|
|
for (final ann in annotations) {
|
|
if (ann.geometryType?.value != 0) continue;
|
|
final coords = ann.geometry?.coordinates;
|
|
if (coords is! List || coords.length < 2) continue;
|
|
final lat = (coords[1] as num).toDouble();
|
|
final lng = (coords[0] as num).toDouble();
|
|
markers.add(Marker(
|
|
point: LatLng(lat, lng),
|
|
width: 32,
|
|
height: 32,
|
|
child: const Icon(Icons.place, color: kMainColor, size: 32),
|
|
));
|
|
}
|
|
return markers;
|
|
}
|
|
|
|
List<Polyline> _buildPolylines(List<MapAnnotationDTO> annotations) {
|
|
final lines = <Polyline>[];
|
|
for (final ann in annotations) {
|
|
if (ann.geometryType?.value != 1) continue;
|
|
final coords = ann.geometry?.coordinates;
|
|
if (coords is! List) continue;
|
|
final points = <LatLng>[];
|
|
for (final c in coords) {
|
|
if (c is List && c.length >= 2) {
|
|
points.add(LatLng((c[1] as num).toDouble(), (c[0] as num).toDouble()));
|
|
}
|
|
}
|
|
if (points.length < 2) continue;
|
|
final color = ann.polyColor != null ? _hexColor(ann.polyColor!) : kMainColor;
|
|
lines.add(Polyline(points: points, color: color, strokeWidth: 4));
|
|
}
|
|
return lines;
|
|
}
|
|
|
|
Color _hexColor(String hex) {
|
|
final v = int.tryParse('FF${hex.replaceAll('#', '')}', radix: 16);
|
|
return v != null ? Color(v) : kMainColor;
|
|
}
|
|
}
|