update
This commit is contained in:
@ -1,7 +1,10 @@
|
|||||||
|
|
||||||
|
|
||||||
|
import 'package:flutter_map/plugin_api.dart';
|
||||||
import 'package:geojson/geojson.dart';
|
import 'package:geojson/geojson.dart';
|
||||||
import 'package:get/get.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/location_service.dart';
|
||||||
import 'package:rogapp/services/perfecture_service.dart';
|
import 'package:rogapp/services/perfecture_service.dart';
|
||||||
|
|
||||||
@ -10,20 +13,86 @@ class HomeController extends GetxController {
|
|||||||
List<GeoJsonFeatureCollection> locations = <GeoJsonFeatureCollection>[].obs;
|
List<GeoJsonFeatureCollection> locations = <GeoJsonFeatureCollection>[].obs;
|
||||||
List<GeoJsonFeature> currentFeature = <GeoJsonFeature>[].obs;
|
List<GeoJsonFeature> currentFeature = <GeoJsonFeature>[].obs;
|
||||||
List<dynamic> perfectures = <dynamic>[].obs;
|
List<dynamic> perfectures = <dynamic>[].obs;
|
||||||
|
List<LatLngBounds> currentBound = <LatLngBounds>[].obs;
|
||||||
|
List<dynamic> subPerfs = <dynamic>[].obs;
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
|
||||||
LocationService.loadLocations().then((value){
|
LocationService.loadLocations().then((value){
|
||||||
locations.add(value!);
|
locations.add(value!);
|
||||||
});
|
});
|
||||||
|
|
||||||
PerfectureService.loadPerfectures().then((value){
|
PerfectureService.loadPerfectures().then((value){
|
||||||
perfectures.add(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){
|
GeoJsonFeature? getFeatureForLatLong(double lat, double long){
|
||||||
|
|||||||
@ -21,7 +21,26 @@ class MapPage extends StatelessWidget {
|
|||||||
|
|
||||||
final HomeController homeController = Get.find<HomeController>();
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -68,16 +87,8 @@ class MapPage extends StatelessWidget {
|
|||||||
height: 50.0,
|
height: 50.0,
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
scrollDirection: Axis.horizontal,
|
scrollDirection: Axis.horizontal,
|
||||||
child: BreadCrumb(
|
child:
|
||||||
items: <BreadCrumbItem>[
|
getBreadCurms(),
|
||||||
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),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
@ -87,7 +98,9 @@ class MapPage extends StatelessWidget {
|
|||||||
FlutterMap(
|
FlutterMap(
|
||||||
mapController: mapController,
|
mapController: mapController,
|
||||||
options: MapOptions(
|
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,
|
zoom: 6,
|
||||||
maxZoom: 20,
|
maxZoom: 20,
|
||||||
plugins: [
|
plugins: [
|
||||||
@ -121,13 +134,14 @@ class MapPage extends StatelessWidget {
|
|||||||
builder:((context) => BottomSheetWidget())
|
builder:((context) => BottomSheetWidget())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
size: Size(40, 40),
|
size: Size(40, 40),
|
||||||
anchor: AnchorPos.align(AnchorAlign.center),
|
anchor: AnchorPos.align(AnchorAlign.center),
|
||||||
fitBoundsOptions: const FitBoundsOptions(
|
fitBoundsOptions: const FitBoundsOptions(
|
||||||
padding: EdgeInsets.all(50),
|
padding: EdgeInsets.all(50),
|
||||||
maxZoom: 15,
|
maxZoom: 265,
|
||||||
),
|
),
|
||||||
markers:homeController.locations[0].collection.map((i) {
|
markers:homeController.locations[0].collection.map((i) {
|
||||||
GeoJsonMultiPoint p = i.geometry as GeoJsonMultiPoint;
|
GeoJsonMultiPoint p = i.geometry as GeoJsonMultiPoint;
|
||||||
|
|||||||
@ -8,7 +8,6 @@ class LocationService{
|
|||||||
static Future<GeoJsonFeatureCollection?> loadLocations() async {
|
static Future<GeoJsonFeatureCollection?> loadLocations() async {
|
||||||
final geo = GeoJson();
|
final geo = GeoJson();
|
||||||
GeoJsonFeatureCollection? fs;
|
GeoJsonFeatureCollection? fs;
|
||||||
print("#### feature collection ####");
|
|
||||||
String url = 'http://localhost:8100/api/location/';
|
String url = 'http://localhost:8100/api/location/';
|
||||||
final response = await http.get(Uri.parse(url),
|
final response = await http.get(Uri.parse(url),
|
||||||
headers: <String, String>{
|
headers: <String, String>{
|
||||||
@ -22,4 +21,22 @@ class LocationService{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<GeoJsonFeatureCollection?> loadLocationsFor(String perfecture) async {
|
||||||
|
final geo = GeoJson();
|
||||||
|
GeoJsonFeatureCollection? fs;
|
||||||
|
String url = 'http://localhost:8100/api/inperf/?perf=' + perfecture;
|
||||||
|
final response = await http.get(Uri.parse(url),
|
||||||
|
headers: <String, String>{
|
||||||
|
'Content-Type': 'application/json; charset=UTF-8',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
GeoJsonFeatureCollection cc = await featuresFromGeoJson(utf8.decode(response.bodyBytes));
|
||||||
|
return cc; //featuresFromGeoJson(utf8.decode(response.bodyBytes));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -6,7 +6,7 @@ class PerfectureService{
|
|||||||
|
|
||||||
static Future<List<dynamic>?> loadPerfectures() async {
|
static Future<List<dynamic>?> loadPerfectures() async {
|
||||||
List<dynamic> perfs = [];
|
List<dynamic> perfs = [];
|
||||||
String url = 'http://localhost:8100/api/perf/';
|
String url = 'http://localhost:8100/api/perf_main/';
|
||||||
final response = await http.get(Uri.parse(url),
|
final response = await http.get(Uri.parse(url),
|
||||||
headers: <String, String>{
|
headers: <String, String>{
|
||||||
'Content-Type': 'application/json; charset=UTF-8',
|
'Content-Type': 'application/json; charset=UTF-8',
|
||||||
@ -15,10 +15,27 @@ class PerfectureService{
|
|||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
|
|
||||||
perfs = json.decode(response.body);
|
perfs = json.decode(utf8.decode(response.bodyBytes));
|
||||||
}
|
}
|
||||||
return perfs;
|
return perfs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<List<dynamic>?> loadSubPerfectures(String sub) async {
|
||||||
|
List<dynamic> perfs = [];
|
||||||
|
String url = 'http://localhost:8100/api/insubperf/?perf=' + sub;
|
||||||
|
final response = await http.get(Uri.parse(url),
|
||||||
|
headers: <String, String>{
|
||||||
|
'Content-Type': 'application/json; charset=UTF-8',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
|
||||||
|
perfs = json.decode(utf8.decode(response.bodyBytes));
|
||||||
|
}
|
||||||
|
return perfs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,33 +1,31 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:geojson/geojson.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:rogapp/pages/home/home_controller.dart';
|
import 'package:rogapp/pages/home/home_controller.dart';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PerfectureWidget extends StatefulWidget {
|
class PerfectureWidget extends StatefulWidget {
|
||||||
PerfectureWidget({Key? key}) : super(key: key);
|
|
||||||
|
|
||||||
final HomeController homeController = Get.find<HomeController>();
|
HomeController homeController;
|
||||||
|
|
||||||
|
PerfectureWidget({required this.homeController});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<PerfectureWidget> createState() => _PerfectureWidgetState();
|
State<PerfectureWidget> createState() => _PerfectureWidgetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _PerfectureWidgetState extends State<PerfectureWidget> {
|
class _PerfectureWidgetState extends State<PerfectureWidget> {
|
||||||
String dropdownValue = 'One';
|
String dropdownValue = "1";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
List<DropdownMenuItem<String>> getDropdownItems() {
|
List<DropdownMenuItem<String>> getDropdownItems() {
|
||||||
List<DropdownMenuItem<String>> dropDownItems = [];
|
List<DropdownMenuItem<String>> dropDownItems = [];
|
||||||
|
|
||||||
print("---------");
|
for (Map<String, dynamic> currency in widget.homeController.perfectures[0]) {
|
||||||
print(widget.homeController.perfectures);
|
//print(currency["id"].toString());
|
||||||
|
|
||||||
for (List<String> currency in widget.homeController.perfectures[0]) {
|
|
||||||
var newDropdown = DropdownMenuItem(
|
var newDropdown = DropdownMenuItem(
|
||||||
child: Text("dddd"),
|
child: Text(currency["adm1_ja"].toString()),
|
||||||
value: "qqqq",
|
value: currency["id"].toString(),
|
||||||
);
|
);
|
||||||
|
|
||||||
dropDownItems.add(newDropdown);
|
dropDownItems.add(newDropdown);
|
||||||
@ -35,11 +33,30 @@ class _PerfectureWidgetState extends State<PerfectureWidget> {
|
|||||||
return dropDownItems;
|
return dropDownItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<DropdownMenuItem<String>> getSubDropdownItems() {
|
||||||
|
List<DropdownMenuItem<String>> dropDownItems = [];
|
||||||
|
if(widget.homeController.subPerfs.length > 0){
|
||||||
|
for (Map<String, dynamic> currency in widget.homeController.subPerfs[0]) {
|
||||||
|
//print(currency["id"].toString());
|
||||||
|
var newDropdown = DropdownMenuItem(
|
||||||
|
child: Text(currency["adm2_l"].toString()),
|
||||||
|
value: currency["id"].toString(),
|
||||||
|
);
|
||||||
|
|
||||||
|
dropDownItems.add(newDropdown);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dropDownItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return DropdownButton<String>(
|
return Obx(() =>
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
DropdownButton<String>(
|
||||||
value: dropdownValue,
|
value: dropdownValue,
|
||||||
icon: const Icon(Icons.arrow_downward),
|
icon: const Icon(Icons.arrow_downward),
|
||||||
elevation: 16,
|
elevation: 16,
|
||||||
@ -51,9 +68,37 @@ class _PerfectureWidgetState extends State<PerfectureWidget> {
|
|||||||
onChanged: (String? newValue) {
|
onChanged: (String? newValue) {
|
||||||
setState(() {
|
setState(() {
|
||||||
dropdownValue = newValue!;
|
dropdownValue = newValue!;
|
||||||
|
print(newValue);
|
||||||
|
widget.homeController.loadLocationforPerf(newValue);
|
||||||
|
widget.homeController.loadSubPerfFor(newValue);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
items:getDropdownItems());
|
items:getDropdownItems()),
|
||||||
|
|
||||||
|
widget.homeController.subPerfs.length > 0 ?
|
||||||
|
|
||||||
|
DropdownButton<String>(
|
||||||
|
value: widget.homeController.getSubInitialVal(),
|
||||||
|
icon: const Icon(Icons.arrow_downward),
|
||||||
|
elevation: 16,
|
||||||
|
style: const TextStyle(color: Colors.deepPurple),
|
||||||
|
underline: Container(
|
||||||
|
height: 2,
|
||||||
|
color: Colors.deepPurpleAccent,
|
||||||
|
),
|
||||||
|
onChanged: (String? newValue) {
|
||||||
|
setState(() {
|
||||||
|
dropdownValue = newValue!;
|
||||||
|
print(newValue);
|
||||||
|
//widget.homeController.loadLocationforPerf(newValue);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
items:getSubDropdownItems()) :
|
||||||
|
Text("--")
|
||||||
|
|
||||||
|
],
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user