From b1832da477229bc122779c5c816174b0e5633697 Mon Sep 17 00:00:00 2001 From: BlubbFish Date: Tue, 30 Jul 2019 21:17:56 +0200 Subject: [PATCH] #19 grid automatisch generieren --- Lora-Map/Model/Settings.cs | 12 ++++++------ Lora-Map/resources/admin/js/menu.js | 9 +++++++++ Lora-Map/resources/js/functions.js | 1 + Lora-Map/resources/js/map.js | 16 +++++++++++++++- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Lora-Map/Model/Settings.cs b/Lora-Map/Model/Settings.cs index 742527b..5f62294 100644 --- a/Lora-Map/Model/Settings.cs +++ b/Lora-Map/Model/Settings.cs @@ -46,15 +46,15 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model { } MilitaryGridReferenceSystem start = new Coordinate(this.Startloclat, this.Startloclon).MGRS; - Double left = start.Easting - this.gridradius - ((start.Easting - this.gridradius) % 100); - Double bottom = start.Northing - this.gridradius - ((start.Northing - this.gridradius) % 100); - Double right = start.Easting + this.gridradius + (100 - ((start.Easting + this.gridradius) % 100)); - Double top = start.Northing + this.gridradius + (100 - ((start.Northing + this.gridradius) % 100)); + Double left = start.Easting - this.gridradius - (start.Easting - this.gridradius) % 100; + Double bottom = start.Northing - this.gridradius - (start.Northing - this.gridradius) % 100; + Double right = start.Easting + this.gridradius + (100 - (start.Easting + this.gridradius) % 100); + Double top = start.Northing + this.gridradius + (100 - (start.Northing + this.gridradius) % 100); this.Grid = new Dictionary>>> { { "Major", new List>>() }, { "Minor", new List>>() } }; - for (Double i = left; i <= right; i = i + 50) { + for (Double i = left; i <= right; i += 50) { Coordinate TopLeft = MilitaryGridReferenceSystem.MGRStoLatLong(new MilitaryGridReferenceSystem(start.LatZone, start.LongZone, start.Digraph, i, top)); Coordinate BottomLeft = MilitaryGridReferenceSystem.MGRStoLatLong(new MilitaryGridReferenceSystem(start.LatZone, start.LongZone, start.Digraph, i, bottom)); if(i%100 == 0) { @@ -85,7 +85,7 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model { }); } } - for (Double i = bottom; i <= top; i = i + 50) { + for (Double i = bottom; i <= top; i += 50) { Coordinate BottomLeft = MilitaryGridReferenceSystem.MGRStoLatLong(new MilitaryGridReferenceSystem(start.LatZone, start.LongZone, start.Digraph, left, i)); Coordinate BottomRight = MilitaryGridReferenceSystem.MGRStoLatLong(new MilitaryGridReferenceSystem(start.LatZone, start.LongZone, start.Digraph, right, i)); if (i % 100 == 0) { diff --git a/Lora-Map/resources/admin/js/menu.js b/Lora-Map/resources/admin/js/menu.js index 9004aab..da4c78c 100644 --- a/Lora-Map/resources/admin/js/menu.js +++ b/Lora-Map/resources/admin/js/menu.js @@ -342,6 +342,15 @@ var NamesEditor = { var Settings = { ParseJson: function (jsonsettings) { + if (typeof jsonsettings.StartPos === "undefined") { + jsonsettings.StartPos = { lat: 0, lon: 0 }; + } + if (typeof jsonsettings.CellIds === "undefined") { + jsonsettings.CellIds = []; + } + if (typeof jsonsettings.GridRadius === "undefined") { + jsonsettings.GridRadius = 1000; + } var html = "
Einstellungen
"; html += "
Startpunkt: Lat, Lon
"; html += "
CellId's für DWD-Wetterwarnungen: (Trennen durch \";\", cap_warncellids_csv)
"; diff --git a/Lora-Map/resources/js/functions.js b/Lora-Map/resources/js/functions.js index 33efadc..9d21f87 100644 --- a/Lora-Map/resources/js/functions.js +++ b/Lora-Map/resources/js/functions.js @@ -40,6 +40,7 @@ var json = JSON.parse(getonce.responseText); MapObject._ParseAJAXLayers(json["getlayer"]); MapObject._ParseAJAXGeo(json["getgeo"]); + MapObject._ParseAJAXSettings(json["startup"]); } }; getonce.open("GET", "/getonce", true); diff --git a/Lora-Map/resources/js/map.js b/Lora-Map/resources/js/map.js index 6b4ea38..1e73f06 100644 --- a/Lora-Map/resources/js/map.js +++ b/Lora-Map/resources/js/map.js @@ -2,11 +2,15 @@ Map: {}, _SpecialMarkers: new Array(), Start: function () { - this.Map = L.map('bigmap').setView(["{%START_LOCATION%}"], 16); + this.Map = L.map('bigmap').setView([0, 0], 16); this._SetupMapZoomFontsize(); this._SetupClickHandler(); return this; }, + _ParseAJAXSettings: function (settings) { + this.Map.panTo([settings.Startloclat, settings.Startloclon]); + this._GenerateGrid(settings.Grid); + }, _ParseAJAXLayers: function (maps) { var i = 0; for (var key in maps) { @@ -46,6 +50,16 @@ L.control.layers(baseMaps).addTo(this.Map); } }, + _GenerateGrid: function (grid) { + for (var i = 0; i < grid.Major.length; i++) { + var linemajor = grid.Major[i]; + L.polyline([[linemajor.from[0], linemajor.from[1]], [linemajor.to[0], linemajor.to[1]]], { color: "red", weight: 1 }).addTo(this.Map); + } + for (var j = 0; j < grid.Minor.length; j++) { + var lineminor = grid.Minor[j]; + L.polyline([[lineminor.from[0], lineminor.from[1]], [lineminor.to[0], lineminor.to[1]]], { color: "red", weight: 0.7, opacity: 0.5 }).addTo(this.Map); + } + }, _ParseAJAXGeo: function (geo) { if (!(Object.keys(geo).length === 0 && geo.constructor === Object)) { L.geoJSON(geo, {