212 lines
7.1 KiB
Dart
212 lines
7.1 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:geojson/geojson.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:http/http.dart' as http;
|
|
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(String perfecture, String cat) async {
|
|
final IndexController indexController = Get.find<IndexController>();
|
|
String url = "";
|
|
String server_url = ConstValues.currentServer();
|
|
|
|
if(cat.isNotEmpty){
|
|
if(indexController.currentUser.length > 0){
|
|
var grp = indexController.currentUser[0]["group"];
|
|
url = '${server_url}/api/inperf/?rog=True&perf=' + perfecture + '&cat=' + cat + "&grp=${grp}";
|
|
}
|
|
else {
|
|
url = '${server_url}/api/inperf/?perf=' + perfecture + '&cat=' + cat;
|
|
}
|
|
}
|
|
else{
|
|
if(indexController.currentUser.length > 0){
|
|
var grp = indexController.currentUser[0]["group"];
|
|
url = '${server_url}/api/inperf/?rog=True&perf=' + perfecture + "&grp=${grp}";
|
|
}
|
|
else {
|
|
url = '${server_url}/api/inperf/?perf=' + perfecture;
|
|
}
|
|
}
|
|
print("----loadLocationsFor url --- ${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?> loadLocationsSubFor(String subperfecture, String cat) async {
|
|
final IndexController indexController = Get.find<IndexController>();
|
|
String url = "";
|
|
String server_url = ConstValues.currentServer();
|
|
if(cat.isNotEmpty){
|
|
if(indexController.currentUser.length > 0){
|
|
var grp = indexController.currentUser[0]["group"];
|
|
url = '${server_url}/api/insubperf?rog=True&subperf=' + subperfecture + '&cat=' + cat + "&grp=${grp}";
|
|
}
|
|
else{
|
|
url = '${server_url}/api/insubperf?subperf=' + subperfecture + '&cat=' + cat;
|
|
}
|
|
}
|
|
else{
|
|
if(indexController.currentUser.length > 0){
|
|
var grp = indexController.currentUser[0]["group"];
|
|
url = '${server_url}/api/insubperf?rog=True&subperf=' + subperfecture + "&grp=${grp}";
|
|
}
|
|
else{
|
|
url = '${server_url}/api/insubperf?subperf=' + subperfecture;
|
|
}
|
|
}
|
|
print("----loadLocationsSubFor url --- ${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(double lat1, double lon1, double lat2, double lon2, double lat3, double lon3, double lat4, double lon4, String cat) async {
|
|
final IndexController indexController = Get.find<IndexController>();
|
|
String url = "";
|
|
String server_url = ConstValues.currentServer();
|
|
if(cat.isNotEmpty){
|
|
if(indexController.currentUser.length > 0){
|
|
var grp = indexController.currentUser[0]["group"];
|
|
url = '${server_url}/api/inbound?rog=True&ln1=${lon1}&la1=${lat1}&ln2=${lon2}&la2=${lat2}&ln3=${lon3}&la3=${lat3}&ln4=${lon4}&la4=${lat4}' + '&cat=' + cat + "&grp=${grp}";
|
|
}
|
|
else{
|
|
url = '${server_url}/api/inbound?ln1=${lon1}&la1=${lat1}&ln2=${lon2}&la2=${lat2}&ln3=${lon3}&la3=${lat3}&ln4=${lon4}&la4=${lat4}' + '&cat=' + cat;
|
|
}
|
|
}
|
|
else{
|
|
if(indexController.currentUser.length > 0){
|
|
var grp = indexController.currentUser[0]["group"];
|
|
url = '${server_url}/api/inbound?rog=True&ln1=${lon1}&la1=${lat1}&ln2=${lon2}&la2=${lat2}&ln3=${lon3}&la3=${lat3}&ln4=${lon4}&la4=${lat4}' + '&grp=${grp}';
|
|
}
|
|
else{
|
|
url = '${server_url}/api/inbound?ln1=${lon1}&la1=${lat1}&ln2=${lon2}&la2=${lat2}&ln3=${lon3}&la3=${lat3}&ln4=${lon4}&la4=${lat4}';
|
|
}
|
|
}
|
|
print("----loadLocationsBound url --- ${url}");
|
|
final response = await http.get(Uri.parse(url),
|
|
headers: <String, String>{
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
},
|
|
);
|
|
|
|
if (response.statusCode == 500) {
|
|
return GeoJsonFeatureCollection(); //featuresFromGeoJson(utf8.decode(response.bodyBytes));
|
|
}
|
|
|
|
if (response.statusCode == 200) {
|
|
GeoJsonFeatureCollection cc = await featuresFromGeoJson(utf8.decode(response.bodyBytes));
|
|
if(cc.collection.isEmpty){
|
|
return null;
|
|
}
|
|
else{
|
|
return cc;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
|
|
static Future<GeoJsonFeatureCollection?> loadCustomLocations(String name, String cat) async {
|
|
final IndexController indexController = Get.find<IndexController>();
|
|
String url = "";
|
|
if(cat == "-all-"){
|
|
cat = "";
|
|
}
|
|
String server_url = ConstValues.currentServer();
|
|
print("loadCustomLocations url is ----- ${cat}");
|
|
if(cat.isNotEmpty){
|
|
if(indexController.currentUser.length > 0){
|
|
var grp = indexController.currentUser[0]["group"];
|
|
url = '${server_url}/api/custom_area/?rog=True&&cat=' + cat + "&grp=${grp}";
|
|
}
|
|
else{
|
|
url = '${server_url}/api/custom_area/?&cat=' + cat;
|
|
}
|
|
}
|
|
else{
|
|
if(indexController.currentUser.length > 0){
|
|
var grp = indexController.currentUser[0]["group"];
|
|
url = '${server_url}/api/customarea?rog=True&name=${name}' + "&grp=${grp}";
|
|
}
|
|
else{
|
|
url = '${server_url}/api/customarea?name=${name}';
|
|
}
|
|
}
|
|
print("----loadCustomLocations url --- ${url}");
|
|
final response = await http.get(Uri.parse(url),
|
|
headers: <String, String>{
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
},
|
|
);
|
|
|
|
if (response.statusCode == 500) {
|
|
return GeoJsonFeatureCollection(); //featuresFromGeoJson(utf8.decode(response.bodyBytes));
|
|
}
|
|
|
|
if (response.statusCode == 200) {
|
|
GeoJsonFeatureCollection cc = await featuresFromGeoJson(utf8.decode(response.bodyBytes));
|
|
if(cc.collection.isEmpty){
|
|
return null;
|
|
}
|
|
else{
|
|
return cc;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
|
|
|
|
|
|
} |