From 128e9f26dc24edbd76e99cad0355f4f76288bf02 Mon Sep 17 00:00:00 2001 From: Eric Bryant Date: Mon, 16 Jul 2018 15:40:45 -0400 Subject: [PATCH 1/3] Create tmg2html.cpp https://github.com/yakra/tmtools/commit/0ae5ec459ae319f9ca91664bf53fe8f2868a9596 --- tmg2html/tmg2html.cpp | 611 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 611 insertions(+) create mode 100644 tmg2html/tmg2html.cpp diff --git a/tmg2html/tmg2html.cpp b/tmg2html/tmg2html.cpp new file mode 100644 index 00000000..94381bce --- /dev/null +++ b/tmg2html/tmg2html.cpp @@ -0,0 +1,611 @@ +#include +#include +#include +#include +#include +using namespace std; + +class vertex +{ public: + string label; + double lat, lon; + + vertex(string &ConstLine) + { char *line = new char[ConstLine.size()+1]; + strcpy(line, ConstLine.data()); + label = strtok(line, " "); + lat = stod(strtok(0, " ")); + lon = stod(strtok(0, " ")); + } +}; + +class edge +{ public: + unsigned int BegI, EndI, qty; + vertex *BegP, *EndP; + char *label; + vector shape; + + edge(string &ConstLine, vertex **vertices) + { char *line = new char[ConstLine.size()+1]; + strcpy(line, ConstLine.data()); + BegI = stoi(strtok(line, " ")); BegP = vertices[BegI]; + EndI = stoi(strtok(0, " ")); EndP = vertices[EndI]; + label = strtok(0, " "); + for (char *val = strtok(0, " "); val; val = strtok(0, " ")) + { shape.push_back(stod(val)); + } + qty = 1; + for (char *comma = strchr(label, ','); comma; qty++) comma = strchr(comma+1, ','); + } +}; + +int main(int argc, char *argv[]) +{ ifstream tmg(argv[1]); + if (argc < 3) { cout << "usage: ./tmg2html \n"; return 0; } + if (!tmg) { cout << argv[1] << " not found.\n"; return 0; } + + const char *filename = &argv[1][string(argv[1]).find_last_of("/\\")+1]; + + unsigned int NumVertices, NumEdges; + string tmgline; + getline(tmg, tmgline); + if (tmgline.substr(0, 7) != "TMG 1.0") { cout << '\"' << tmgline << "\" unsupported.\n"; return 0; } + tmg >> NumVertices; + tmg >> NumEdges; + vertex **vertices = new vertex*[NumVertices]; + edge **edges = new edge*[NumEdges]; + getline(tmg, tmgline); // seek to end of NumVertices, NumEdges line + + // read vertices + for (unsigned int i = 0; i < NumVertices; i++) + { getline(tmg, tmgline); + vertices[i] = new vertex(tmgline); + //cout << vertices[i]->label << ' ' << to_string(vertices[i]->lat) << ' ' << to_string(vertices[i]->lon) << '\n'; + } + + // read edges + for (unsigned int i = 0; i < NumEdges; i++) + { getline(tmg, tmgline); + edges[i] = new edge(tmgline, vertices); + /*cout << edges[i]->BegI << ' ' << edges[i]->EndI << ' ' << edges[i]->label; + for (unsigned int j = 0; j < edges[i]->shape.size(); j++) cout << ' ' << edges[i]->shape[j]; + cout << '\n';//*/ + } + + // HTML output + ofstream html(argv[2]); + + // html elements + html << "\n"; + html << "\n"; + html << "\n"; + html << " \n"; + html << " yakra's HDX-Lite: " << filename << "\n"; + html << " \n"; + html << "\n"; + html << "\n"; + html << "\n"; + html << "\n"; + html << "\n"; + html << "(To see Map, upgrade browser.)\n"; + html << "\n"; + html << "\n"; + html << "


\n"; + html << "
\n"; + html << "+\n"; + html << "-\n"; + html << "\n"; + html << "Reset\n"; + html << "\n"; + html << "
\n"; + html << "\n"; + html << "
\n"; + html << "\n"; + html << "\n"; + html << "\n"; + html << "
Info\n"; + html << " X
\n"; + html << "
\n"; + html << "\n"; + html << "\n"; + html << "\n"; + html << "\n"; +} From b0a8107ec11cb1b922533a3bea9929676129e5f5 Mon Sep 17 00:00:00 2001 From: Eric Bryant Date: Mon, 16 Jul 2018 15:46:51 -0400 Subject: [PATCH 2/3] Create README.md https://github.com/yakra/tmtools/commit/b7ec032e8c6d5bb98582071cd97f15baed906b70 --- tmg2html/README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tmg2html/README.md diff --git a/tmg2html/README.md b/tmg2html/README.md new file mode 100644 index 00000000..b74db274 --- /dev/null +++ b/tmg2html/README.md @@ -0,0 +1,26 @@ +# tmg2html +From yakra/tmtools/tmg2html.
+The "official" version can be found at [this link](https://github.com/yakra/tmtools/tree/master/tmg2html). +
+**Purpose:**
+Converts a .tmg [graph](http://travelmapping.net/graphs/) file into a web page with a Javascript "HDX-Lite" implementation using the HTML5 \ tag.
+This can be used to check concurrencies and NMPs, without having to deal with the slowdown Leaflet experiences with larger datasets in the full [HDX](http://courses.teresco.org/metal/hdx/) implementation. + +**Compiling:**
+C++11 support is required.
+With GCC, I use the commandline `g++ tmg2html.cpp -o tmg2html -std=c++11`
+tmg2html.cpp is all you need; no other files from the `tmtools` repository are required. + +**Commandline:**
+`tmg2html ` + +**Web page interface:** +* Pan by using the arrow keys, or double-clicking or dragging the map. +* Zoom by using the mouse wheel, or the `+` or `-` keys or buttons. +* Clicking a vertex or edge on the map will highlight it and display its info. +* Clicking a vertex or edge in the table will highlight & pan to it, and display its info. + +**Compatibility:**
+* **Firefox** is recommended. +* **Chrome & Chromium:** Rendering & redrawing the map, or getting results after clicking a vertex or edge are considerably slower, especially with larger data sets or more data on screen. +* **Other browsers** have not been tested. From 9091f50be24cee2571aeda3c1ad893d0655b49fa Mon Sep 17 00:00:00 2001 From: Eric Bryant Date: Mon, 16 Jul 2018 15:47:52 -0400 Subject: [PATCH 3/3] fix bold text --- tmg2html/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/tmg2html/README.md b/tmg2html/README.md index b74db274..98859e6a 100644 --- a/tmg2html/README.md +++ b/tmg2html/README.md @@ -2,6 +2,7 @@ From yakra/tmtools/tmg2html.
The "official" version can be found at [this link](https://github.com/yakra/tmtools/tree/master/tmg2html).
+ **Purpose:**
Converts a .tmg [graph](http://travelmapping.net/graphs/) file into a web page with a Javascript "HDX-Lite" implementation using the HTML5 \ tag.
This can be used to check concurrencies and NMPs, without having to deal with the slowdown Leaflet experiences with larger datasets in the full [HDX](http://courses.teresco.org/metal/hdx/) implementation.