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.alpha_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) |
self.changed(LAYER_CHANGED, self) |
483 |
|
|
484 |
|
def AlphaOpacity(self): |
485 |
|
"""Return the level of opacity used in alpha blending, or None |
486 |
|
if mask type is not MASK_ALPHA. |
487 |
|
""" |
488 |
|
if self.mask_type == self.MASK_ALPHA: |
489 |
|
return self.alpha_opacity |
490 |
|
else: |
491 |
|
return None |
492 |
|
|
493 |
|
def SetAlphaOpacity(self, op): |
494 |
|
"""Set the level of alpha opacity. |
495 |
|
|
496 |
|
0 <= op <= 1. |
497 |
|
|
498 |
|
The layer is fully opaque when op = 1. |
499 |
|
""" |
500 |
|
if not (0 <= op <= 1): |
501 |
|
raise ValueError("op out of range") |
502 |
|
|
503 |
|
self.alpha_opacity = op |
504 |
|
|
505 |
def ImageInfo(self): |
def ImageInfo(self): |
506 |
return self.image_info |
return self.image_info |
507 |
|
|