public static string getJson(List <Station> stations, Dictionary <ushort, MapTransportLine> transportLines) { var cto = new CityTransportObject { transportLines = transportLines }; return(cto.toJson()); }
public string getResult(CityTransportObject cto, string cityName, DateTime currentTime) { var document = new StringBuilder(getHtmlHeader(width, height, cto)); document.Append(svgPart); document.Append("</svg><div id=\"stationsContainer\">"); document.Append(htmlStationsPart); document.Append("</div>"); document.Append(getHtmlFooter(cityName, currentTime)); return(document.ToString()); }
private static string drawSVG(List <Station> stations, Dictionary <ushort, MapTransportLine> transportLines, string cityName, string cityId, DateTime currentTime, float minX, float minY, float maxX, float maxY) { float maxRadius = Math.Max(stations.Max(x => x.getAllStationOffsetPoints().Count) * 2 + 2, 10); var svg = new SVGTemplate((int)((maxY - minY + 16)), (int)((maxX - minX + 16)), maxRadius, minX - maxRadius, minY - maxRadius); var linesOrdened = transportLines.OrderBy(x => getLineUID(x.Key)).ToList(); //ordena pela quantidade de linhas passando stations = stations.OrderBy(x => x.linesPassingCount).ToList(); //calcula as posições de todas as estações no mapa foreach (KeyValuePair <ushort, MapTransportLine> line in linesOrdened) { Station station0 = line.Value[0]; Vector2 prevPos = station0.getPositionForLine(line.Key, line.Value[1].centralPos); for (int i = 1; i < line.Value.stationsCount(); i++) { prevPos = line.Value[i].getPositionForLine(line.Key, prevPos); } } //adiciona as exceções svg.addStationsToExceptionMap(stations); //pinta as linhas foreach (KeyValuePair <ushort, MapTransportLine> line in linesOrdened) { svg.addTransportLine(line.Value, line.Key); } svg.drawAllLines(); foreach (Station station in stations) { svg.addStation(station, transportLines); } string cityMapsFolder = TLMController.exportedMapsFolder + Path.DirectorySeparatorChar + $"{cityName} ({cityId})"; FileInfo fipalette = FileUtils.EnsureFolderCreation(cityMapsFolder); string filename = cityMapsFolder + Path.DirectorySeparatorChar + currentTime.ToString("yyyy-MM-dd-HH-mm-ss") + ".html"; if (File.Exists(filename)) { File.Delete(filename); } StreamWriter sr = File.CreateText(filename); var cto = new CityTransportObject { transportLines = transportLines }; sr.WriteLine(svg.getResult(cto, cityName, currentTime)); sr.Close(); return(filename); }
/// <summary> /// The header.<> /// 0 = Height /// 1 = Width /// </summary> public string getHtmlHeader(int height, int width, CityTransportObject cto) { return($@" <!DOCTYPE html><html><head> <meta charset='UTF-8'> <style>{KlyteResourceLoader.LoadResourceString("MapDrawer.lineDrawBasicCss.css") }</style> <script src=""https://code.jquery.com/jquery-3.3.1.min.js"" integrity=""sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="" crossorigin=""anonymous""></script> <script>var _infoLines = {cto.toJson()};</script> <script>{KlyteResourceLoader.LoadResourceString("MapDrawer.app.js") }</script> </head><body> <style id=""styleSelectionLineMap""></style> <svg id=""map"" height='{height}' width='{width}'> <defs> <marker orient=""auto"" markerHeight=""6"" markerWidth=""6"" refY=""2.5"" refX=""1"" viewBox=""0 0 10 5"" id=""Triangle1""><path d=""M 0 0 L 10 2.5 L 0 5 z""/></marker> <marker orient=""auto"" markerHeight=""6"" markerWidth=""6"" refY=""2.5"" refX=""1"" viewBox=""0 0 10 5"" id=""Triangle2""><path d=""M 10 0 L 0 2.5 L 10 5 z""/></marker> </defs>"); }
public static string printToJson(List <Station> stations, Dictionary <ushort, MapTransportLine> transportLines, string mapName) { CityTransportObject cto = new CityTransportObject { transportLines = transportLines }; String folder = "Transport Lines Manager"; TLMUtils.EnsureFolderCreation(folder); String filename = folder + Path.DirectorySeparatorChar + "TLM_MAP_" + mapName + ".json"; if (File.Exists(filename)) { File.Delete(filename); } var sr = File.CreateText(filename); sr.WriteLine(cto.toJson()); sr.Close(); return(filename); }