Skip to content

Commit

Permalink
✨ Add support for PolygonSkyRegion
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys committed May 14, 2024
1 parent c9eff43 commit 73348ad
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
3 changes: 3 additions & 0 deletions js/models/message_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export default class MessageHandler {
case "line":
overlay.add(A.line(infos.ra1, infos.dec1, infos.ra2, infos.dec2));
break;
case "polygon":
overlay.add(A.polygon(infos.vertices));
break;
}
}

Expand Down
23 changes: 18 additions & 5 deletions src/ipyaladin/aladin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@
import traitlets

try:
from regions import CircleSkyRegion, EllipseSkyRegion, LineSkyRegion
from regions import (
CircleSkyRegion,
EllipseSkyRegion,
LineSkyRegion,
PolygonSkyRegion,
)
except ImportError:
CircleSkyRegion = None
EllipseSkyRegion = None
LineSkyRegion = None
PolygonSkyRegion = None
from traitlets import (
Float,
Int,
Expand Down Expand Up @@ -345,7 +351,9 @@ def add_table(self, table: Union[QTable, Table], **table_options: any) -> None:

def add_overlay(
self,
region: Union[str, CircleSkyRegion, EllipseSkyRegion, LineSkyRegion],
region: Union[
str, CircleSkyRegion, EllipseSkyRegion, LineSkyRegion, PolygonSkyRegion
],
**overlay_options: any,
) -> None:
"""Add an overlay layer to the Aladin Lite widget.
Expand All @@ -358,9 +366,9 @@ def add_overlay(
overlay_options: keyword arguments
"""
if not isinstance(region, str) and (
CircleSkyRegion is None or EllipseSkyRegion is None or LineSkyRegion is None
):
if (
not isinstance(region, str) and CircleSkyRegion is None
): # Only need to check one of the imports
raise ValueError(
"A region can be given as an STC-S string or a regions "
"object. To read regions objects, you need to install the regions "
Expand Down Expand Up @@ -397,6 +405,11 @@ def add_overlay(
"ra2": region.end.ra.deg,
"dec2": region.end.dec.deg,
}
elif isinstance(region, PolygonSkyRegion):
region_type = "polygon"
# Create a list of 2 elements arrays
vertices = [[coord.ra.deg, coord.dec.deg] for coord in region.vertices]
infos = {"vertices": vertices}

self.send(
{
Expand Down

0 comments on commit 73348ad

Please sign in to comment.