diff --git a/native-apps/urban-heat-notifier/urban_heat_notifier/_.env b/native-apps/urban-heat-notifier/urban_heat_notifier/_.env index 3290a2b..0c85371 100644 --- a/native-apps/urban-heat-notifier/urban_heat_notifier/_.env +++ b/native-apps/urban-heat-notifier/urban_heat_notifier/_.env @@ -1 +1,14 @@ APIKEY=[your_api_key] +TITLE=Urban Heat Notifier +INITIALVIEWPOINT={"lon": 7.10, "lat": 50.71, "scale": 200000} +BASEMAP=BasemapStyle.osmStreets +HriVectorTileServiceTitle=Heat Risk Index Vector +HriVectorTileServicePortalItemID=c9e5c25aeb494c30b143dd4c2f87c3ef +HriFeatureServiceTitle=Heat Risk Index Feature +HriFeatureServicePortalItemID=5969b96bfb0340b0abe1ad78dbe8150c +DrinkingWaterFeatureServiceTitle=Drinking Water Feature +DrinkingWaterFeatureServicePortalItemID=bd918e6dd0da42ca9462cfb56214eb6a +PlacesServiceUrl=https://places-api.arcgis.com/arcgis/rest/services/places-service/v1/places/near-point +PlacesSearchRadius=500 +PlacesCategoryDiningDrinkingId=13000 +PlacesCategoryHealthMedicineId=1500 diff --git a/native-apps/urban-heat-notifier/urban_heat_notifier/lib/env/env.dart b/native-apps/urban-heat-notifier/urban_heat_notifier/lib/env/env.dart index e0e6db8..50dc37b 100644 --- a/native-apps/urban-heat-notifier/urban_heat_notifier/lib/env/env.dart +++ b/native-apps/urban-heat-notifier/urban_heat_notifier/lib/env/env.dart @@ -5,5 +5,25 @@ part 'env.g.dart'; @Envied(path: '.env') abstract class Env { @EnviedField(varName: 'APIKEY', obfuscate: true) - static final String apikey = _Env.apikey; + static String apikey = _Env.apikey; + @EnviedField(varName: 'TITLE', obfuscate: false) + static String title = _Env.title; + @EnviedField(varName: 'INITIALVIEWPOINT', obfuscate: false) + static String initialViewPont = _Env.initialViewPont; + @EnviedField(varName: 'BASEMAP', obfuscate: false) + static String basemap = _Env.basemap; + @EnviedField(varName: 'HriVectorTileServicePortalItemID', obfuscate: false) + static String hriVectorTileServicePortalItemID = _Env.hriVectorTileServicePortalItemID; + @EnviedField(varName: 'HriFeatureServicePortalItemID', obfuscate: false) + static String hriFeatureServicePortalItemID = _Env.hriFeatureServicePortalItemID; + @EnviedField(varName: 'DrinkingWaterFeatureServicePortalItemID', obfuscate: false) + static String drinkingWaterFeatureServicePortalItemID = _Env.drinkingWaterFeatureServicePortalItemID; + @EnviedField(varName: 'PlacesServiceUrl', obfuscate: false) + static String placesServiceUrl = _Env.placesServiceUrl; + @EnviedField(varName: 'PlacesSearchRadius', obfuscate: false) + static String placesSearchRadius = _Env.placesSearchRadius; + @EnviedField(varName: 'PlacesCategoryDiningDrinkingId', obfuscate: false) + static String placesCategoryDiningDrinkingId = _Env.placesCategoryDiningDrinkingId; + @EnviedField(varName: 'PlacesCategoryHealthMedicineId', obfuscate: false) + static String placesCategoryHealthMedicineId = _Env.placesCategoryHealthMedicineId; } \ No newline at end of file diff --git a/native-apps/urban-heat-notifier/urban_heat_notifier/lib/main.dart b/native-apps/urban-heat-notifier/urban_heat_notifier/lib/main.dart index e9e8aa9..0381b0a 100644 --- a/native-apps/urban-heat-notifier/urban_heat_notifier/lib/main.dart +++ b/native-apps/urban-heat-notifier/urban_heat_notifier/lib/main.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:arcgis_maps/arcgis_maps.dart'; +import 'dart:convert'; import 'env/env.dart'; void main() { @@ -24,6 +25,9 @@ class MapScreen extends StatefulWidget { class _MapScreenState extends State { bool _switchValue = false; final _mapViewController = ArcGISMapView.createController(); + late ArcGISVectorTiledLayer _hriVectorTiledLayer; + late FeatureLayer _hriFeatureLayer; + @override void initState() { @@ -33,11 +37,14 @@ class _MapScreenState extends State { @override Widget build(BuildContext context) { return Scaffold( + appBar: AppBar( + title: Text(Env.title) + ), body: Stack( children: [ ArcGISMapView( controllerProvider: () => _mapViewController, - onMapViewReady: onMapViewReady + onMapViewReady: onMapViewReady ), Positioned( bottom: 25, @@ -62,18 +69,63 @@ class _MapScreenState extends State { } void onMapViewReady() { - _mapViewController.arcGISMap = ArcGISMap.withBasemapStyle(BasemapStyle.arcGISLightGray); + + BasemapStyle basemapStyle = BasemapStyle.values.firstWhere((e) => e.toString() == Env.basemap); + var map = ArcGISMap.withBasemapStyle(basemapStyle); + + + final parsedInitialViewPoint = jsonDecode(Env.initialViewPont); + + map.initialViewpoint = Viewpoint.fromCenter( + ArcGISPoint( + x: double.parse(parsedInitialViewPoint["lon"].toString()), + y: double.parse(parsedInitialViewPoint["lat"].toString()), + spatialReference: SpatialReference.wgs84, + ), + scale: double.parse(parsedInitialViewPoint["scale"].toString()), + ); + + + var portalItem = PortalItem.withPortalAndItemId(portal: Portal.arcGISOnline(), itemId: Env.hriVectorTileServicePortalItemID); + _hriVectorTiledLayer = ArcGISVectorTiledLayer.withItem(portalItem); + map.operationalLayers.add(_hriVectorTiledLayer); + + portalItem = PortalItem.withPortalAndItemId(portal: Portal.arcGISOnline(), itemId: Env.hriFeatureServicePortalItemID); + _hriFeatureLayer = FeatureLayer.withFeatureLayerItem(portalItem); + _hriFeatureLayer.definitionExpression = "hri >= 9"; + _hriFeatureLayer.opacity = .5; + map.operationalLayers.add(_hriFeatureLayer); + + _mapViewController.arcGISMap = map; // Set the initial system location data source and auto-pan mode. _mapViewController.locationDisplay.dataSource = SystemLocationDataSource(); _mapViewController.locationDisplay.autoPanMode = LocationDisplayAutoPanMode.compassNavigation; + _mapViewController.locationDisplay.initialZoomScale = 2000; + + _mapViewController.onScaleChanged.listen((scale){ + _toggleUserLocation(); + _toggleLayerVisibility(scale); + }); } - void _toggleUserLocation() { + void _toggleUserLocation() async { if (_switchValue) { + _mapViewController.locationDisplay.autoPanMode = LocationDisplayAutoPanMode.compassNavigation; _mapViewController.locationDisplay.start(); } else { + _mapViewController.locationDisplay.autoPanMode = LocationDisplayAutoPanMode.off; _mapViewController.locationDisplay.stop(); } + } + + void _toggleLayerVisibility(double scale) async { + if (scale <= 10000) { + _hriVectorTiledLayer.isVisible = false; + _hriFeatureLayer.isVisible = true; + } else { + _hriVectorTiledLayer.isVisible = true; + _hriFeatureLayer.isVisible = false; + } } } \ No newline at end of file diff --git a/native-apps/urban-heat-notifier/urban_heat_notifier/pubspec.lock b/native-apps/urban-heat-notifier/urban_heat_notifier/pubspec.lock index 10ed8d3..b042afe 100644 --- a/native-apps/urban-heat-notifier/urban_heat_notifier/pubspec.lock +++ b/native-apps/urban-heat-notifier/urban_heat_notifier/pubspec.lock @@ -813,10 +813,10 @@ packages: dependency: transitive description: name: url_launcher_linux - sha256: e2b9622b4007f97f504cd64c0128309dfb978ae66adbe944125ed9e1750f06af + sha256: "4e9ba368772369e3e08f231d2301b4ef72b9ff87c31192ef471b380ef29a4935" url: "https://pub.dev" source: hosted - version: "3.2.0" + version: "3.2.1" url_launcher_macos: dependency: transitive description: