Commit 9a4de264 authored by Michael Ochmann's avatar Michael Ochmann
Browse files

fixed heightmap rendering

parent 66a150f6
......@@ -23,11 +23,6 @@ class HeightMapViewController extends UIViewController {
$("#points").html(this.model.points.length);
let min = this.min;
let max = this.max;
this.min = geoPoint.altitude < this.min ? geoPoint.altitude : this.min;
this.max = geoPoint.altitude > this.max ? geoPoint.altitude : this.max;
this.model.add(geoPoint);
......@@ -42,12 +37,17 @@ class HeightMapViewController extends UIViewController {
position.coords.altitude
));
});
/* this.addPoint(new GeoPoint(
Std.Random(60, 150),
Std.Random(60, 150),
Std.Random(60, 150)
));*/
}
viewDidLoad() {
this.canvas = $("#heightmap").get();
this.canvas.width = this.canvas.parentNode.offsetWidth - 16;
this.canvas.height = this.canvas.parentNode.offsetHeight - 16;
this.canvas.height = this.canvas.parentNode.offsetHeight - 18;
let ctx = this.canvas.getContext("2d");
......@@ -58,16 +58,18 @@ class HeightMapViewController extends UIViewController {
this.canvas.addEventListener("touchmove", event => {
if (!this.drag)
return;
this.clear();
let ctx = this.canvas.getContext("2d");
let delta = event.changedTouches[0].clientX - this.lastX;
if (this.translated + delta > 0 || (this.translated + delta) < (this.model.points.length * -20 + this.canvas.width))
return;
console.log(this.translated + delta, this.model.points.length * -20 -20 - this.canvas.width);
this.clear();
this.translated += delta;
this.lastX = event.changedTouches[0].clientX;
ctx.translate(delta, 0);
this.drawHeightMap();
});
this.canvas.addEventListener("touchend", event => {
this.translated = false;
this.drawHeightMap();
});
this.drawHeightMap();
......@@ -89,15 +91,18 @@ class HeightMapViewController extends UIViewController {
ctx.moveTo(0, height);
let x = 0;
for (let point of this.model.points) {
let ordinateVal = Std.Map(point.altitude, this.min, this.max, 0, height * 0.95);
let ordinateVal = Std.Map(point.altitude, this.model.min, this.model.max, 0, height * 0.95);
ctx.lineTo(x, height - ordinateVal);
x+=20;
}
ctx.lineTo(x - 20, height);
ctx.lineTo(0, height);
ctx.closePath();
ctx.globalAlpha = 1;
ctx.strokeStyle = "#029BE8";
ctx.stroke();
ctx.fillStyle = "#9F00B2";
ctx.globalAlpha = 0.3;
ctx.fillStyle = "#029BE8";
ctx.fill();
}
......
......@@ -51,6 +51,7 @@ class ViewController extends UIViewController {
render() {
this.children = [];
let leftButton = "<a></a>";
switch(this.state) {
case States.SETTINGS:
......@@ -58,6 +59,7 @@ class ViewController extends UIViewController {
break;
case States.TRACKLIST:
this.addSubview(new TracksListController("main", new Tracks()));
leftButton = "<a href=#>+</a>";
break;
case States.HEIGHTMAP:
this.addSubview(new HeightMapViewController("main", new HeightMap(this.track)));
......@@ -66,7 +68,7 @@ class ViewController extends UIViewController {
return `
<header>
<a href=#>Zurück</a>
${leftButton}
<h2 class=title>HeightTracker</h2>
<a href=# id=about>Info</a>
</header>
......
......@@ -15,6 +15,12 @@ class HeightMap {
add(geoPoint) {
if (geoPoint.constructor.name !== "GeoPoint")
throw new TypeError("an object of type 'GeoPoint' must be p1assed.");
let min = this.min;
let max = this.max;
this.min = geoPoint.altitude < this.min ? geoPoint.altitude : this.min;
this.max = geoPoint.altitude > this.max ? geoPoint.altitude : this.max;
this.points.push(geoPoint);
}
}
......
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