Commit 265fd5f9 authored by Michael Ochmann's avatar Michael Ochmann
Browse files

added GeoJSON export

parent 32c2d6ca
class GeoJSONCollection {
constructor(track) {
console.log(track);
this.type = "FeatureCollection";
this.features = [
{
geometry : {
coordinates : track.points.map(point => [point.latitude, point.longitude, point.altitude]),
type : "LineString"
},
properties : {
name : track.name
},
type : "Feature"
}
];
}
toString() {
return JSON.stringify(this);
}
}
export default GeoJSONCollection;
\ No newline at end of file
...@@ -50,14 +50,6 @@ class HeightMapViewController extends UIViewController { ...@@ -50,14 +50,6 @@ class HeightMapViewController extends UIViewController {
this.drawHeightMap(); this.drawHeightMap();
} }
capture() {
/* this.addPoint(new GeoPoint(
Std.Random(136, 150),
Std.Random(60, 150),
Std.Random(80, 159)
));*/
}
/** /**
* @override * @override
*/ */
...@@ -256,6 +248,7 @@ class HeightMapViewController extends UIViewController { ...@@ -256,6 +248,7 @@ class HeightMapViewController extends UIViewController {
${content} ${content}
`; `;
} }
} }
HeightMapViewController.BACKGROUND = "#ccc"; HeightMapViewController.BACKGROUND = "#ccc";
HeightMapViewController.MAINLOOP = null; HeightMapViewController.MAINLOOP = null;
......
...@@ -8,6 +8,7 @@ import Tracks from "../models/Tracks.js"; ...@@ -8,6 +8,7 @@ import Tracks from "../models/Tracks.js";
import Settings from "../Settings.js"; import Settings from "../Settings.js";
import $ from "../smallQ.js"; import $ from "../smallQ.js";
import GeoJSONCollection from "../GeoJSONCollection.js";
const States = { const States = {
TRACKLIST : 0, TRACKLIST : 0,
...@@ -70,6 +71,9 @@ class ViewController extends UIViewController { ...@@ -70,6 +71,9 @@ class ViewController extends UIViewController {
$("#backButton").click(element => { $("#backButton").click(element => {
this.changeState(States.TRACKLIST); this.changeState(States.TRACKLIST);
}); });
$("#download").click(element => {
this.download();
});
} }
changeState(newState) { changeState(newState) {
...@@ -87,6 +91,8 @@ class ViewController extends UIViewController { ...@@ -87,6 +91,8 @@ class ViewController extends UIViewController {
render() { render() {
this.children = []; this.children = [];
let leftButton = "<a></a>"; let leftButton = "<a></a>";
let rightButton = `<a href=# id=about><span class="fa fa-info-circle"></span></a>`;
let title = "HeightTracker"; let title = "HeightTracker";
switch(this.state) { switch(this.state) {
...@@ -100,6 +106,7 @@ class ViewController extends UIViewController { ...@@ -100,6 +106,7 @@ class ViewController extends UIViewController {
case States.HEIGHTMAP: case States.HEIGHTMAP:
this.addSubview(new HeightMapViewController("main", new HeightMap(this, this.track))); this.addSubview(new HeightMapViewController("main", new HeightMap(this, this.track)));
leftButton = "<a id=backButton href=#><span class='fa fa-chevron-left'></span> <span>Zurück</span></a>"; leftButton = "<a id=backButton href=#><span class='fa fa-chevron-left'></span> <span>Zurück</span></a>";
rightButton = "<a id=download href=#><span class='fa fa-download'></span></a>";
title = this.tracks.get(this.track).name; title = this.tracks.get(this.track).name;
break; break;
} }
...@@ -108,7 +115,7 @@ class ViewController extends UIViewController { ...@@ -108,7 +115,7 @@ class ViewController extends UIViewController {
<header> <header>
${leftButton} ${leftButton}
<h2 class=title>${title}</h2> <h2 class=title>${title}</h2>
<a href=# id=about><span class="fa fa-info-circle"></span></a> ${rightButton}
</header> </header>
<main class=view> <main class=view>
</main> </main>
...@@ -129,6 +136,22 @@ class ViewController extends UIViewController { ...@@ -129,6 +136,22 @@ class ViewController extends UIViewController {
</section> </section>
`; `;
} }
download() {
let filename = `${this.tracks.get(this.track).name.toLowerCase().replace(new RegExp(" ", "g"), '_')}.json`;
let text = new GeoJSONCollection(this.tracks.get(this.track)).toString();
let element = document.createElement("a");
element.setAttribute("href", "data:text/plain;charset=utf-8," + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = "none";
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
} }
export default ViewController; export default ViewController;
\ No newline at end of file
...@@ -33,6 +33,9 @@ class HeightMap { ...@@ -33,6 +33,9 @@ class HeightMap {
if (geoPoint.constructor.name !== "GeoPoint") if (geoPoint.constructor.name !== "GeoPoint")
throw new TypeError("an object of type 'GeoPoint' must be p1assed."); throw new TypeError("an object of type 'GeoPoint' must be p1assed.");
if (geoPoint.altitude === null)
return;
this.min = this.min === null ? geoPoint.altitude : this.min; this.min = this.min === null ? geoPoint.altitude : this.min;
let min = this.min; let min = this.min;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment