Skip to content

Commit

Permalink
Added Heat Risk Layers
Browse files Browse the repository at this point in the history
  • Loading branch information
esride-ale committed Nov 14, 2024
1 parent 2ad4c40 commit d8d6222
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 6 deletions.
13 changes: 13 additions & 0 deletions native-apps/urban-heat-notifier/urban_heat_notifier/_.env
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
58 changes: 55 additions & 3 deletions native-apps/urban-heat-notifier/urban_heat_notifier/lib/main.dart
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -24,6 +25,9 @@ class MapScreen extends StatefulWidget {
class _MapScreenState extends State<MapScreen> {
bool _switchValue = false;
final _mapViewController = ArcGISMapView.createController();
late ArcGISVectorTiledLayer _hriVectorTiledLayer;
late FeatureLayer _hriFeatureLayer;


@override
void initState() {
Expand All @@ -33,11 +37,14 @@ class _MapScreenState extends State<MapScreen> {
@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,
Expand All @@ -62,18 +69,63 @@ class _MapScreenState extends State<MapScreen> {
}

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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit d8d6222

Please sign in to comment.