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