Merge pull request #118 from szpetny/draw-function-fixes

Small changed regarding drawing a footprint
This commit is contained in:
Matthieu Baumann
2023-08-31 16:55:53 +02:00
committed by GitHub
2 changed files with 21 additions and 11 deletions

View File

@@ -46,13 +46,15 @@ export let Footprint= (function() {
this.shapes = shapes;
this.isShowing = true;
this.overlay = null;
};
Footprint.prototype.setCatalog = function(catalog) {
if (this.source) {
this.source.setCatalog(catalog);
}
};
};
Footprint.prototype.show = function() {
if (this.isShowing) {
@@ -91,7 +93,7 @@ export let Footprint= (function() {
Footprint.prototype.setSelectionColor = function(color) {
this.shapes.forEach((shape) => shape.setSelectionColor(color))
};
Footprint.prototype.isFootprint = function() {
return true;
}
@@ -125,6 +127,10 @@ export let Footprint= (function() {
return this.source && this.source.catalog;
};
Footprint.prototype.setOverlay = function(overlay) {
this.overlay = overlay;
};
Footprint.prototype.intersectsBBox = function(x, y, w, h, view) {
if(this.source) {
let s = this.source;

View File

@@ -45,7 +45,7 @@ export let Polyline= (function() {
let Polyline = function(radecArray, options) {
options = options || {};
this.color = options['color'] || undefined;
this.lineWidth = options["lineWidth"] || 2;
this.lineWidth = options["lineWidth"] || undefined;
if (options["closed"]) {
this.closed = options["closed"];
@@ -138,7 +138,7 @@ export let Polyline= (function() {
this.overlay.reportChange();
}
};
Polyline.prototype.isFootprint = function() {
// The polyline is a footprint if it describes a polygon (i.e. a closed polyline)
return this.closed;
@@ -163,6 +163,10 @@ export let Polyline= (function() {
baseColor = '#ff0000';
}
if (!this.lineWidth) {
this.lineWidth = this.overlay.lineWidth || 2;
}
if (this.isSelected) {
if(this.selectionColor) {
ctx.strokeStyle = this.selectionColor;
@@ -204,11 +208,11 @@ export let Polyline= (function() {
}
let drawLine;
if (view.projection === ProjectionEnum.SIN) {
drawLine = (v0, v1) => {
const line = new Line(v0.x, v0.y, v1.x, v1.y);
if (line.isInsideView(view.width, view.height)) {
line.draw(ctx);
}
@@ -216,14 +220,14 @@ export let Polyline= (function() {
} else {
drawLine = (v0, v1) => {
const line = new Line(v0.x, v0.y, v1.x, v1.y);
if (line.isInsideView(view.width, view.height)) {
// check if the line is too big (in the clip space) to be drawn
const [x1, y1] = AladinUtils.viewXyToClipXy(line.x1, line.y1, view);
const [x2, y2] = AladinUtils.viewXyToClipXy(line.x2, line.y2, view);
const mag2 = (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2);
if (mag2 < 0.1) {
line.draw(ctx);
}
@@ -264,7 +268,7 @@ export let Polyline= (function() {
ctx.lineWidth = this.lineWidth;
ctx.beginPath();
for (var k = 0; k < nSegment; k++) {
drawLine(xyView[v0], xyView[v1])
@@ -303,7 +307,7 @@ export let Polyline= (function() {
if(this.closed) {
const line = new Line(pointXY[lastPointIdx].x, pointXY[lastPointIdx].y, pointXY[0].x, pointXY[0].y); // new segment
line.draw(ctx, true);
if (ctx.isPointInStroke(x, y)) { // x,y is on line?
return true;
}