Skip to content

Commit

Permalink
satellite view on the map. fixes #61
Browse files Browse the repository at this point in the history
  • Loading branch information
guivazcabral committed Jun 11, 2019
1 parent e30af0f commit 2f36f91
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/middleware/preferences_middleware.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Middleware<AppState> _createLoadPreferences() {

data['pref-important'] = prefs.getInt('important') ?? 0;
data['pref-warnings'] = prefs.getInt('warnings') ?? 0;
data['pref-satellite'] = prefs.getInt('satellite') ?? 0;

store.dispatch(new AllPreferencesLoadedAction(data));
store.dispatch(new SavedFireFiltersAction(saveFilters));
Expand Down
62 changes: 60 additions & 2 deletions lib/screens/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:fogosmobile/actions/fires_actions.dart';
import 'package:fogosmobile/actions/preferences_actions.dart';
import 'package:fogosmobile/localization/fogos_localizations.dart';
import 'package:fogosmobile/models/app_state.dart';
import 'package:fogosmobile/models/fire.dart';
Expand Down Expand Up @@ -136,9 +137,50 @@ class HomePage extends StatelessWidget {
}
}

Widget _getSatelliteButton(state, context) {
List<Widget> widgets = [
IconButton(
icon: Icon(Icons.satellite),
onPressed: () {
final store = StoreProvider.of<AppState>(context);
store.dispatch(SetPreferenceAction('satellite', state.preferences['pref-satellite'] == 1 ? 0 : 1));
},
),
];

if (state.preferences['pref-satellite'] == 1) {
widgets.add(
Positioned(
bottom: 5,
right: 5,
child: Icon(
Icons.check_circle,
size: 18,
color: Colors.green,
),
)
);
}

return Stack(
children: widgets,
);
}

return StoreConnector<AppState, AppState>(
converter: (Store<AppState> store) => store.state,
builder: (BuildContext context, AppState state) {
String mapboxUrlTemplate;
String mapboxId;

if (state.preferences['pref-satellite'] == 1) {
mapboxUrlTemplate = MAPBOX_URL_SATTELITE_TEMPLATE;
mapboxId = MAPBOX_SATTELITE_ID;
} else {
mapboxUrlTemplate = MAPBOX_URL_TEMPLATE;
mapboxId = MAPBOX_ID;
}

return ModalProgressHUD(
opacity: 0.75,
color: Colors.black,
Expand All @@ -155,10 +197,10 @@ class HomePage extends StatelessWidget {
),
layers: [
new TileLayerOptions(
urlTemplate: MAPBOX_URL_TEMPLATE,
urlTemplate: mapboxUrlTemplate,
additionalOptions: {
'accessToken': MAPBOX_ACCESS_TOKEN,
'id': MAPBOX_ID,
'id': mapboxId,
},
),
new MarkerLayerOptions(
Expand All @@ -167,6 +209,22 @@ class HomePage extends StatelessWidget {
],
),
MapboxCopyright(),
Positioned(
right: 0.0,
top: 0.0,
child: SafeArea(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(bottomLeft: Radius.circular(14.0)),
color: Colors.white54,
),
child: Padding(
padding: const EdgeInsets.all(4.0),
child: _getSatelliteButton(state, context),
),
),
),
)
],
),
);
Expand Down

0 comments on commit 2f36f91

Please sign in to comment.