map updated to 6

This commit is contained in:
2023-12-06 11:16:17 +05:30
parent 8d1c84d9fb
commit fa0587178f
19 changed files with 631 additions and 596 deletions

View File

@ -1,39 +1,13 @@
import 'dart:convert';
import 'package:geojson/geojson.dart';
import 'package:geojson_vi/geojson_vi.dart';
import 'package:get/get.dart';
import 'package:http/http.dart' as http;
import 'package:rogapp/pages/destination/destination_controller.dart';
import 'package:rogapp/pages/index/index_controller.dart';
import 'package:rogapp/utils/const.dart';
class LocationService {
// static Future<GeoJsonFeatureCollection?> loadLocations() async {
// final IndexController indexController = Get.find<IndexController>();
// String server_url = ConstValues.currentServer();
// String url = "";
// if(indexController.currentUser.length > 0){
// url = '${server_url}/api/location/?is_rog=True';
// }
// else {
// url = '${server_url}/api/location/';
// }
// //String url = 'http://localhost:8100/api/location/';
// final response = await http.get(Uri.parse(url),
// headers: <String, String>{
// 'Content-Type': 'application/json; charset=UTF-8',
// },
// );
// if (response.statusCode == 200) {
// return featuresFromGeoJson(utf8.decode(response.bodyBytes));
// }
// return null;
// }
static Future<GeoJsonFeatureCollection?> loadLocationsFor(
static Future<GeoJSONFeatureCollection?> loadLocationsFor(
String perfecture, String cat) async {
final IndexController indexController = Get.find<IndexController>();
String url = "";
@ -67,8 +41,8 @@ class LocationService {
);
if (response.statusCode == 200) {
GeoJsonFeatureCollection cc =
await featuresFromGeoJson(utf8.decode(response.bodyBytes));
GeoJSONFeatureCollection cc =
GeoJSONFeatureCollection.fromJSON(utf8.decode(response.bodyBytes));
//print(cc);
return cc; //featuresFromGeoJson(utf8.decode(response.bodyBytes));
}
@ -95,48 +69,7 @@ class LocationService {
return ext;
}
static Future<GeoJsonFeatureCollection?> loadLocationsSubFor(
String subperfecture, String cat) async {
final IndexController indexController = Get.find<IndexController>();
String url = "";
String serverUrl = ConstValues.currentServer();
if (cat.isNotEmpty) {
if (indexController.currentUser.isNotEmpty) {
bool rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = rog == true ? 'True' : 'False';
var grp = indexController.currentUser[0]['user']['event_code'];
url = '$serverUrl/api/insubperf?rog=$r&subperf=$subperfecture&cat=$cat';
} else {
url = '$serverUrl/api/insubperf?subperf=$subperfecture&cat=$cat';
}
} else {
if (indexController.currentUser.isNotEmpty) {
bool rog = indexController.currentUser[0]['user']['is_rogaining'];
String r = rog == true ? 'True' : 'False';
var grp = indexController.currentUser[0]['user']['event_code'];
url = '$serverUrl/api/insubperf?rog=$r&subperf=$subperfecture';
} else {
url = '$serverUrl/api/insubperf?subperf=$subperfecture';
}
}
//print('++++++++$url');
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));
//print(cc);
return cc; //featuresFromGeoJson(utf8.decode(response.bodyBytes));
}
return null;
}
static Future<GeoJsonFeatureCollection?> loadLocationsBound(
static Future<GeoJSONFeatureCollection?> loadLocationsBound(
double lat1,
double lon1,
double lat2,
@ -183,13 +116,15 @@ class LocationService {
);
if (response.statusCode == 500) {
return GeoJsonFeatureCollection(); //featuresFromGeoJson(utf8.decode(response.bodyBytes));
return null; //featuresFromGeoJson(utf8.decode(response.bodyBytes));
}
if (response.statusCode == 200) {
GeoJsonFeatureCollection cc =
await featuresFromGeoJson(utf8.decode(response.bodyBytes));
if (cc.collection.isEmpty) {
DestinationController destinationController =
Get.find<DestinationController>();
GeoJSONFeatureCollection cc =
GeoJSONFeatureCollection.fromJSON(utf8.decode(response.bodyBytes));
if (cc.features.isEmpty) {
return null;
} else {
//print("---- feature got from server is ${cc.collection[0].properties} ------");
@ -199,7 +134,7 @@ class LocationService {
return null;
}
static Future<GeoJsonFeatureCollection?> loadCustomLocations(
static Future<GeoJSONFeatureCollection?> loadCustomLocations(
String name, String cat) async {
final IndexController indexController = Get.find<IndexController>();
String url = "";
@ -236,13 +171,13 @@ class LocationService {
);
if (response.statusCode == 500) {
return GeoJsonFeatureCollection(); //featuresFromGeoJson(utf8.decode(response.bodyBytes));
return null; //featuresFromGeoJson(utf8.decode(response.bodyBytes));
}
if (response.statusCode == 200) {
GeoJsonFeatureCollection cc =
await featuresFromGeoJson(utf8.decode(response.bodyBytes));
if (cc.collection.isEmpty) {
GeoJSONFeatureCollection cc =
GeoJSONFeatureCollection.fromJSON(utf8.decode(response.bodyBytes));
if (cc.features.isEmpty) {
return null;
} else {
return cc;