Added Monitorized Areas
This commit is contained in:
parent
864ee28584
commit
e50ff5179b
16 changed files with 223 additions and 19 deletions
|
|
@ -1,16 +1,18 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:comunes_flutter/comunes_flutter.dart';
|
||||
import 'package:connectivity/connectivity.dart';
|
||||
import 'package:fires_flutter/models/fireNotification.dart';
|
||||
import 'package:fires_flutter/models/yourLocation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:connectivity/connectivity.dart';
|
||||
|
||||
import 'fireMapState.dart';
|
||||
import 'user.dart';
|
||||
|
||||
export 'fireMapState.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
|
||||
part 'appState.g.dart';
|
||||
|
||||
|
|
@ -36,6 +38,8 @@ class AppState extends Object with _$AppStateSerializerMixin {
|
|||
final List<YourLocation> yourLocations;
|
||||
final List<FireNotification> fireNotifications;
|
||||
@JsonKey(ignore: true)
|
||||
final List<Polyline> monitoredAreas;
|
||||
@JsonKey(ignore: true)
|
||||
final int fireNotificationsUnread;
|
||||
@JsonKey(ignore: true)
|
||||
final FireMapState fireMapState;
|
||||
|
|
@ -58,7 +62,8 @@ class AppState extends Object with _$AppStateSerializerMixin {
|
|||
this.firesApiKey,
|
||||
this.firesApiUrl,
|
||||
this.serverUrl,
|
||||
this.connectivity,
|
||||
this.connectivity,
|
||||
this.monitoredAreas,
|
||||
this.fireMapState: const FireMapState.initial()});
|
||||
|
||||
AppState copyWith(
|
||||
|
|
@ -74,6 +79,7 @@ class AppState extends Object with _$AppStateSerializerMixin {
|
|||
List<FireNotification> fireNotifications,
|
||||
int fireNotificationsUnread,
|
||||
FireMapState fireMapState,
|
||||
List<Polyline> monitoredAreas,
|
||||
ConnectivityResult connectivity}) {
|
||||
return new AppState(
|
||||
isLoading: isLoading ?? this.isLoading,
|
||||
|
|
@ -88,13 +94,15 @@ class AppState extends Object with _$AppStateSerializerMixin {
|
|||
fireNotifications: fireNotifications ?? this.fireNotifications,
|
||||
fireNotificationsUnread:
|
||||
fireNotificationsUnread ?? this.fireNotificationsUnread,
|
||||
monitoredAreas: monitoredAreas ?? this.monitoredAreas,
|
||||
fireMapState: fireMapState ?? this.fireMapState,
|
||||
connectivity: connectivity ?? this.connectivity);
|
||||
connectivity: connectivity ?? this.connectivity);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'AppState{\nuser: ${user}\nconnectivity: ${connectivity.toString()}\nisLoading: $isLoading\nisLoaded: $isLoaded\napiKey: ${ellipse(
|
||||
return 'AppState{\nuser: ${user}\nconnectivity: ${connectivity
|
||||
.toString()}\nisLoading: $isLoading\nisLoaded: $isLoaded\napiKey: ${ellipse(
|
||||
firesApiKey,
|
||||
8)}\napiUrl: ${firesApiUrl}\nserverUrl: ${serverUrl}\nfireMapState: $fireMapState\nyourLocations count: ${yourLocations
|
||||
.length}\nunread notif: ${fireNotificationsUnread}\nfireNotifications: ${fireNotifications}\nyourLocations: ${yourLocations}}';
|
||||
|
|
|
|||
1
lib/models/falsePositiveTypes.dart
Normal file
1
lib/models/falsePositiveTypes.dart
Normal file
|
|
@ -0,0 +1 @@
|
|||
enum FalsePositiveType { industry, controled, falsealarm }
|
||||
|
|
@ -1,10 +1,13 @@
|
|||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:bson_objectid/bson_objectid.dart';
|
||||
import 'package:fires_flutter/models/yourLocation.dart';
|
||||
import 'package:http/http.dart' as ht;
|
||||
import 'package:jaguar_resty/jaguar_resty.dart' as resty;
|
||||
import 'package:latlong/latlong.dart';
|
||||
|
||||
import '../globals.dart' as globals;
|
||||
import '../redux/actions.dart';
|
||||
|
|
@ -114,7 +117,7 @@ class FiresApi {
|
|||
}
|
||||
|
||||
Future<UpdateYourLocationMapStatsAction> getFiresInLocation(
|
||||
{AppState state, double lat, double lon, int distance}) async {
|
||||
{AppState state, double lat, double lon, int distance}) async {
|
||||
assert(state.firesApiUrl != null);
|
||||
assert(state.firesApiKey != null);
|
||||
var url = '${state.firesApiUrl}fires-in-full/${state
|
||||
|
|
@ -139,7 +142,37 @@ class FiresApi {
|
|||
fires: fires,
|
||||
falsePos: falsePos,
|
||||
industries: industries);
|
||||
} else throw Exception('Wrong response trying to get fire data');
|
||||
} else
|
||||
throw Exception('Wrong response trying to get fire data');
|
||||
});
|
||||
}
|
||||
|
||||
Future<List<Polyline>> getMonitoredAreas({AppState state}) async {
|
||||
assert(state.firesApiUrl != null);
|
||||
assert(state.firesApiKey != null);
|
||||
var url = '${state.firesApiUrl}status/subs-public-union/${state
|
||||
.firesApiKey}';
|
||||
var color = const Color(0xFF145A32);
|
||||
return await resty.get(url).go().then((response) {
|
||||
if (response.statusCode == 200) {
|
||||
var resultDecoded = json.decode(response.body);
|
||||
// print(resultDecoded['data']['union']);
|
||||
List<Polyline> union = [];
|
||||
final multipolygon =
|
||||
json.decode(resultDecoded['data']['union']['value'])['geometry']
|
||||
['coordinates'];
|
||||
for (List<dynamic> polygon in multipolygon) {
|
||||
for (List<dynamic> hole in polygon) {
|
||||
List<LatLng> points = [];
|
||||
for (List<dynamic> point in hole) {
|
||||
points.add(new LatLng(point[1].toDouble(), point[0].toDouble()));
|
||||
}
|
||||
union.add(new Polyline(points: points, color: color, strokeWidth: 3.0));
|
||||
}
|
||||
}
|
||||
return union;
|
||||
} else
|
||||
throw Exception('Wrong response trying to get fire data');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue