Compare commits

...

5 Commits

Author SHA1 Message Date
Thomas Boch
64fcc777de Update release notes 2020-08-24 11:58:58 +02:00
Thomas Boch
0f74b5e94f Merge pull request #22 from imbasimba/polyline
Polyline improvements
2020-08-24 11:55:41 +02:00
Thomas Boch
5799482dde Merge branch 'master' into polyline 2020-08-24 11:53:56 +02:00
Henrik Norman
416c20cecc Fixed Polyline flickering & added possibility to set line width and color 2019-12-06 13:54:02 +01:00
Henrik Norman
09ef8418bb Fixed error when mouse x position is 0 2019-12-05 09:51:58 +01:00
3 changed files with 57 additions and 19 deletions

View File

@@ -1,3 +1,6 @@
2020-08
- polyline improvements (by @imbasimba)
2020-07
- new method stopAnimation

View File

@@ -37,7 +37,8 @@ Polyline= (function() {
// constructor
Polyline = function(radecArray, options) {
options = options || {};
this.color = options['color'] || undefined;
this.color = options['color'] || "white";
this.lineWidth = options["lineWidth"] || 2;
this.radecArray = radecArray;
this.overlay = null;
@@ -89,6 +90,22 @@ Polyline= (function() {
this.overlay.reportChange();
}
};
Polyline.prototype.setLineWidth = function(lineWidth) {
if (this.lineWidth == lineWidth) {
return;
}
this.lineWidth = lineWidth;
this.overlay.reportChange();
};
Polyline.prototype.setColor = function(color) {
if (this.color == color) {
return;
}
this.color = color;
this.overlay.reportChange();
};
Polyline.prototype.draw = function(ctx, projection, frame, width, height, largestDim, zoomFactor) {
if (! this.isShowing) {
@@ -103,22 +120,44 @@ Polyline= (function() {
ctx.strokeStyle= this.color;
}
var start = AladinUtils.radecToViewXy(this.radecArray[0][0], this.radecArray[0][1], projection, frame, width, height, largestDim, zoomFactor);
if (! start) {
return;
}
ctx.beginPath();
ctx.moveTo(start.vx, start.vy);
var pt;
for (var k=1; k<this.radecArray.length; k++) {
pt = AladinUtils.radecToViewXy(this.radecArray[k][0], this.radecArray[k][1], projection, frame, width, height, largestDim, zoomFactor);
if (!pt) {
for (var k = 0; k < this.radecArray.length; k++) {
start = AladinUtils.radecToViewXy(this.radecArray[k][0], this.radecArray[k][1], projection, frame, width, height, largestDim, zoomFactor);
if (start) {
break;
}
ctx.lineTo(pt.vx, pt.vy);
}
if (!start) {
return;
}
ctx.moveTo(start.vx, start.vy);
var pt;
var newSeg = false;
var drawingNewSeg = true;
for (var k = 1; k < this.radecArray.length; k++) {
pt = AladinUtils.radecToViewXy(this.radecArray[k][0], this.radecArray[k][1], projection, frame, width, height, largestDim, zoomFactor);
if (!pt) {
if (drawingNewSeg) {
//console.log("closing segment");
ctx.stroke();
}
drawingNewSeg = false;
newSeg = true;
} else {
if (newSeg) {
//console.log ("starting newSeg at "+pt.vx+" "+pt.vy);
drawingNewSeg = true;
ctx.beginPath();
ctx.lineWidth = this.lineWidth;
ctx.moveTo(pt.vx, pt.vy);
newSeg = false;
} else {
ctx.lineTo(pt.vx, pt.vy);
}
}
}
ctx.stroke();
};

View File

@@ -71,11 +71,7 @@ function relMouseCoords(event) {
var clientX = e.clientX;
var clientY = e.clientY;
if (e.clientX) {
clientX = e.clientX;
clientY = e.clientY;
}
else {
if (e.clientX == undefined) {
clientX = e.originalEvent.changedTouches[0].clientX;
clientY = e.originalEvent.changedTouches[0].clientY;
}