mirror of
https://bitbucket.org/FransoletThomas/tablet-app.git
synced 2025-12-06 08:31:19 +00:00
Added new flutter map view (based on web)
This commit is contained in:
parent
192c893219
commit
8f6913407c
136
lib/Screens/Map/flutter_map_view.dart
Normal file
136
lib/Screens/Map/flutter_map_view.dart
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_map/flutter_map.dart';
|
||||||
|
import 'package:latlong2/latlong.dart';
|
||||||
|
import 'package:manager_api/api.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:tablet_app/Models/tabletContext.dart';
|
||||||
|
import 'package:tablet_app/Screens/Map/map_context.dart';
|
||||||
|
import 'package:tablet_app/app_context.dart';
|
||||||
|
import 'package:html/parser.dart' show parse;
|
||||||
|
import 'package:latlong2/latlong.dart' as ll;
|
||||||
|
|
||||||
|
class FlutterMapView extends StatefulWidget {
|
||||||
|
final MapDTO? mapDTO;
|
||||||
|
final List<GeoPointDTO> geoPoints;
|
||||||
|
final List<Map<String, dynamic>> icons;
|
||||||
|
final String? language;
|
||||||
|
const FlutterMapView({
|
||||||
|
Key? key,
|
||||||
|
this.mapDTO,
|
||||||
|
required this.geoPoints,
|
||||||
|
required this.icons,
|
||||||
|
this.language,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_FlutterMapViewState createState() => _FlutterMapViewState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _FlutterMapViewState extends State<FlutterMapView> {
|
||||||
|
late List<GeoPointDTO> markersList;
|
||||||
|
late List<Marker> markers;
|
||||||
|
bool filterZoneSelected = false;
|
||||||
|
MapController? mapController;
|
||||||
|
|
||||||
|
List<Marker> createPoints(mapContext) {
|
||||||
|
markersList = [];
|
||||||
|
markers = [];
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
widget.geoPoints.forEach((point) {
|
||||||
|
if (point.title!.where((translation) => translation.language == widget.language).isNotEmpty) {
|
||||||
|
var textSansHTML = parse(point.title!.firstWhere((translation) => translation.language == widget.language).value);
|
||||||
|
point.id = i;
|
||||||
|
point.title = point.title!.where((t) => t.language == widget.language).toList();
|
||||||
|
markersList.add(point);
|
||||||
|
|
||||||
|
//var icon = point.categorie == null ? BitmapDescriptor.fromBytes(widget.icons.where((i) => i['id'] == null).first['icon']) : widget.icons.any((i) => i['id'] == point.categorieId) ? BitmapDescriptor.fromBytes(widget.icons.where((i) => i['id'] == point.categorieId).first['icon']) : BitmapDescriptor.fromBytes(widget.icons.where((i) => i['id'] == null).first['icon']); //widget.selectedMarkerIcon,;
|
||||||
|
|
||||||
|
markers.add(
|
||||||
|
Marker(
|
||||||
|
width: 80.0,
|
||||||
|
height: 80.0,
|
||||||
|
point: LatLng(double.tryParse(point.latitude!)!, double.tryParse(point.longitude!)!),
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
/*final mapContext = Provider.of<MapContext>(context, listen: false);
|
||||||
|
mapContext.setSelectedPoint(point);
|
||||||
|
mapContext.setSelectedPointForNavigate(point);*/
|
||||||
|
mapContext.setSelectedPoint(point);
|
||||||
|
mapContext.setSelectedPointForNavigate(point);
|
||||||
|
},
|
||||||
|
child: widget.icons.firstWhere((i) => i['id'] == point.categorieId, orElse: () => widget.icons.first)['icon'] != null ? Image.memory(widget.icons.firstWhere((i) => i['id'] == point.categorieId, orElse: () => widget.icons.first)['icon']) : Icon(Icons.pin_drop, color: Colors.red),//widget.icons.firstWhere((i) => i['id'] == point.categorieId, orElse: () => widget.icons.first)['icon'],
|
||||||
|
)
|
||||||
|
),
|
||||||
|
);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return markers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final mapContext = Provider.of<MapContext>(context);
|
||||||
|
final appContext = Provider.of<AppContext>(context);
|
||||||
|
TabletAppContext tabletAppContext = appContext.getContext() as TabletAppContext;
|
||||||
|
|
||||||
|
markers = createPoints(mapContext);
|
||||||
|
|
||||||
|
if (mapController == null) { // mapContext.getSelectedPointForNavigate() != null
|
||||||
|
/*var geoPoint = mapContext.getSelectedPointForNavigate();
|
||||||
|
var center = LatLng(double.tryParse(geoPoint.latitude!)!, double.tryParse(geoPoint.longitude!)!);*/
|
||||||
|
mapController = MapController();
|
||||||
|
|
||||||
|
//mapController!.move(center, widget.mapDTO!.zoom != null ? widget.mapDTO!.zoom!.toDouble() : 12);
|
||||||
|
mapContext.setSelectedPointForNavigate(null); // Reset after navigation
|
||||||
|
}
|
||||||
|
|
||||||
|
return Stack(
|
||||||
|
children: [
|
||||||
|
FlutterMap(
|
||||||
|
mapController: mapController,
|
||||||
|
options: MapOptions(
|
||||||
|
initialCenter: widget.mapDTO!.longitude != null && widget.mapDTO!.latitude != null ? ll.LatLng(double.tryParse(widget.mapDTO!.latitude!)!, double.tryParse(widget.mapDTO!.longitude!)!) : ll.LatLng(4.865105, 50.465503), //.toJson()
|
||||||
|
initialZoom: widget.mapDTO!.zoom != null ? widget.mapDTO!.zoom!.toDouble() : 12,
|
||||||
|
onTap: (Tap, lnt) => {
|
||||||
|
mapContext.setSelectedPointForNavigate(null),
|
||||||
|
mapContext.setSelectedPoint(null),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
children: [
|
||||||
|
TileLayer(
|
||||||
|
urlTemplate: "https://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}",
|
||||||
|
userAgentPackageName: 'be.unov.myinfomate.tablet',
|
||||||
|
),
|
||||||
|
MarkerLayer(
|
||||||
|
markers: markers
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
child: Builder(
|
||||||
|
builder: (context) {
|
||||||
|
return Consumer<MapContext>(
|
||||||
|
builder: (context, mapContext, _) {
|
||||||
|
var geoPoint = mapContext.getSelectedPointForNavigate() as GeoPointDTO?;
|
||||||
|
if (geoPoint != null && mapController != null) {
|
||||||
|
print("COUCOU IL FAUT NAVIGATE FLUTTER MAP");
|
||||||
|
mapController!.move(LatLng(double.tryParse(geoPoint.latitude!)!, double.tryParse(geoPoint.longitude!)!), 16);
|
||||||
|
}
|
||||||
|
return SizedBox();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,7 +4,7 @@ import 'dart:math';
|
|||||||
//import 'package:animated_tree_view/animated_tree_view.dart';
|
//import 'package:animated_tree_view/animated_tree_view.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
|
|
||||||
//import 'package:generate_tree/generate_tree.dart';
|
//import 'package:generate_tree/generate_tree.dart';
|
||||||
//import 'package:generate_tree/treeNode.dart';
|
//import 'package:generate_tree/treeNode.dart';
|
||||||
import 'package:manager_api/api.dart';
|
import 'package:manager_api/api.dart';
|
||||||
@ -260,6 +260,7 @@ class _GeoPointFilterState extends State<GeoPointFilter> {
|
|||||||
onPressed: () {
|
onPressed: () {
|
||||||
if(_searchController.text.isNotEmpty) {
|
if(_searchController.text.isNotEmpty) {
|
||||||
_searchController.text = "";
|
_searchController.text = "";
|
||||||
|
// TODO reset view ?
|
||||||
}
|
}
|
||||||
filterNodes();
|
filterNodes();
|
||||||
if(_searchController.text.isNotEmpty) {
|
if(_searchController.text.isNotEmpty) {
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import 'package:tablet_app/Models/map-marker.dart';
|
|||||||
//import 'dart:ui' as ui;
|
//import 'dart:ui' as ui;
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:tablet_app/Models/tabletContext.dart';
|
import 'package:tablet_app/Models/tabletContext.dart';
|
||||||
|
import 'package:tablet_app/Screens/Map/flutter_map_view.dart';
|
||||||
import 'package:tablet_app/Screens/Map/geo_point_filter.dart';
|
import 'package:tablet_app/Screens/Map/geo_point_filter.dart';
|
||||||
import 'package:tablet_app/Screens/Map/map_box_view.dart';
|
import 'package:tablet_app/Screens/Map/map_box_view.dart';
|
||||||
import 'package:tablet_app/Screens/Map/marker_view.dart';
|
import 'package:tablet_app/Screens/Map/marker_view.dart';
|
||||||
@ -99,6 +100,8 @@ class _MapViewWidget extends State<MapViewWidget> {
|
|||||||
return GoogleMapView(language: appContext.getContext().language, geoPoints: value, mapDTO: mapDTO!, icons: widget.icons);
|
return GoogleMapView(language: appContext.getContext().language, geoPoints: value, mapDTO: mapDTO!, icons: widget.icons);
|
||||||
case MapProvider.MapBox:
|
case MapProvider.MapBox:
|
||||||
return MapBoxView(language: appContext.getContext().language, geoPoints: value, mapDTO: mapDTO, icons: widget.icons);
|
return MapBoxView(language: appContext.getContext().language, geoPoints: value, mapDTO: mapDTO, icons: widget.icons);
|
||||||
|
// If mapbox bug as 3.24 flutter, we can test via this new widget
|
||||||
|
//return FlutterMapView(language: appContext.getContext().language, geoPoints: value, mapDTO: mapDTO, icons: widget.icons);
|
||||||
default:
|
default:
|
||||||
// By default google
|
// By default google
|
||||||
return GoogleMapView(language: appContext.getContext().language, geoPoints: value, mapDTO: mapDTO!, icons: widget.icons);
|
return GoogleMapView(language: appContext.getContext().language, geoPoints: value, mapDTO: mapDTO!, icons: widget.icons);
|
||||||
|
|||||||
@ -92,6 +92,7 @@ class _MarkerInfoWidget extends State<MarkerViewWidget> {
|
|||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
mapContext.setSelectedPoint(null);
|
mapContext.setSelectedPoint(null);
|
||||||
|
mapContext.setSelectedPointForNavigate(null);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
|
|||||||
@ -36,6 +36,8 @@ dependencies:
|
|||||||
|
|
||||||
mapbox_maps_flutter: ^2.0.0 # specific mobile ..
|
mapbox_maps_flutter: ^2.0.0 # specific mobile ..
|
||||||
|
|
||||||
|
flutter_map: ^7.0.2 #all
|
||||||
|
|
||||||
#ota_update: ^6.0.0
|
#ota_update: ^6.0.0
|
||||||
#package_info: ^2.0.2 # specific mobile
|
#package_info: ^2.0.2 # specific mobile
|
||||||
package_info_plus: ^8.0.0 # chewie version casse couille
|
package_info_plus: ^8.0.0 # chewie version casse couille
|
||||||
@ -46,7 +48,7 @@ dependencies:
|
|||||||
http: ^1.2.0
|
http: ^1.2.0
|
||||||
auto_size_text: ^3.0.0
|
auto_size_text: ^3.0.0
|
||||||
fluttertoast:
|
fluttertoast:
|
||||||
device_info_plus: ^10.1.0
|
device_info_plus: ^10.0.0
|
||||||
enum_to_string: ^2.0.1
|
enum_to_string: ^2.0.1
|
||||||
mqtt_client: ^10.0.0
|
mqtt_client: ^10.0.0
|
||||||
photo_view: ^0.15.0
|
photo_view: ^0.15.0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user