Added initial support for circular annotations
This commit is contained in:
Родитель
68cdfdd97f
Коммит
e9d39cc2b1
|
@ -0,0 +1,54 @@
|
|||
import uuid
|
||||
from traitlets import Bool, Unicode, Float, HasTraits
|
||||
|
||||
# The WWT web control API is described here:
|
||||
# https://worldwidetelescope.gitbooks.io/worldwide-telescope-web-control-script-reference/content/
|
||||
|
||||
|
||||
class Annotation(HasTraits):
|
||||
|
||||
shape = None
|
||||
|
||||
label = Unicode(help='Contains descriptive text '
|
||||
'for the annotation').tag(wwt='label')
|
||||
|
||||
opacity = Float(help='Specifies the opacity to be applied to the '
|
||||
'complete annotation').tag(wwt='opacity')
|
||||
|
||||
hover_label = Bool(help='Specifies whether to render the label '
|
||||
'if the mouse is hovering over the '
|
||||
'annotation').tag(wwt='showHoverLabel')
|
||||
|
||||
tag = Unicode(help='Contains a string for use by '
|
||||
'the web client').tag(wwt='tag')
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super(Annotation, self).__init__()
|
||||
self.parent = parent
|
||||
self.observe(self._on_trait_change, type='change')
|
||||
self.id = str(uuid.uuid4())
|
||||
self.parent._send_msg(event='annotation_create', id=self.id, shape=self.shape)
|
||||
|
||||
def _on_trait_change(self, changed):
|
||||
# This method gets called anytime a trait gets changed. Since this class
|
||||
# gets inherited by the Jupyter widgets class which adds some traits of
|
||||
# its own, we only want to react to changes in traits that have the wwt
|
||||
# metadata attribute (which indicates the name of the corresponding WWT
|
||||
# setting).
|
||||
wwt_name = self.trait_metadata(changed['name'], 'wwt')
|
||||
if wwt_name is not None:
|
||||
self.parent._send_msg(event='annotation_set',
|
||||
id=self.id,
|
||||
setting=wwt_name,
|
||||
value=changed['new'])
|
||||
|
||||
|
||||
class Circle(Annotation):
|
||||
|
||||
shape = 'circle'
|
||||
|
||||
def set_center(self, coord):
|
||||
coord_icrs = coord.icrs
|
||||
self.parent._send_msg(event='circle_set_center', id=self.id,
|
||||
ra=coord_icrs.ra.degree,
|
||||
dec=coord_icrs.dec.degree)
|
|
@ -1,4 +1,10 @@
|
|||
from traitlets import Bool, HasTraits
|
||||
from astropy import units as u
|
||||
|
||||
from .annotation import Circle
|
||||
|
||||
# The WWT web control API is described here:
|
||||
# https://worldwidetelescope.gitbooks.io/worldwide-telescope-web-control-script-reference/content/
|
||||
|
||||
|
||||
class BaseWWTWidget(HasTraits):
|
||||
|
@ -29,7 +35,16 @@ class BaseWWTWidget(HasTraits):
|
|||
|
||||
# TODO: need to add more methods here.
|
||||
|
||||
def center_on_coordinates(self, ra, dec, fov, instant=True):
|
||||
# TODO: make this method take SkyCoord objects
|
||||
def center_on_coordinates(self, coord, fov, instant=True):
|
||||
coord_icrs = coord.icrs
|
||||
self._send_msg(event='center_on_coordinates',
|
||||
ra=ra, dec=dec, fov=fov, instant=instant)
|
||||
ra=coord_icrs.ra.deg,
|
||||
dec=coord_icrs.dec.deg,
|
||||
fov=fov.to(u.deg).value,
|
||||
instant=instant)
|
||||
|
||||
# TODO: need to implement more annotation types
|
||||
|
||||
def create_circle(self):
|
||||
# TODO: could buffer JS call here
|
||||
return Circle(self)
|
||||
|
|
|
@ -5,6 +5,10 @@
|
|||
|
||||
function wwt_apply_json_message(wwt, msg) {
|
||||
|
||||
if (!wwt.hasOwnProperty('annotations')) {
|
||||
wwt.annotations = {};
|
||||
}
|
||||
|
||||
switch(msg['event']) {
|
||||
|
||||
case 'center_on_coordinates':
|
||||
|
@ -16,6 +20,34 @@ function wwt_apply_json_message(wwt, msg) {
|
|||
wwt.settings["set_" + name](msg['value']);
|
||||
break;
|
||||
|
||||
case 'annotation_create':
|
||||
|
||||
switch(msg['shape']) {
|
||||
case 'circle':
|
||||
// TODO: check if ID already exists
|
||||
circle = wwt.createCircle();
|
||||
circle.set_id(msg['id']);
|
||||
wwt.addAnnotation(circle);
|
||||
wwt.annotations[msg['id']] = circle;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'annotation_set':
|
||||
|
||||
var name = msg['setting'];
|
||||
// TODO: nice error message if annotation doesn't exist
|
||||
annotation = wwt.annotations[msg['id']];
|
||||
annotation["set_" + name](msg['value']);
|
||||
break;
|
||||
|
||||
case 'circle_set_center':
|
||||
|
||||
var name = msg["setting"];
|
||||
// TODO: nice error message if annotation doesn't exist
|
||||
circle = wwt.annotations[msg['id']];
|
||||
circle.setCenter(msg['ra'], msg['dec']);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче