From 28bf1c585bf1eac827cbe5561054837c0981b3e8 Mon Sep 17 00:00:00 2001 From: Philip Schell Date: Thu, 22 Aug 2019 13:45:11 +0200 Subject: [PATCH] #27 Draw Camera-Desity bock on map --- CHANGELOG | 1 + Lora-Map/Model/Crowd.cs | 4 ++-- Lora-Map/Model/Settings.cs | 28 ++++++++++++++++++++++++++++ Lora-Map/Program.cs | 2 +- Lora-Map/resources/js/functions.js | 1 + Lora-Map/resources/js/map.js | 30 ++++++++++++++++++++++++++++++ 6 files changed, 63 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1811fcf..8791eca 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,7 @@ * #19 grid automatisch generieren * #24 Add information about weather/warning * #28 Fightdedection Plygon on Map +* #27 Draw Camera-Desity bock on map ### Bugfixes * Add Correct Dispose Handling * TimeCalculation now handle negative values correct diff --git a/Lora-Map/Model/Crowd.cs b/Lora-Map/Model/Crowd.cs index c66dd9c..2d22ed6 100644 --- a/Lora-Map/Model/Crowd.cs +++ b/Lora-Map/Model/Crowd.cs @@ -18,7 +18,7 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model json.ContainsKey("density_map") && json["density_map"].IsArray && json.ContainsKey("type_module") && json["type_module"].IsString && json["type_module"].ToString() == "crowd_density_local" && json.ContainsKey("density_count") && json["density_count"].IsInt && - json.ContainsKey("timestamp1") && json["timestamp1"].IsString; + json.ContainsKey("timestamp_1") && json["timestamp_1"].IsString; public static Boolean CheckJsonFlow(JsonData json) => json.ContainsKey("camera_ids") && json["camera_ids"].IsArray && json["camera_ids"].Count == 1 && json.ContainsKey("average_flow_magnitude") && json["average_flow_magnitude"].IsArray && @@ -31,7 +31,7 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model public void Update(JsonData json) { if(CheckJsonCrowdDensityLocal(json)) { this.DensityCount = (Int32)json["density_count"]; - if (DateTime.TryParse((String)json["timestamp1"], DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal, out DateTime updatetime)) { + if (DateTime.TryParse((String)json["timestamp_1"], DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal, out DateTime updatetime)) { this.TimeStamp = updatetime.ToUniversalTime(); } } else if(CheckJsonFlow(json)) { diff --git a/Lora-Map/Model/Settings.cs b/Lora-Map/Model/Settings.cs index 85c7768..ed88be4 100644 --- a/Lora-Map/Model/Settings.cs +++ b/Lora-Map/Model/Settings.cs @@ -13,6 +13,7 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model { public Double Startloclon { get; private set; } public Dictionary>>> Grid { get; private set; } public Dictionary>> FightDedection { get; private set; } + public Dictionary DensityArea { get; private set; } public Settings() => this.ParseJson(); @@ -55,6 +56,28 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model { } this.FightDedection = fight; } + if (json.ContainsKey("CrwodDensity") && json["CrwodDensity"].IsObject) { + Dictionary densitys = new Dictionary(); + foreach (KeyValuePair entry in json["CrwodDensity"]) { + Density density = new Density(); + density.Polygon = new List>(); + if (entry.Value.ContainsKey("Poly") && entry.Value["Poly"].IsArray) { + foreach (JsonData coord in entry.Value["Poly"]) { + List coords = new List(); + if (coord.ContainsKey("Lat") && coord["Lat"].IsDouble && coord.ContainsKey("Lon") && coord["Lon"].IsDouble) { + coords.Add((Double)coord["Lat"]); + coords.Add((Double)coord["Lon"]); + } + density.Polygon.Add(coords); + } + } + if(entry.Value.ContainsKey("Count") && (entry.Value["Count"].IsInt || entry.Value["Count"].IsDouble)) { + density.Maximum = (Int32)entry.Value["Count"]; + } + densitys.Add(entry.Key, density); + } + this.DensityArea = densitys; + } this.gridradius = json.ContainsKey("GridRadius") && json["GridRadius"].IsInt && this.Startloclat != 0 && this.Startloclon != 0 ? (Int32)json["GridRadius"] : 0; this.GenerateGrid(); } @@ -138,5 +161,10 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model { } public List GetWeatherCellIds() => this.weatherCellIDs; + + public struct Density { + public List> Polygon { get; set; } + public Int32 Maximum { get; set; } + } } } diff --git a/Lora-Map/Program.cs b/Lora-Map/Program.cs index c3cfb1d..80f7cb6 100644 --- a/Lora-Map/Program.cs +++ b/Lora-Map/Program.cs @@ -19,7 +19,7 @@ namespace Fraunhofer.Fit.IoT.LoraMap { } InIReader ini = InIReader.GetInstance("settings"); Dictionary backenddata = ini.GetSection("mqtt"); - backenddata.Add("topic", "lora/#;camera/#"); + backenddata.Add("topic", "lora/#;camera/#;sfn/#"); ADataBackend b = (ADataBackend)ABackend.GetInstance(backenddata, ABackend.BackendType.Data); _ = new Server(b, ini.GetSection("webserver"), InIReader.GetInstance("requests")); } diff --git a/Lora-Map/resources/js/functions.js b/Lora-Map/resources/js/functions.js index 73d4c5b..a43bc1a 100644 --- a/Lora-Map/resources/js/functions.js +++ b/Lora-Map/resources/js/functions.js @@ -30,6 +30,7 @@ OverlayObject._ParseAJAXDensity(json["crowdcount"]); MenuObject._ParseAJAXWeatherAlerts(json["weatherwarnings"]); MapObject._ParseAJAXFightDedection(json["fightdedect"]); + MapObject._ParseAJAXDensity(json["crowdcount"]); } }; get1000.open("GET", "/get1000", true); diff --git a/Lora-Map/resources/js/map.js b/Lora-Map/resources/js/map.js index d4d9da9..6b1bd89 100644 --- a/Lora-Map/resources/js/map.js +++ b/Lora-Map/resources/js/map.js @@ -1,6 +1,7 @@ var MapObject = { Map: {}, _FightDedection: {}, + _DensityAreas: {}, _SpecialMarkers: new Array(), Start: function () { this.Map = L.map('bigmap').setView([0, 0], 16); @@ -12,6 +13,7 @@ this.Map.panTo([settings.Startloclat, settings.Startloclon]); this._GenerateGrid(settings.Grid); this._GenerateFightBoxes(settings.FightDedection); + this._GenerateDensityBoxes(settings.DensityArea); }, _ParseAJAXLayers: function (maps) { var i = 0; @@ -88,6 +90,34 @@ } } }, + _GenerateDensityBoxes: function (densityareas) { + for (var cameraid in densityareas) { + this._DensityAreas[cameraid] = { 'Poly': L.polygon(densityareas[cameraid].Polygon, { color: 'hsl(120,100%,50%)', weight: 1 }).addTo(this.Map), 'Maximum': densityareas[cameraid].Maximum }; + this._DensityAreas[cameraid].Poly.bindPopup("Besuchermenge:
" + + "Besucher (0/" + this._DensityAreas[cameraid].Maximum + ") Personen
" + + ""); + } + }, + _ParseAJAXDensity: function (json) { + for (var cameraid in json) { + if (this._DensityAreas.hasOwnProperty(cameraid)) { + var crowd = json[cameraid]; + var box = this._DensityAreas[cameraid].Poly; + var max = this._DensityAreas[cameraid].Maximum; + var cur = crowd.DensityCount; + if (cur > max) { + cur = max; + } + box.setStyle({ color: this._createRGB(cur, max) }); + var p = box.getPopup().setContent("Besuchermenge:
" + + "Besucher (" + cur + "/" + max + ") Personen
" + + "").update(); + } + } + }, + _createRGB: function (current, max) { + return "hsl(" + (120 * (1 - (current / max))) + ",100%,50%)"; + }, _ParseAJAXGeo: function (geo) { if (!(Object.keys(geo).length === 0 && geo.constructor === Object)) { L.geoJSON(geo, {