diff --git a/tmg2html/README.md b/tmg2html/README.md new file mode 100644 index 00000000..98859e6a --- /dev/null +++ b/tmg2html/README.md @@ -0,0 +1,27 @@ +# 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. 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"; +}