refactoring
This commit is contained in:
@ -1,35 +1,35 @@
|
||||
import 'package:geojson/geojson.dart';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../utils/const.dart';
|
||||
|
||||
class LocationLineService{
|
||||
|
||||
static Future<GeoJsonFeature?> loadLocationLines() async {
|
||||
final geo = GeoJson();
|
||||
GeoJsonFeature? fs;
|
||||
String server_url = ConstValues.currentServer();
|
||||
String url = '${server_url}/api/location_line/';
|
||||
//String url = 'http://localhost:8100/api/location_line/';
|
||||
final response = await http.get(Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
);
|
||||
// static Future<GeoJsonFeature?> loadLocationLines() async {
|
||||
// final geo = GeoJson();
|
||||
// GeoJsonFeature? fs;
|
||||
// String server_url = ConstValues.currentServer();
|
||||
// String url = '${server_url}/api/location_line/';
|
||||
// //String url = 'http://localhost:8100/api/location_line/';
|
||||
// final response = await http.get(Uri.parse(url),
|
||||
// headers: <String, String>{
|
||||
// 'Content-Type': 'application/json; charset=UTF-8',
|
||||
// },
|
||||
// );
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
// if (response.statusCode == 200) {
|
||||
|
||||
geo.processedFeatures.listen((fst) {
|
||||
fs = fst;
|
||||
});
|
||||
// geo.processedFeatures.listen((fst) {
|
||||
// fs = fst;
|
||||
// });
|
||||
|
||||
await geo.parse(response.body, verbose:true);
|
||||
// await geo.parse(response.body, verbose:true);
|
||||
|
||||
return fs;
|
||||
// return fs;
|
||||
|
||||
} else {
|
||||
throw Exception('Failed to create album.');
|
||||
}
|
||||
}
|
||||
// } else {
|
||||
// throw Exception('Failed to create album.');
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
@ -1,36 +1,35 @@
|
||||
import 'package:geojson/geojson.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../utils/const.dart';
|
||||
|
||||
class LocationPolygonervice{
|
||||
|
||||
static Future<GeoJsonFeature?> loadLocationLines() async {
|
||||
final geo = GeoJson();
|
||||
GeoJsonFeature? fs;
|
||||
// static Future<GeoJsonFeature?> loadLocationLines() async {
|
||||
// final geo = GeoJson();
|
||||
// GeoJsonFeature? fs;
|
||||
|
||||
String server_url = ConstValues.currentServer();
|
||||
String url = '${server_url}/api/location_polygon/';
|
||||
//String url = 'http://localhost:8100/api/location_polygon/';
|
||||
final response = await http.get(Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
);
|
||||
// String server_url = ConstValues.currentServer();
|
||||
// String url = '${server_url}/api/location_polygon/';
|
||||
// //String url = 'http://localhost:8100/api/location_polygon/';
|
||||
// final response = await http.get(Uri.parse(url),
|
||||
// headers: <String, String>{
|
||||
// 'Content-Type': 'application/json; charset=UTF-8',
|
||||
// },
|
||||
// );
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
// if (response.statusCode == 200) {
|
||||
|
||||
geo.processedFeatures.listen((fst) {
|
||||
fs = fst;
|
||||
});
|
||||
// geo.processedFeatures.listen((fst) {
|
||||
// fs = fst;
|
||||
// });
|
||||
|
||||
await geo.parse(response.body, verbose:true);
|
||||
// await geo.parse(response.body, verbose:true);
|
||||
|
||||
return fs;
|
||||
// return fs;
|
||||
|
||||
} else {
|
||||
throw Exception('Failed to create album.');
|
||||
}
|
||||
}
|
||||
// } else {
|
||||
// throw Exception('Failed to create album.');
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
@ -1,15 +1,20 @@
|
||||
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/model/location.dart';
|
||||
import 'package:rogapp/utils/const.dart';
|
||||
|
||||
class LocationService{
|
||||
class LocationService extends GetxService{
|
||||
Future<LocationService> init() async {
|
||||
print('$runtimeType ready!');
|
||||
return this;
|
||||
}
|
||||
|
||||
static Future<GeoJsonFeatureCollection?> loadLocations() async {
|
||||
String server_url = ConstValues.currentServer();
|
||||
String url = '${server_url}/api/location/';
|
||||
//String url = 'http://localhost:8100/api/location/';
|
||||
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',
|
||||
@ -17,25 +22,29 @@ class LocationService{
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
|
||||
return featuresFromGeoJson(utf8.decode(response.bodyBytes));
|
||||
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 null;
|
||||
return locs;
|
||||
}
|
||||
|
||||
static Future<GeoJsonFeatureCollection?> loadLocationsFor(String perfecture, String cat) async {
|
||||
Future<List<Location>> loadLocationsFor(String perfecture, String cat) async {
|
||||
List<Location> locs = [];
|
||||
String url = "";
|
||||
String server_url = ConstValues.currentServer();
|
||||
String serverUrl = ConstValues.currentServer();
|
||||
if(cat.isNotEmpty){
|
||||
url = '${server_url}/api/inperf/?perf=' + perfecture + '&cat=' + cat;
|
||||
//url = 'http://localhost:8100/api/inperf/?perf=' + perfecture + '&cat=' + cat;
|
||||
url = '${serverUrl}/api/inperf/?perf=' + perfecture + '&cat=' + cat;
|
||||
}
|
||||
else{
|
||||
url = '${server_url}/api/inperf/?perf=' + perfecture;
|
||||
//url = 'http://localhost:8100/api/inperf/?perf=' + perfecture;
|
||||
url = '${serverUrl}/api/inperf/?perf=' + perfecture;
|
||||
}
|
||||
//print("----- url ---- ${url} --- ${cat}");
|
||||
//String url = 'http://localhost:8100/api/inperf/?perf=' + perfecture + '&cat=' + cat;
|
||||
final response = await http.get(Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
@ -43,25 +52,29 @@ class LocationService{
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
GeoJsonFeatureCollection cc = await featuresFromGeoJson(utf8.decode(response.bodyBytes));
|
||||
//print(cc);
|
||||
return cc; //featuresFromGeoJson(utf8.decode(response.bodyBytes));
|
||||
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 null;
|
||||
return locs;
|
||||
}
|
||||
|
||||
|
||||
static Future<GeoJsonFeatureCollection?> loadLocationsSubFor(String subperfecture, String cat) async {
|
||||
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;
|
||||
//url = 'http://localhost:8100/api/insubperf?subperf=' + subperfecture + '&cat=' + cat;
|
||||
}
|
||||
else{
|
||||
print("------ loading location in sub----");
|
||||
url = '${server_url}/api/insubperf?subperf=' + subperfecture;
|
||||
//url = 'http://localhost:8100/api/insubperf?subperf=' + subperfecture;
|
||||
}
|
||||
final response = await http.get(Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
@ -70,55 +83,52 @@ class LocationService{
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
GeoJsonFeatureCollection cc = await featuresFromGeoJson(utf8.decode(response.bodyBytes));
|
||||
//print(cc);
|
||||
return cc; //featuresFromGeoJson(utf8.decode(response.bodyBytes));
|
||||
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 null;
|
||||
return locs;
|
||||
}
|
||||
|
||||
|
||||
static Future<GeoJsonFeatureCollection?> loadLocationsBound(double lat1, double lon1, double lat2, double lon2, double lat3, double lon3, double lat4, double lon4, String cat) async {
|
||||
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}");
|
||||
//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;
|
||||
//url = 'http://localhost:8100/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}';
|
||||
//url = 'http://localhost:8100/api/inbound?ln1=${lon1}&la1=${lat1}&ln2=${lon2}&la2=${lat2}&ln3=${lon3}&la3=${lat3}&ln4=${lon4}&la4=${lat4}';
|
||||
}
|
||||
print("----url --- ${url}");
|
||||
//print("----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;
|
||||
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 null;
|
||||
return locs;
|
||||
}
|
||||
|
||||
|
||||
static Future<GeoJsonFeatureCollection?> loadCustomLocations(String name, String cat) async {
|
||||
Future<List<Location>> loadCustomLocations(String name, String cat) async {
|
||||
List<Location> locs = [];
|
||||
String url = "";
|
||||
if(cat == "-all-"){
|
||||
cat = "";
|
||||
}
|
||||
String server_url = ConstValues.currentServer();
|
||||
print("cat is ----- ${cat}");
|
||||
if(cat.isNotEmpty){
|
||||
@ -136,23 +146,18 @@ class LocationService{
|
||||
},
|
||||
);
|
||||
|
||||
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;
|
||||
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 null;
|
||||
return locs;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user