[1.2.1] #6 Load the map from the Device
This commit is contained in:
parent
418a6e8aad
commit
617fbc4dea
@ -68,7 +68,6 @@
|
||||
<None Include="dpkg\preinst" />
|
||||
<None Include="dpkg\prerm" />
|
||||
<None Include="layer.json" />
|
||||
<None Include="names.json" />
|
||||
<None Include="resources\icons\marker\din1451m.woff">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
@ -89,6 +88,9 @@
|
||||
<Content Include="resources\css\icons\admin-with-cogwheels.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="resources\css\icons\failtile.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="resources\css\icons\information.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
@ -138,7 +140,9 @@
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="resources\js\leaflet\images\layers-2x.png" />
|
||||
<Content Include="resources\js\leaflet\images\layers.png" />
|
||||
<Content Include="resources\js\leaflet\images\layers.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="resources\js\leaflet\images\marker-icon-2x.png" />
|
||||
<Content Include="resources\js\leaflet\images\marker-icon.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
|
@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Fraunhofer FIT")]
|
||||
[assembly: AssemblyProduct("Lora-Map")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2018 - 15.04.2019")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2018 - 21.04.2019")]
|
||||
[assembly: AssemblyTrademark("Fraunhofer FIT, BlubbFish")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: NeutralResourcesLanguage("de-DE")]
|
||||
@ -33,8 +33,8 @@ using System.Runtime.InteropServices;
|
||||
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
|
||||
// übernehmen, indem Sie "*" eingeben:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.2.0")]
|
||||
[assembly: AssemblyFileVersion("1.2.0")]
|
||||
[assembly: AssemblyVersion("1.2.1")]
|
||||
[assembly: AssemblyFileVersion("1.2.1")]
|
||||
|
||||
/*
|
||||
* 1.1.1 Add Debian package config
|
||||
@ -45,4 +45,5 @@ using System.Runtime.InteropServices;
|
||||
* 1.1.6 #5 Create admin area
|
||||
* 1.1.7 #8 Editor for Names
|
||||
* 1.2.0 #4 Possible to Ex and Import Setting
|
||||
* 1.2.1 #6 Load the map from the Device
|
||||
*/
|
||||
|
@ -12,8 +12,7 @@ using Fraunhofer.Fit.IoT.LoraMap.Model.Admin;
|
||||
using LitJson;
|
||||
|
||||
namespace Fraunhofer.Fit.IoT.LoraMap {
|
||||
class Server : Webserver
|
||||
{
|
||||
class Server : Webserver {
|
||||
private readonly SortedDictionary<String, PositionItem> positions = new SortedDictionary<String, PositionItem>();
|
||||
private readonly SortedDictionary<String, AlarmItem> alarms = new SortedDictionary<String, AlarmItem>();
|
||||
private JsonData marker;
|
||||
@ -49,9 +48,9 @@ namespace Fraunhofer.Fit.IoT.LoraMap {
|
||||
protected override void Backend_MessageIncomming(Object sender, BackendEvent e) {
|
||||
try {
|
||||
JsonData d = JsonMapper.ToObject(e.Message);
|
||||
if (PositionItem.CheckJson(d) && ((String)e.From).Contains("lora/data")) {
|
||||
if(PositionItem.CheckJson(d) && ((String)e.From).Contains("lora/data")) {
|
||||
String name = PositionItem.GetId(d);
|
||||
if (this.positions.ContainsKey(name)) {
|
||||
if(this.positions.ContainsKey(name)) {
|
||||
this.positions[name].Update(d);
|
||||
} else {
|
||||
this.positions.Add(name, new PositionItem(d, this.marker));
|
||||
@ -66,20 +65,20 @@ namespace Fraunhofer.Fit.IoT.LoraMap {
|
||||
}
|
||||
Console.WriteLine("PANIC erhalten!");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
} catch(Exception ex) {
|
||||
Helper.WriteError(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
protected override Boolean SendWebserverResponse(HttpListenerContext cont) {
|
||||
try {
|
||||
if (cont.Request.Url.PathAndQuery.StartsWith("/loc")) {
|
||||
if(cont.Request.Url.PathAndQuery.StartsWith("/loc")) {
|
||||
return SendJsonResponse(this.positions, cont);
|
||||
} else if(cont.Request.Url.PathAndQuery.StartsWith("/panic")) {
|
||||
return SendJsonResponse(this.alarms, cont);
|
||||
} else if (cont.Request.Url.PathAndQuery.StartsWith("/icons/marker/Marker.svg") && cont.Request.Url.PathAndQuery.Contains("?")) {
|
||||
} else if(cont.Request.Url.PathAndQuery.StartsWith("/icons/marker/Marker.svg") && cont.Request.Url.PathAndQuery.Contains("?")) {
|
||||
String hash = cont.Request.Url.PathAndQuery.Substring(cont.Request.Url.PathAndQuery.IndexOf('?') + 1);
|
||||
if (!this.markertable.ContainsKey(hash)) {
|
||||
if(!this.markertable.ContainsKey(hash)) {
|
||||
this.markertable.Add(hash, new Marker(hash));
|
||||
}
|
||||
cont.Response.ContentType = "image/svg+xml";
|
||||
@ -92,13 +91,52 @@ namespace Fraunhofer.Fit.IoT.LoraMap {
|
||||
return SendJsonResponse(new Dictionary<String, DateTime>() { { "utc", DateTime.UtcNow } }, cont);
|
||||
} else if(cont.Request.Url.PathAndQuery.StartsWith("/admin")) {
|
||||
return this.admin.ParseReuqest(cont);
|
||||
} else if(cont.Request.Url.PathAndQuery.StartsWith("/getlayer")) {
|
||||
return SendJsonResponse(this.FindMapLayer(cont.Request), cont);
|
||||
} else if(cont.Request.Url.PathAndQuery.StartsWith("/maps/")) {
|
||||
return SendFileResponse(cont, "resources", false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
Helper.WriteError("500 - " + e.Message);
|
||||
cont.Response.StatusCode = 500;
|
||||
return false;
|
||||
}
|
||||
return SendFileResponse(cont);
|
||||
}
|
||||
|
||||
private Dictionary<String, Dictionary<String, Object>> FindMapLayer(HttpListenerRequest request) {
|
||||
Dictionary<String, Dictionary<String, Object>> ret = new Dictionary<String, Dictionary<String, Object>> {
|
||||
{ "online", new Dictionary<String, Object>() {
|
||||
{ "title", "Online Map" },
|
||||
{ "url", "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" },
|
||||
{ "attribution", "© <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors" },
|
||||
{ "minZoom", 1 },
|
||||
{ "maxZoom", 18 }
|
||||
} }
|
||||
};
|
||||
if(Directory.Exists("resources" + Path.DirectorySeparatorChar + "maps")) {
|
||||
String[] dirs = Directory.GetDirectories("resources" + Path.DirectorySeparatorChar + "maps");
|
||||
foreach(String dir in dirs) {
|
||||
if(File.Exists(dir + Path.DirectorySeparatorChar + "tiles.json")) {
|
||||
try {
|
||||
JsonData map = JsonMapper.ToObject(File.ReadAllText(dir + Path.DirectorySeparatorChar + "tiles.json"));
|
||||
Dictionary<String, Object> entry = new Dictionary<String, Object> {
|
||||
{ "title", (String)map["name"] },
|
||||
{ "url", (String)map["tiles"][0] },
|
||||
{ "attribution", (String)map["attribution"] },
|
||||
{ "minZoom", (Int32)map["minzoom"] },
|
||||
{ "maxZoom", (Int32)map["maxzoom"] },
|
||||
{ "bounds", new Dictionary<String, Object>() {
|
||||
{ "corner1", new Double[] { (Double)map["bounds"][0], (Double)map["bounds"][1] } },
|
||||
{ "corner2", new Double[] { (Double)map["bounds"][2], (Double)map["bounds"][3] } }
|
||||
} }
|
||||
};
|
||||
ret.Add(dir.Substring(("resources" + Path.DirectorySeparatorChar + "maps").Length+1), entry);
|
||||
} catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
BIN
Lora-Map/resources/css/icons/failtile.png
Normal file
BIN
Lora-Map/resources/css/icons/failtile.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.9 KiB |
@ -1,8 +1,53 @@
|
||||
var mymap = L.map('bigmap').setView(["{%START_LOCATION%}"], 14);
|
||||
|
||||
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
||||
}).addTo(mymap);
|
||||
GetMapLayers();
|
||||
function GetMapLayers() {
|
||||
var layergetter = new XMLHttpRequest();
|
||||
layergetter.onreadystatechange = function () {
|
||||
if (layergetter.readyState === 4 && layergetter.status === 200) {
|
||||
var maps = JSON.parse(layergetter.responseText);
|
||||
var i = 0;
|
||||
for (var key in maps) {
|
||||
i++;
|
||||
}
|
||||
if (i === 1) {
|
||||
L.tileLayer(maps["online"]["url"], {
|
||||
attribution: maps["online"]["attribution"],
|
||||
minZoom: maps["online"]["minZoom"],
|
||||
maxZoom: maps["online"]["maxZoom"]
|
||||
}).addTo(mymap);
|
||||
} else {
|
||||
var baseMaps = {};
|
||||
for (key in maps) {
|
||||
if (key !== "online") {
|
||||
var basemap = L.tileLayer(maps[key]["url"], {
|
||||
attribution: maps[key]["attribution"],
|
||||
minZoom: maps[key]["minZoom"],
|
||||
maxZoom: maps[key]["maxZoom"],
|
||||
errorTileUrl: "css/icons/failtile.png"
|
||||
});
|
||||
basemap.addTo(mymap);
|
||||
baseMaps[maps[key]["title"]] = basemap;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (key in maps) {
|
||||
if (!baseMaps.hasOwnProperty(maps[key]["title"])) {
|
||||
baseMaps[maps[key]["title"]] = L.tileLayer(maps[key]["url"], {
|
||||
attribution: maps[key]["attribution"],
|
||||
minZoom: maps[key]["minZoom"],
|
||||
maxZoom: maps[key]["maxZoom"],
|
||||
errorTileUrl: "css/icons/failtile.png"
|
||||
});
|
||||
}
|
||||
}
|
||||
L.control.layers(baseMaps).addTo(mymap);
|
||||
}
|
||||
}
|
||||
};
|
||||
layergetter.open("GET", "http://{%REQUEST_URL_HOST%}/getlayer", true);
|
||||
layergetter.send();
|
||||
}
|
||||
|
||||
mymap.on("click", hidePanel);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user