#27 Draw Camera-Desity bock on map

This commit is contained in:
Philip Schell 2019-08-22 13:45:11 +02:00
parent 438584f4b9
commit 28bf1c585b
6 changed files with 63 additions and 3 deletions

View File

@ -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

View File

@ -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)) {

View File

@ -13,6 +13,7 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model {
public Double Startloclon { get; private set; }
public Dictionary<String, List<Dictionary<String, List<Double>>>> Grid { get; private set; }
public Dictionary<String, List<List<Double>>> FightDedection { get; private set; }
public Dictionary<String, Density> 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<String, Density> densitys = new Dictionary<String, Density>();
foreach (KeyValuePair<String, JsonData> entry in json["CrwodDensity"]) {
Density density = new Density();
density.Polygon = new List<List<Double>>();
if (entry.Value.ContainsKey("Poly") && entry.Value["Poly"].IsArray) {
foreach (JsonData coord in entry.Value["Poly"]) {
List<Double> coords = new List<Double>();
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<Int32> GetWeatherCellIds() => this.weatherCellIDs;
public struct Density {
public List<List<Double>> Polygon { get; set; }
public Int32 Maximum { get; set; }
}
}
}

View File

@ -19,7 +19,7 @@ namespace Fraunhofer.Fit.IoT.LoraMap {
}
InIReader ini = InIReader.GetInstance("settings");
Dictionary<String, String> 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"));
}

View File

@ -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);

View File

@ -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("<strong>Besuchermenge:</strong><br>" +
"Besucher <strong>(0/" + this._DensityAreas[cameraid].Maximum + ")</strong> Personen<br>" +
"<progress value='0' max='" + this._DensityAreas[cameraid].Maximum + "'></progress>");
}
},
_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("<strong>Besuchermenge:</strong><br>" +
"Besucher <strong>(" + cur + "/" + max + ")</strong> Personen<br>" +
"<progress value='" + cur + "' max='" + max + "'></progress>").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, {