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 {
this.drawHeightMap();
}
capture() {
/* this.addPoint(new GeoPoint(
Std.Random(136, 150),
Std.Random(60, 150),
Std.Random(80, 159)
));*/
}
/**
* @override
*/
......@@ -256,6 +248,7 @@ class HeightMapViewController extends UIViewController {
${content}
`;
}
}
HeightMapViewController.BACKGROUND = "#ccc";
HeightMapViewController.MAINLOOP = null;
......
......@@ -8,6 +8,7 @@ import Tracks from "../models/Tracks.js";
import Settings from "../Settings.js";
import $ from "../smallQ.js";
import GeoJSONCollection from "../GeoJSONCollection.js";
const States = {
TRACKLIST : 0,
......@@ -70,6 +71,9 @@ class ViewController extends UIViewController {
$("#backButton").click(element => {
this.changeState(States.TRACKLIST);
});
$("#download").click(element => {
this.download();
});
}
changeState(newState) {
......@@ -87,6 +91,8 @@ class ViewController extends UIViewController {
render() {
this.children = [];
let leftButton = "<a></a>";
let rightButton = `<a href=# id=about><span class="fa fa-info-circle"></span></a>`;
let title = "HeightTracker";
switch(this.state) {
......@@ -100,6 +106,7 @@ class ViewController extends UIViewController {
case States.HEIGHTMAP:
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>";
rightButton = "<a id=download href=#><span class='fa fa-download'></span></a>";
title = this.tracks.get(this.track).name;
break;
}
......@@ -108,7 +115,7 @@ class ViewController extends UIViewController {
<header>
${leftButton}
<h2 class=title>${title}</h2>
<a href=# id=about><span class="fa fa-info-circle"></span></a>
${rightButton}
</header>
<main class=view>
</main>
......@@ -129,6 +136,22 @@ class ViewController extends UIViewController {
</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;
\ No newline at end of file
......@@ -33,6 +33,9 @@ class HeightMap {
if (geoPoint.constructor.name !== "GeoPoint")
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;
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