mirror of
https://bitbucket.org/FransoletThomas/tablet-app.git
synced 2025-12-06 08:31:19 +00:00
201 lines
7.2 KiB
Dart
201 lines
7.2 KiB
Dart
import 'dart:async';
|
|
import 'dart:typed_data';
|
|
import 'package:enum_to_string/enum_to_string.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
|
import 'package:manager_api/api.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:tablet_app/Components/multi_select_container.dart';
|
|
import 'package:tablet_app/Models/map-marker.dart';
|
|
import 'package:tablet_app/Screens/Map/map_context.dart';
|
|
import 'package:html/parser.dart' show parse;
|
|
import 'package:tablet_app/constants.dart';
|
|
|
|
class GoogleMapView extends StatefulWidget {
|
|
final MapDTO? mapDTO;
|
|
final Uint8List? selectedMarkerIcon;
|
|
final String? language;
|
|
const GoogleMapView({
|
|
Key? key,
|
|
this.mapDTO,
|
|
this.selectedMarkerIcon,
|
|
this.language,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
_GoogleMapViewState createState() => _GoogleMapViewState();
|
|
}
|
|
|
|
class _GoogleMapViewState extends State<GoogleMapView> {
|
|
ConfigurationDTO? configurationDTO;
|
|
Completer<GoogleMapController> _controller = Completer();
|
|
Set<Marker> markers = {};
|
|
List<GeoPointDTO>? pointsToShow = [];
|
|
List<String>? selectedCategories = [];
|
|
bool init = false;
|
|
|
|
Set<Marker> getMarkers(language, mapContext) {
|
|
markers = {};
|
|
|
|
pointsToShow!.forEach((point) {
|
|
var textSansHTML = parse(point.title!.firstWhere((translation) => translation.language == language).value);
|
|
var mapMarker = new MapMarker(
|
|
id: point.id,
|
|
title: parse(textSansHTML.body!.text).documentElement!.text,
|
|
description: point.description!.firstWhere((translation) => translation.language == language).value,
|
|
longitude: point.longitude,
|
|
latitude: point.latitude,
|
|
contents: point.contents
|
|
);
|
|
if (mapMarker.latitude != null && mapMarker.longitude != null) {
|
|
markers.add(Marker(
|
|
draggable: false,
|
|
markerId: MarkerId(mapMarker.latitude! + mapMarker.longitude!),
|
|
position: LatLng(
|
|
double.tryParse(mapMarker.latitude!)!,
|
|
double.tryParse(mapMarker.longitude!)!,
|
|
),
|
|
icon: widget.selectedMarkerIcon != null ? BitmapDescriptor.fromBytes(widget.selectedMarkerIcon!) : BitmapDescriptor.defaultMarker,
|
|
/*icon: BitmapDescriptor.defaultMarkerWithHue(
|
|
BitmapDescriptor.hueYellow,
|
|
),*/
|
|
onTap: () {
|
|
//setState(() {
|
|
mapContext.setSelectedMarker(
|
|
new MapMarker(
|
|
title: mapMarker.title,
|
|
contents: mapMarker.contents,
|
|
description: mapMarker.description,
|
|
longitude: mapMarker.longitude,
|
|
latitude: mapMarker.latitude,
|
|
)
|
|
);
|
|
//});
|
|
},
|
|
infoWindow: InfoWindow.noText));
|
|
}
|
|
});
|
|
return markers;
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
pointsToShow = widget.mapDTO!.points;
|
|
selectedCategories = widget.mapDTO!.categories!.map((categorie) => categorie.label!.firstWhere((element) => element.language == widget.language).value!).toList();
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
// TODO: implement dispose
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final mapContext = Provider.of<MapContext>(context);
|
|
Size size = MediaQuery.of(context).size;
|
|
|
|
if(!init) {
|
|
print("getmarkers in build");
|
|
getMarkers(widget.language, mapContext);
|
|
init = true;
|
|
}
|
|
//MapTypeApp? mapTypeApp = MapTypeApp.fromJson(widget.mapDTO!.mapType!.value);
|
|
//print(mapTypeApp.toString());
|
|
|
|
MapType type = MapType.hybrid;
|
|
//if(kIsWeb) {
|
|
if(widget.mapDTO!.mapType != null) {
|
|
switch(widget.mapDTO!.mapType!.value) {
|
|
case 0:
|
|
type = MapType.none;
|
|
break;
|
|
case 1:
|
|
type = MapType.normal;
|
|
break;
|
|
case 2:
|
|
type = MapType.satellite;
|
|
break;
|
|
case 3:
|
|
type = MapType.terrain;
|
|
break;
|
|
case 4:
|
|
type = MapType.hybrid;
|
|
break;
|
|
}
|
|
}
|
|
|
|
/*} else {
|
|
print("is OTHEER");
|
|
type = EnumToString.fromString(MapType.values, widget.mapDTO!.mapType.toString()) != null ? EnumToString.fromString(MapType.values, widget.mapDTO!.mapType.toString())! : MapType.hybrid;
|
|
}*/
|
|
|
|
|
|
//MapType type = EnumToString.fromString(MapType.values, widget.mapDTO!.mapType.toString()) != null ? EnumToString.fromString(MapType.values, widget.mapDTO!.mapType.toString())! : MapType.hybrid;
|
|
return Stack(
|
|
children: [
|
|
Center(
|
|
child: GoogleMap(
|
|
mapType: type, // widget.mapDTO!.mapType != null ? EnumToString.fromString(MapType.values, widget.mapDTO!.mapType.toString())!: MapType.hybrid,
|
|
mapToolbarEnabled: false,
|
|
indoorViewEnabled: false,
|
|
initialCameraPosition: CameraPosition(
|
|
target: LatLng(50.465503, 4.865105), //TODO add element in manager // MDLF 50.416639, 4.879169 / Namur 50.465503, 4.865105
|
|
zoom: widget.mapDTO!.zoom != null ? widget.mapDTO!.zoom!.toDouble() : 18,
|
|
),
|
|
onMapCreated: (GoogleMapController controller) {
|
|
if(kIsWeb) {
|
|
//_controllerWeb.complete(controller);
|
|
} else {
|
|
_controller.complete(controller);
|
|
}
|
|
},
|
|
markers: markers,
|
|
onTap: (LatLng location) {
|
|
//setState(() {
|
|
print(location);
|
|
mapContext.setSelectedMarker(
|
|
new MapMarker(
|
|
title: '',
|
|
description: '',
|
|
contents: null,
|
|
longitude: null,
|
|
latitude: null
|
|
));
|
|
// });
|
|
},
|
|
),
|
|
),
|
|
Positioned(
|
|
bottom: 35,
|
|
left: 10,
|
|
child: SizedBox(
|
|
width: size.width * 0.55,
|
|
child: MultiSelectContainer(
|
|
label: null,
|
|
color: kBackgroundGrey,
|
|
initialValue: selectedCategories!,
|
|
isMultiple: true,
|
|
values: widget.mapDTO!.categories!.map((categorie) => categorie.label!.firstWhere((element) => element.language == widget.language).value!).toList(),
|
|
onChanged: (value) {
|
|
var tempOutput = new List<String>.from(value);
|
|
print(tempOutput);
|
|
if(init) {
|
|
setState(() {
|
|
selectedCategories = tempOutput;
|
|
pointsToShow = widget.mapDTO!.points!.where((point) => tempOutput.any((tps) => point.categorie?.label?.firstWhere((lab) => lab.language == widget.language).value == tps) || point.categorie == null).toList();
|
|
markers = getMarkers(widget.language, mapContext);
|
|
mapContext.notifyListeners();
|
|
});
|
|
}
|
|
},
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
} |