From 98b0d0dff6c39e94688417343c2b2abf91c3ae00 Mon Sep 17 00:00:00 2001 From: szpetny Date: Tue, 22 Aug 2023 16:29:06 +0200 Subject: [PATCH] setOverlay added to Footprint bc draw function fails when it is lacking, improvement - reading lineWidth from overlay if not specified in shape --- src/js/Footprint.js | 10 ++++++++-- src/js/Polyline.js | 22 +++++++++++++--------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/js/Footprint.js b/src/js/Footprint.js index fc018600..b9b61918 100644 --- a/src/js/Footprint.js +++ b/src/js/Footprint.js @@ -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; diff --git a/src/js/Polyline.js b/src/js/Polyline.js index 0abf7469..ccafa2ac 100644 --- a/src/js/Polyline.js +++ b/src/js/Polyline.js @@ -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; }