Skip to content

Commit

Permalink
Merge pull request #118 from szpetny/draw-function-fixes
Browse files Browse the repository at this point in the history
Small changed regarding drawing a footprint
  • Loading branch information
bmatthieu3 authored Aug 31, 2023
2 parents d6e753e + 98b0d0d commit 3bda0fc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
10 changes: 8 additions & 2 deletions src/js/Footprint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 13 additions & 9 deletions src/js/Polyline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -204,26 +208,26 @@ 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);
}
};
} 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);
}
Expand Down Expand Up @@ -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])

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 3bda0fc

Please sign in to comment.