164 lines
5.3 KiB
Dart
164 lines
5.3 KiB
Dart
import 'dart:convert';
|
|
import 'package:geojson_vi/geojson_vi.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:rogapp/model/location.dart';
|
|
import 'package:rogapp/utils/const.dart';
|
|
|
|
class LocationService extends GetxService{
|
|
Future<LocationService> init() async {
|
|
print('$runtimeType ready!');
|
|
return this;
|
|
}
|
|
|
|
Future<List<Location>> loadLocations() async {
|
|
List<Location> locs = [];
|
|
String serverUrl = ConstValues.currentServer();
|
|
String url = '${serverUrl}/api/location/';
|
|
final response = await http.get(Uri.parse(url),
|
|
headers: <String, String>{
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
},
|
|
);
|
|
|
|
if (response.statusCode == 200) {
|
|
GeoJSONFeatureCollection coll = GeoJSONFeatureCollection.fromJSON(utf8.decode(response.bodyBytes));
|
|
for(int i=0; i<coll.features.length; i++ ){
|
|
GeoJSONFeature? gf = coll.features[i];
|
|
if(gf != null){
|
|
Location l = Location.fromGeoJSONFeture(gf);
|
|
locs.add(l);
|
|
}
|
|
}
|
|
}
|
|
return locs;
|
|
}
|
|
|
|
Future<List<Location>> loadLocationsFor(String perfecture, String cat) async {
|
|
List<Location> locs = [];
|
|
String url = "";
|
|
String serverUrl = ConstValues.currentServer();
|
|
if(cat.isNotEmpty){
|
|
url = '${serverUrl}/api/inperf/?perf=' + perfecture + '&cat=' + cat;
|
|
}
|
|
else{
|
|
url = '${serverUrl}/api/inperf/?perf=' + perfecture;
|
|
}
|
|
//print("----- url ---- ${url} --- ${cat}");
|
|
final response = await http.get(Uri.parse(url),
|
|
headers: <String, String>{
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
},
|
|
);
|
|
|
|
if (response.statusCode == 200) {
|
|
GeoJSONFeatureCollection coll = GeoJSONFeatureCollection.fromJSON(utf8.decode(response.bodyBytes));
|
|
for(int i=0; i<coll.features.length; i++ ){
|
|
GeoJSONFeature? gf = coll.features[i];
|
|
if(gf != null){
|
|
Location l = Location.fromGeoJSONFeture(gf);
|
|
locs.add(l);
|
|
}
|
|
}
|
|
}
|
|
return locs;
|
|
}
|
|
|
|
|
|
Future<List<Location>> loadLocationsSubFor(String subperfecture, String cat) async {
|
|
List<Location> locs = [];
|
|
String url = "";
|
|
String server_url = ConstValues.currentServer();
|
|
if(cat.isNotEmpty){
|
|
url = '${server_url}/api/insubperf?subperf=' + subperfecture + '&cat=' + cat;
|
|
}
|
|
else{
|
|
print("------ loading location in sub----");
|
|
url = '${server_url}/api/insubperf?subperf=' + subperfecture;
|
|
}
|
|
final response = await http.get(Uri.parse(url),
|
|
headers: <String, String>{
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
},
|
|
);
|
|
|
|
if (response.statusCode == 200) {
|
|
GeoJSONFeatureCollection coll = GeoJSONFeatureCollection.fromJSON(utf8.decode(response.bodyBytes));
|
|
for(int i=0; i<coll.features.length; i++ ){
|
|
GeoJSONFeature? gf = coll.features[i];
|
|
if(gf != null){
|
|
Location l = Location.fromGeoJSONFeture(gf);
|
|
locs.add(l);
|
|
}
|
|
}
|
|
}
|
|
return locs;
|
|
}
|
|
|
|
Future<List<Location>> loadLocationsBound(double lat1, double lon1, double lat2, double lon2, double lat3, double lon3, double lat4, double lon4, String cat) async {
|
|
List<Location> locs = [];
|
|
String url = "";
|
|
String server_url = ConstValues.currentServer();
|
|
//print("cat is ----- ${cat}");
|
|
if(cat.isNotEmpty){
|
|
url = '${server_url}/api/inbound?ln1=${lon1}&la1=${lat1}&ln2=${lon2}&la2=${lat2}&ln3=${lon3}&la3=${lat3}&ln4=${lon4}&la4=${lat4}' + '&cat=' + cat;
|
|
}
|
|
else{
|
|
url = '${server_url}/api/inbound?ln1=${lon1}&la1=${lat1}&ln2=${lon2}&la2=${lat2}&ln3=${lon3}&la3=${lat3}&ln4=${lon4}&la4=${lat4}';
|
|
}
|
|
//print("----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 coll = GeoJSONFeatureCollection.fromJSON(utf8.decode(response.bodyBytes));
|
|
for(int i=0; i<coll.features.length; i++ ){
|
|
GeoJSONFeature? gf = coll.features[i];
|
|
if(gf != null){
|
|
Location l = Location.fromGeoJSONFeture(gf);
|
|
locs.add(l);
|
|
}
|
|
}
|
|
}
|
|
return locs;
|
|
}
|
|
|
|
Future<List<Location>> loadCustomLocations(String name, String cat) async {
|
|
List<Location> locs = [];
|
|
String url = "";
|
|
String server_url = ConstValues.currentServer();
|
|
print("cat is ----- ${cat}");
|
|
if(cat.isNotEmpty){
|
|
url = '${server_url}/api/custom_area/?&cat=' + cat;
|
|
//url = 'http://localhost:8100/api/customarea?name=${name}&cat=' + cat;
|
|
}
|
|
else{
|
|
url = '${server_url}/api/customarea?name=${name}&';
|
|
//url = 'http://localhost:8100/api/customarea?name=${name}&';
|
|
}
|
|
print("----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 coll = GeoJSONFeatureCollection.fromJSON(utf8.decode(response.bodyBytes));
|
|
for(int i=0; i<coll.features.length; i++ ){
|
|
GeoJSONFeature? gf = coll.features[i];
|
|
if(gf != null){
|
|
Location l = Location.fromGeoJSONFeture(gf);
|
|
locs.add(l);
|
|
}
|
|
}
|
|
}
|
|
return locs;
|
|
}
|
|
|
|
}
|
|
|