Refactor. Fires marker calibration
This commit is contained in:
parent
574c1afc33
commit
f970c6b4fe
9 changed files with 128 additions and 51 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'mainDrawer.dart';
|
||||
import 'leafletMap.dart';
|
||||
import 'genericMap.dart';
|
||||
import 'dart:async';
|
||||
import 'package:comunes_flutter/comunes_flutter.dart';
|
||||
import 'colors.dart';
|
||||
|
|
@ -80,7 +80,7 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
|
|||
Navigator.push(
|
||||
context,
|
||||
new MaterialPageRoute(
|
||||
builder: (context) => new LeafletMap(
|
||||
builder: (context) => new GenericMap(
|
||||
title: loc.description,
|
||||
location: loc,
|
||||
)));
|
||||
|
|
|
|||
27
lib/dummyMapPlugin.dart
Normal file
27
lib/dummyMapPlugin.dart
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import 'package:flutter/src/widgets/framework.dart';
|
||||
import 'package:flutter_map/plugin_api.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class DummyMapPluginOptions extends LayerOptions {
|
||||
final String text;
|
||||
|
||||
DummyMapPluginOptions({this.text = ""});
|
||||
}
|
||||
|
||||
// https://github.com/apptreesoftware/flutter_map/blob/master/flutter_map_example/lib/pages/plugin_api.dart
|
||||
class DummyMapPlugin extends MapPlugin {
|
||||
|
||||
@override
|
||||
Widget createLayer(LayerOptions options, MapState mapState) {
|
||||
if (options is DummyMapPluginOptions) {
|
||||
return const SizedBox();
|
||||
}
|
||||
throw ("Unknown options type for DummyMapPlugin"
|
||||
"plugin: $options");
|
||||
}
|
||||
|
||||
@override
|
||||
bool supportsLayer(LayerOptions options) {
|
||||
return options is DummyMapPluginOptions;
|
||||
}
|
||||
}
|
||||
7
lib/fireMarkType.dart
Normal file
7
lib/fireMarkType.dart
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
enum FireMarkType {
|
||||
position, // user saved location
|
||||
pixel, // use for fire drawn as pixels
|
||||
fire,
|
||||
industry,
|
||||
falsePos
|
||||
}
|
||||
29
lib/fireMarker.dart
Normal file
29
lib/fireMarker.dart
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:flutter_map/plugin_api.dart';
|
||||
import 'package:latlong/latlong.dart';
|
||||
import 'fireMarkerIcon.dart';
|
||||
import 'fireMarkType.dart';
|
||||
|
||||
class FireMarker extends Marker {
|
||||
FireMarker(location, type,
|
||||
[AnchorPos anchor = AnchorPos.center, Anchor anchorOverride])
|
||||
: super(
|
||||
width: 80.0,
|
||||
height: 80.0,
|
||||
point: new LatLng(location.lat, location.lon),
|
||||
builder: (ctx) => new Container(
|
||||
child: new FireMarkerIcon(type),
|
||||
),
|
||||
anchor: anchor,
|
||||
anchorOverride: anchorOverride ?? type == FireMarkType.position
|
||||
? new Anchor(40.0, 20.0)
|
||||
: type == FireMarkType.fire
|
||||
? new Anchor(40.0, 24.0)
|
||||
: type == FireMarkType.pixel
|
||||
? null // auto calculate with height/width in Marker
|
||||
// industries, etc (below)
|
||||
// FIXME check if this is accurate
|
||||
: new Anchor(40.0, 35.0),
|
||||
);
|
||||
}
|
||||
27
lib/fireMarkerIcon.dart
Normal file
27
lib/fireMarkerIcon.dart
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'fireMarkType.dart';
|
||||
import 'colors.dart';
|
||||
|
||||
class FireMarkerIcon extends StatelessWidget {
|
||||
|
||||
final FireMarkType type;
|
||||
|
||||
FireMarkerIcon(this.type);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
switch (type) {
|
||||
case FireMarkType.position:
|
||||
return new Icon(Icons.location_on, color: fires600, size: 50.0);
|
||||
case FireMarkType.pixel:
|
||||
return new Icon(Icons.brightness_1, color: fires900, size: 3.0);
|
||||
case FireMarkType.fire:
|
||||
return new Image.asset('images/fire-marker-l.png');
|
||||
case FireMarkType.industry:
|
||||
return new Image.asset('images/industry-marker-reg.png');
|
||||
case FireMarkType.falsePos:
|
||||
default:
|
||||
return new Image.asset('images/industry-marker.png');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -11,23 +11,26 @@ import 'globals.dart' as globals;
|
|||
import 'package:http/http.dart' as http;
|
||||
import 'dart:convert' show json;
|
||||
import 'slider.dart';
|
||||
import 'customMapPlugin.dart';
|
||||
import 'fireMarker.dart';
|
||||
import 'zoomMapPlugin.dart';
|
||||
import 'dummyMapPlugin.dart';
|
||||
import 'package:just_debounce_it/just_debounce_it.dart';
|
||||
import 'fireMarkType.dart';
|
||||
|
||||
enum MarkType { position, fire, industry, falsePos }
|
||||
enum MapOperation { view }
|
||||
|
||||
class LeafletMap extends StatefulWidget {
|
||||
class GenericMap extends StatefulWidget {
|
||||
final BasicLocation location;
|
||||
final String title;
|
||||
|
||||
LeafletMap({@required this.title, @required this.location});
|
||||
GenericMap({@required this.title, @required this.location});
|
||||
|
||||
@override
|
||||
_LeafletMapState createState() =>
|
||||
_LeafletMapState(title: title, location: location);
|
||||
_GenericMapState createState() =>
|
||||
_GenericMapState(title: title, location: location);
|
||||
}
|
||||
|
||||
class _LeafletMapState extends State<LeafletMap> {
|
||||
class _GenericMapState extends State<GenericMap> {
|
||||
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
|
||||
|
||||
final BasicLocation location;
|
||||
|
|
@ -50,7 +53,7 @@ class _LeafletMapState extends State<LeafletMap> {
|
|||
http.read(url).then((result) {
|
||||
setState(() {
|
||||
var resultDecoded = json.decode(result);
|
||||
print(resultDecoded);
|
||||
// print(resultDecoded);
|
||||
numFires = resultDecoded['real'];
|
||||
fires = resultDecoded['fires'];
|
||||
falsePos = resultDecoded['falsePos'];
|
||||
|
|
@ -60,19 +63,21 @@ class _LeafletMapState extends State<LeafletMap> {
|
|||
var industriesCount = industries.length;
|
||||
var falsePosCount = falsePos.length;
|
||||
|
||||
print(
|
||||
'fire: $firesCount falsePos: $falsePosCount industries: $industriesCount');
|
||||
/* print(
|
||||
'fire: $firesCount falsePos: $falsePosCount industries: $industriesCount'); */
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
_LeafletMapState({@required this.title, @required this.location});
|
||||
_GenericMapState({@required this.title, @required this.location});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
MapOptions mapOptions = new MapOptions(
|
||||
center: new LatLng(this.location.lat, this.location.lon),
|
||||
plugins: [new ZoomMapPlugin()],
|
||||
plugins: globals.isDevelopment
|
||||
? [new ZoomMapPlugin()]
|
||||
: [new DummyMapPlugin()],
|
||||
// this works ?
|
||||
// interactive: false,
|
||||
zoom: 13.0,
|
||||
|
|
@ -99,7 +104,9 @@ class _LeafletMapState extends State<LeafletMap> {
|
|||
'© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
|
||||
},
|
||||
),
|
||||
new ZoomMapPluginOptions(),
|
||||
globals.isDevelopment
|
||||
? new ZoomMapPluginOptions()
|
||||
: new DummyMapPluginOptions(),
|
||||
new MarkerLayerOptions(
|
||||
markers: buildMarkers(
|
||||
this.location, this.fires, this.industries, this.falsePos),
|
||||
|
|
@ -170,47 +177,27 @@ class _LeafletMapState extends State<LeafletMap> {
|
|||
List<Marker> buildMarkers(BasicLocation yourLocation, List<dynamic> fires,
|
||||
List<dynamic> falsePos, List<dynamic> industries) {
|
||||
List<Marker> markers = [];
|
||||
markers.add(buildMarker(yourLocation, MarkType.position));
|
||||
const calibrate = false; // useful when we change the fire icons size
|
||||
markers.add(FireMarker(yourLocation, FireMarkType.position));
|
||||
if (calibrate) markers.add(FireMarker(yourLocation, FireMarkType.pixel));
|
||||
falsePos.forEach((fire) {
|
||||
var coords = fire['geo']['coordinates'];
|
||||
var loc = BasicLocation(lon: coords[0], lat: coords[1]);
|
||||
markers.add(buildMarker(loc, MarkType.falsePos));
|
||||
markers.add(FireMarker(loc, FireMarkType.falsePos));
|
||||
if (calibrate) markers.add(FireMarker(loc, FireMarkType.pixel));
|
||||
});
|
||||
industries.forEach((fire) {
|
||||
// print(fire['geo']['coordinates']);
|
||||
var coords = fire['geo']['coordinates'];
|
||||
var loc = BasicLocation(lon: coords[0], lat: coords[1]);
|
||||
markers.add(buildMarker(loc, MarkType.industry));
|
||||
markers.add(FireMarker(loc, FireMarkType.industry));
|
||||
if (calibrate) markers.add(FireMarker(loc, FireMarkType.pixel));
|
||||
});
|
||||
fires.forEach((fire) {
|
||||
var loc = new BasicLocation(lat: fire['lat'], lon: fire['lon']);
|
||||
markers.add(buildMarker(loc, MarkType.fire));
|
||||
markers.add(FireMarker(loc, FireMarkType.fire));
|
||||
markers.add(FireMarker(loc, FireMarkType.pixel));
|
||||
});
|
||||
return markers;
|
||||
}
|
||||
|
||||
Marker buildMarker(location, MarkType type) {
|
||||
return new Marker(
|
||||
width: 80.0,
|
||||
height: 80.0,
|
||||
point: new LatLng(location.lat, location.lon),
|
||||
builder: (ctx) => new Container(
|
||||
child: buildImageMark(type),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildImageMark(MarkType type) {
|
||||
switch (type) {
|
||||
case MarkType.position:
|
||||
return new Icon(Icons.location_on, color: fires600, size: 50.0);
|
||||
case MarkType.fire:
|
||||
return new Image.asset('images/fire-marker-l.png');
|
||||
case MarkType.industry:
|
||||
return new Image.asset('images/industry-marker-reg.png');
|
||||
case MarkType.falsePos:
|
||||
default:
|
||||
return new Image.asset('images/industry-marker.png');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,11 +8,12 @@ import 'package:flutter/material.dart';
|
|||
String gmapKey;
|
||||
String firesApiKey;
|
||||
String firesApiUrl;
|
||||
String appName = 'All Against The Fire!';
|
||||
String appVersion = '0.0.1';
|
||||
String appLicense = "(c) 2017-2018 Comunes Association under the GNU Affero GPL v3";
|
||||
Widget appMediumIcon = Image.asset('images/logo-200.png', width: 60.0, height: 60.0);
|
||||
Widget appIcon = Image.asset('images/logo-200.png', width: 24.0, height: 24.0);
|
||||
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
|
||||
final String appName = 'All Against The Fire!';
|
||||
final String appVersion = '0.0.1';
|
||||
final String appLicense = "(c) 2017-2018 Comunes Association under the GNU Affero GPL v3";
|
||||
final Widget appMediumIcon = Image.asset('images/logo-200.png', width: 60.0, height: 60.0);
|
||||
final Widget appIcon = Image.asset('images/logo-200.png', width: 24.0, height: 24.0);
|
||||
final Future<SharedPreferences> prefs = SharedPreferences.getInstance();
|
||||
final List<BasicLocation> yourLocations = [];
|
||||
final GetIt getIt = new GetIt();
|
||||
final bool isDevelopment = true;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
|
|||
|
||||
import 'colors.dart';
|
||||
import 'sandbox.dart';
|
||||
import 'introPage.dart';
|
||||
import 'activeFires.dart';
|
||||
import 'globals.dart' as globals;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue