344 |
|
|
345 |
class RasterLayer(BaseLayer): |
class RasterLayer(BaseLayer): |
346 |
|
|
347 |
|
MASK_NONE = 0 |
348 |
|
MASK_BIT = 1 |
349 |
|
MASK_ALPHA = 2 |
350 |
|
|
351 |
def __init__(self, title, filename, projection = None, visible = True): |
def __init__(self, title, filename, projection = None, visible = True): |
352 |
"""Initialize the Raster Layer. |
"""Initialize the Raster Layer. |
353 |
|
|
371 |
|
|
372 |
self.bbox = -1 |
self.bbox = -1 |
373 |
|
|
374 |
self.use_mask = True |
self.mask_type = self.MASK_BIT |
375 |
|
self.opacity = 1 |
376 |
|
|
377 |
self.image_info = None |
self.image_info = None |
378 |
|
|
463 |
def GetImageFilename(self): |
def GetImageFilename(self): |
464 |
return self.filename |
return self.filename |
465 |
|
|
466 |
def UseMask(self): |
def MaskType(self): |
467 |
"""Return True if the mask should be used when rendering the layer.""" |
"""Return True if the mask should be used when rendering the layer.""" |
468 |
return self.use_mask |
return self.mask_type |
469 |
|
|
470 |
|
def SetMaskType(self, type): |
471 |
|
"""Set the type of mask to use. |
472 |
|
|
473 |
def SetUseMask(self, use): |
type can be one of MASK_NONE, MASK_BIT, MASK_ALPHA |
|
"""Set whether to use a mask when render the image. |
|
474 |
|
|
475 |
If the state changes, a LAYER_CHANGED message is sent. |
If the state changes, a LAYER_CHANGED message is sent. |
476 |
""" |
""" |
477 |
if use != self.use_mask: |
if type not in (self.MASK_NONE, self.MASK_BIT, self.MASK_ALPHA): |
478 |
self.use_mask = use |
raise ValueError("type is invalid") |
479 |
|
|
480 |
|
if type != self.mask_type: |
481 |
|
self.mask_type = type |
482 |
|
self.changed(LAYER_CHANGED, self) |
483 |
|
|
484 |
|
def Opacity(self): |
485 |
|
"""Return the level of opacity used in alpha blending. |
486 |
|
""" |
487 |
|
return self.opacity |
488 |
|
|
489 |
|
def SetOpacity(self, op): |
490 |
|
"""Set the level of alpha opacity. |
491 |
|
|
492 |
|
0 <= op <= 1. |
493 |
|
|
494 |
|
The layer is fully opaque when op = 1. |
495 |
|
""" |
496 |
|
if not (0 <= op <= 1): |
497 |
|
raise ValueError("op out of range") |
498 |
|
|
499 |
|
if op != self.opacity: |
500 |
|
self.opacity = op |
501 |
self.changed(LAYER_CHANGED, self) |
self.changed(LAYER_CHANGED, self) |
502 |
|
|
503 |
def ImageInfo(self): |
def ImageInfo(self): |