7 |
|
|
8 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
9 |
|
|
10 |
from messages import LAYERS_CHANGED, MAP_PROJECTION_CHANGED, \ |
#from messages import MAP_LAYERS_CHANGED, MAP_PROJECTION_CHANGED, \ |
11 |
CHANGED, LAYER_PROJECTION_CHANGED, LAYER_LEGEND_CHANGED, \ |
#CHANGED, LAYER_PROJECTION_CHANGED, LAYER_LEGEND_CHANGED, \ |
12 |
LAYER_VISIBILITY_CHANGED |
#LAYER_VISIBILITY_CHANGED |
13 |
|
|
14 |
|
from messages import * |
15 |
|
|
16 |
|
from Thuban import _ |
17 |
|
|
18 |
from base import TitledObject, Modifiable |
from base import TitledObject, Modifiable |
19 |
|
|
29 |
|
|
30 |
TITLE_CHANGED -- The title has changed. Parameter: the map. |
TITLE_CHANGED -- The title has changed. Parameter: the map. |
31 |
|
|
32 |
LAYERS_CHANGED -- Layers were added, removed or rearranged. |
MAP_LAYERS_CHANGED -- Layers were added, removed or rearranged. |
33 |
Parameters: the map |
Parameters: the map |
34 |
|
|
35 |
MAP_PROJECTION_CHANGED -- the map's projection has changed. |
MAP_PROJECTION_CHANGED -- the map's projection has changed. |
36 |
Parameter: the map |
Parameter: the map |
37 |
""" |
""" |
38 |
|
|
39 |
forwarded_channels = (LAYER_PROJECTION_CHANGED, |
forwarded_channels = (CHANGED, |
40 |
|
LAYER_PROJECTION_CHANGED, |
41 |
LAYER_LEGEND_CHANGED, |
LAYER_LEGEND_CHANGED, |
42 |
|
LAYER_CHANGED, |
43 |
LAYER_VISIBILITY_CHANGED) |
LAYER_VISIBILITY_CHANGED) |
44 |
|
|
45 |
def __init__(self, title, projection = None): |
def __init__(self, title, projection = None): |
46 |
"""Initialize the map.""" |
"""Initialize the map.""" |
47 |
TitledObject.__init__(self, title) |
TitledObject.__init__(self, title) |
48 |
|
Modifiable.__init__(self) |
49 |
self.layers = [] |
self.layers = [] |
50 |
self.label_layer = LabelLayer("Labels") |
self.label_layer = LabelLayer(_("Labels")) |
51 |
self.label_layer.Subscribe(CHANGED, self.forward, LAYERS_CHANGED) |
self.label_layer.Subscribe(CHANGED, self.forward, MAP_LAYERS_CHANGED) |
52 |
self.projection = projection |
self.projection = projection |
53 |
|
|
54 |
def Destroy(self): |
def Destroy(self): |
58 |
# cause problems. |
# cause problems. |
59 |
Modifiable.Destroy(self) |
Modifiable.Destroy(self) |
60 |
self.ClearLayers() |
self.ClearLayers() |
61 |
self.label_layer.Unsubscribe(CHANGED, self.forward, LAYERS_CHANGED) |
self.label_layer.Unsubscribe(CHANGED, self.forward, MAP_LAYERS_CHANGED) |
62 |
self.label_layer.Destroy() |
self.label_layer.Destroy() |
63 |
|
|
64 |
def AddLayer(self, layer): |
def AddLayer(self, layer): |
65 |
"""Append layer to the map on top opf all.""" |
"""Append layer to the map on top opf all.""" |
66 |
self.layers.append(layer) |
self.layers.append(layer) |
67 |
self.subscribe_layer_channels(layer) |
self.subscribe_layer_channels(layer) |
68 |
self.changed(LAYERS_CHANGED, self) |
self.changed(MAP_LAYERS_CHANGED, self) |
69 |
|
self.changed(MAP_LAYERS_ADDED, self) |
70 |
|
|
71 |
def RemoveLayer(self, layer): |
def RemoveLayer(self, layer): |
72 |
"""Remove layer from the map.""" |
"""Remove layer from the map.""" |
73 |
self.unsubscribe_layer_channels(layer) |
self.unsubscribe_layer_channels(layer) |
74 |
self.layers.remove(layer) |
self.layers.remove(layer) |
75 |
self.changed(LAYERS_CHANGED, self) |
self.changed(MAP_LAYERS_CHANGED, self) |
76 |
|
self.changed(MAP_LAYERS_REMOVED, self) |
77 |
layer.Destroy() |
layer.Destroy() |
78 |
|
|
79 |
|
def CanRemoveLayer(self, layer): |
80 |
|
"""Return true if the layer can be deleted. |
81 |
|
|
82 |
|
The default implementation always returns 1. Derived classes |
83 |
|
should override this method if they have e.g. special layers |
84 |
|
that the user should not be able to remove. |
85 |
|
""" |
86 |
|
return 1 |
87 |
|
|
88 |
def ClearLayers(self): |
def ClearLayers(self): |
89 |
"""Delete all layers.""" |
"""Delete all layers.""" |
90 |
for layer in self.layers: |
for layer in self.layers: |
92 |
layer.Destroy() |
layer.Destroy() |
93 |
del self.layers[:] |
del self.layers[:] |
94 |
self.label_layer.ClearLabels() |
self.label_layer.ClearLabels() |
95 |
self.changed(LAYERS_CHANGED, self) |
self.changed(MAP_LAYERS_CHANGED, self) |
96 |
|
self.changed(MAP_LAYERS_REMOVED, self) |
97 |
|
|
98 |
def subscribe_layer_channels(self, layer): |
def subscribe_layer_channels(self, layer): |
99 |
"""Subscribe to some of layer's channels.""" |
"""Subscribe to some of layer's channels.""" |
123 |
"""Swap the layer with the one above it. |
"""Swap the layer with the one above it. |
124 |
|
|
125 |
If the layer is already at the top do nothing. If the stacking |
If the layer is already at the top do nothing. If the stacking |
126 |
order has been changed, issue a LAYERS_CHANGED message. |
order has been changed, issue a MAP_LAYERS_CHANGED message. |
127 |
""" |
""" |
128 |
index = self.layers.index(layer) |
index = self.layers.index(layer) |
129 |
if index < len(self.layers) - 1: |
if index < len(self.layers) - 1: |
130 |
del self.layers[index] |
del self.layers[index] |
131 |
self.layers.insert(index + 1, layer) |
self.layers.insert(index + 1, layer) |
132 |
self.changed(LAYERS_CHANGED, self) |
self.changed(MAP_LAYERS_CHANGED, self) |
133 |
|
self.changed(MAP_STACKING_CHANGED, self) |
134 |
|
|
135 |
def LowerLayer(self, layer): |
def LowerLayer(self, layer): |
136 |
"""Swap the layer with the one below it. |
"""Swap the layer with the one below it. |
137 |
|
|
138 |
If the layer is already at the bottom do nothing. If the |
If the layer is already at the bottom do nothing. If the |
139 |
stacking order has been changed, issue a LAYERS_CHANGED message. |
stacking order has been changed, issue a MAP_LAYERS_CHANGED message. |
140 |
""" |
""" |
141 |
index = self.layers.index(layer) |
index = self.layers.index(layer) |
142 |
if index > 0: |
if index > 0: |
143 |
del self.layers[index] |
del self.layers[index] |
144 |
self.layers.insert(index - 1, layer) |
self.layers.insert(index - 1, layer) |
145 |
self.changed(LAYERS_CHANGED, self) |
self.changed(MAP_LAYERS_CHANGED, self) |
146 |
|
self.changed(MAP_STACKING_CHANGED, self) |
147 |
|
|
148 |
def BoundingBox(self): |
def BoundingBox(self): |
149 |
"""Return the bounding box of the map in Lat/Lon coordinates. |
"""Return the bounding box of the map in Lat/Lon coordinates. |
219 |
def TreeInfo(self): |
def TreeInfo(self): |
220 |
items = [] |
items = [] |
221 |
if self.BoundingBox() != None: |
if self.BoundingBox() != None: |
222 |
items.append("Extent (lat-lon): (%g, %g, %g, %g)" |
items.append(_("Extent (lat-lon): (%g, %g, %g, %g)") |
223 |
% self.BoundingBox()) |
% self.BoundingBox()) |
224 |
if self.projection and len(self.projection.params) > 0: |
if self.projection and len(self.projection.params) > 0: |
225 |
items.append("Extent (projected): (%g, %g, %g, %g)" |
items.append(_("Extent (projected): (%g, %g, %g, %g)") |
226 |
% self.ProjectedBoundingBox()) |
% self.ProjectedBoundingBox()) |
227 |
items.append(("Projection", |
items.append((_("Projection"), |
228 |
[str(param) |
[str(param) |
229 |
for param in self.projection.params])) |
for param in self.projection.params])) |
230 |
|
|
232 |
layers.reverse() |
layers.reverse() |
233 |
items.extend(layers) |
items.extend(layers) |
234 |
|
|
235 |
return ("Map: %s" % self.title, items) |
return (_("Map: %s") % self.title, items) |
236 |
|
|