This commit is contained in:
Mohamed Nouffer
2022-03-30 16:19:18 +05:30
parent ea874c094c
commit ee3845681d
5 changed files with 193 additions and 31 deletions

View File

@ -1,7 +1,10 @@
import 'package:flutter_map/plugin_api.dart';
import 'package:geojson/geojson.dart';
import 'package:get/get.dart';
import 'package:latlong2/latlong.dart';
import 'package:rogapp/pages/map/map_page.dart';
import 'package:rogapp/services/location_service.dart';
import 'package:rogapp/services/perfecture_service.dart';
@ -10,20 +13,86 @@ class HomeController extends GetxController {
List<GeoJsonFeatureCollection> locations = <GeoJsonFeatureCollection>[].obs;
List<GeoJsonFeature> currentFeature = <GeoJsonFeature>[].obs;
List<dynamic> perfectures = <dynamic>[].obs;
List<LatLngBounds> currentBound = <LatLngBounds>[].obs;
List<dynamic> subPerfs = <dynamic>[].obs;
@override
void onInit() {
super.onInit();
LocationService.loadLocations().then((value){
locations.add(value!);
});
PerfectureService.loadPerfectures().then((value){
perfectures.add(value);
print(perfectures);
});
super.onInit();
}
void getBoundFromLatLng(List<LatLng> list) {
double? x0, x1, y0, y1;
for (LatLng latLng in list) {
if (x0 == null) {
x0 = x1 = latLng.latitude;
y0 = y1 = latLng.longitude;
} else {
if (latLng.latitude > x1!) x1 = latLng.latitude;
if (latLng.latitude < x0) x0 = latLng.latitude;
if (latLng.longitude > y1!) y1 = latLng.longitude;
if (latLng.longitude < y0!) y0 = latLng.longitude;
}
}
currentBound.clear();
currentBound.add(LatLngBounds(LatLng(x1!, y1!), LatLng(x0!, y0!)));
}
void setBounds(){
List<LatLng> lts = [];
if(locations.length > 0){
for(GeoJsonFeature i in locations[0].collection){
GeoJsonMultiPoint p = i.geometry as GeoJsonMultiPoint;
LatLng lt = LatLng(p.geoSerie!.geoPoints[0].latitude , p.geoSerie!.geoPoints[0].longitude) ;
lts.add(lt);
}
}
else{
LatLng lt = LatLng(37.15319600454702, 139.58765950528198);
lts.add(lt);
}
getBoundFromLatLng(lts);
}
void loadLocationforPerf(String perf){
locations.clear();
LocationService.loadLocationsFor(perf).then((value){
locations.add(value!);
setBounds();
MapPage.mapController.fitBounds(currentBound[0]);
});
}
String getSubInitialVal(){
int min = 0;
if(subPerfs.length > 0){
min = subPerfs[0][0]['id'] as int;
for(var sub in subPerfs[0]){
int x = sub['id'] as int;
if(x < min){
min = x;
}
}
}
return min.toString();
}
void loadSubPerfFor(String perf){
subPerfs.clear();
PerfectureService.loadSubPerfectures(perf).then((value){
subPerfs.add(value);
print(subPerfs);
});
}
GeoJsonFeature? getFeatureForLatLong(double lat, double long){

View File

@ -21,7 +21,26 @@ class MapPage extends StatelessWidget {
final HomeController homeController = Get.find<HomeController>();
final MapController mapController = MapController();
static final MapController mapController = MapController();
Widget getBreadCurms(){
print("---------map-------------");
return Obx(() =>
homeController.perfectures.length > 0 ?
BreadCrumb.builder(
itemCount: homeController.perfectures.length,
builder: (index) {
return BreadCrumbItem(
content: PerfectureWidget(homeController: homeController,) //Text('Item$index')
);
},
divider: Icon(Icons.chevron_right),
) :
Container(width: 0, height: 0,),
);
}
@override
Widget build(BuildContext context) {
@ -68,16 +87,8 @@ class MapPage extends StatelessWidget {
height: 50.0,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: BreadCrumb(
items: <BreadCrumbItem>[
BreadCrumbItem(content:
//Text('Item1', style: TextStyle(fontSize: 16.0, fontWeight: FontWeight.bold),)
PerfectureWidget(),
),
BreadCrumbItem(content: Text('Item2', style: TextStyle(fontSize: 16.0, fontWeight: FontWeight.bold),)),
],
divider: Icon(Icons.chevron_right),
),
child:
getBreadCurms(),
),
),
Expanded(
@ -87,7 +98,9 @@ class MapPage extends StatelessWidget {
FlutterMap(
mapController: mapController,
options: MapOptions(
center: LatLng(37.15319600454702, 139.58765950528198),
//center: LatLng(37.15319600454702, 139.58765950528198),
bounds: homeController.currentBound.length > 0 ? homeController.currentBound[0]: LatLngBounds.fromPoints([LatLng(37.15319600454702, 139.58765950528198)]),
zoom: 6,
maxZoom: 20,
plugins: [
@ -121,13 +134,14 @@ class MapPage extends StatelessWidget {
builder:((context) => BottomSheetWidget())
);
}
},
size: Size(40, 40),
anchor: AnchorPos.align(AnchorAlign.center),
fitBoundsOptions: const FitBoundsOptions(
padding: EdgeInsets.all(50),
maxZoom: 15,
maxZoom: 265,
),
markers:homeController.locations[0].collection.map((i) {
GeoJsonMultiPoint p = i.geometry as GeoJsonMultiPoint;