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_VISIBILITY_CHANGED) |
LAYER_VISIBILITY_CHANGED) |
43 |
|
|
44 |
def __init__(self, title, projection = None): |
def __init__(self, title, projection = None): |
45 |
"""Initialize the map.""" |
"""Initialize the map.""" |
46 |
TitledObject.__init__(self, title) |
TitledObject.__init__(self, title) |
47 |
|
Modifiable.__init__(self) |
48 |
self.layers = [] |
self.layers = [] |
49 |
self.label_layer = LabelLayer("Labels") |
self.label_layer = LabelLayer(_("Labels")) |
50 |
self.label_layer.Subscribe(CHANGED, self.forward, LAYERS_CHANGED) |
self.label_layer.Subscribe(CHANGED, self.forward, MAP_LAYERS_CHANGED) |
51 |
self.projection = projection |
self.projection = projection |
52 |
|
|
53 |
def Destroy(self): |
def Destroy(self): |
57 |
# cause problems. |
# cause problems. |
58 |
Modifiable.Destroy(self) |
Modifiable.Destroy(self) |
59 |
self.ClearLayers() |
self.ClearLayers() |
60 |
self.label_layer.Unsubscribe(CHANGED, self.forward, LAYERS_CHANGED) |
self.label_layer.Unsubscribe(CHANGED, self.forward, MAP_LAYERS_CHANGED) |
61 |
self.label_layer.Destroy() |
self.label_layer.Destroy() |
62 |
|
|
63 |
def AddLayer(self, layer): |
def AddLayer(self, layer): |
64 |
"""Append layer to the map on top opf all.""" |
"""Append layer to the map on top opf all.""" |
65 |
self.layers.append(layer) |
self.layers.append(layer) |
66 |
self.subscribe_layer_channels(layer) |
self.subscribe_layer_channels(layer) |
67 |
self.changed(LAYERS_CHANGED, self) |
self.changed(MAP_LAYERS_CHANGED, self) |
68 |
|
self.changed(MAP_LAYERS_ADDED, self) |
69 |
|
|
70 |
def RemoveLayer(self, layer): |
def RemoveLayer(self, layer): |
71 |
"""Remove layer from the map.""" |
"""Remove layer from the map.""" |
72 |
self.unsubscribe_layer_channels(layer) |
self.unsubscribe_layer_channels(layer) |
73 |
self.layers.remove(layer) |
self.layers.remove(layer) |
74 |
self.changed(LAYERS_CHANGED, self) |
self.changed(MAP_LAYERS_CHANGED, self) |
75 |
|
self.changed(MAP_LAYERS_REMOVED, self) |
76 |
layer.Destroy() |
layer.Destroy() |
77 |
|
|
78 |
def CanRemoveLayer(self, layer): |
def CanRemoveLayer(self, layer): |
91 |
layer.Destroy() |
layer.Destroy() |
92 |
del self.layers[:] |
del self.layers[:] |
93 |
self.label_layer.ClearLabels() |
self.label_layer.ClearLabels() |
94 |
self.changed(LAYERS_CHANGED, self) |
self.changed(MAP_LAYERS_CHANGED, self) |
95 |
|
self.changed(MAP_LAYERS_REMOVED, self) |
96 |
|
|
97 |
def subscribe_layer_channels(self, layer): |
def subscribe_layer_channels(self, layer): |
98 |
"""Subscribe to some of layer's channels.""" |
"""Subscribe to some of layer's channels.""" |
122 |
"""Swap the layer with the one above it. |
"""Swap the layer with the one above it. |
123 |
|
|
124 |
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 |
125 |
order has been changed, issue a LAYERS_CHANGED message. |
order has been changed, issue a MAP_LAYERS_CHANGED message. |
126 |
""" |
""" |
127 |
index = self.layers.index(layer) |
index = self.layers.index(layer) |
128 |
if index < len(self.layers) - 1: |
if index < len(self.layers) - 1: |
129 |
del self.layers[index] |
del self.layers[index] |
130 |
self.layers.insert(index + 1, layer) |
self.layers.insert(index + 1, layer) |
131 |
self.changed(LAYERS_CHANGED, self) |
self.changed(MAP_LAYERS_CHANGED, self) |
132 |
|
self.changed(MAP_STACKING_CHANGED, self) |
133 |
|
|
134 |
def LowerLayer(self, layer): |
def LowerLayer(self, layer): |
135 |
"""Swap the layer with the one below it. |
"""Swap the layer with the one below it. |
136 |
|
|
137 |
If the layer is already at the bottom do nothing. If the |
If the layer is already at the bottom do nothing. If the |
138 |
stacking order has been changed, issue a LAYERS_CHANGED message. |
stacking order has been changed, issue a MAP_LAYERS_CHANGED message. |
139 |
""" |
""" |
140 |
index = self.layers.index(layer) |
index = self.layers.index(layer) |
141 |
if index > 0: |
if index > 0: |
142 |
del self.layers[index] |
del self.layers[index] |
143 |
self.layers.insert(index - 1, layer) |
self.layers.insert(index - 1, layer) |
144 |
self.changed(LAYERS_CHANGED, self) |
self.changed(MAP_LAYERS_CHANGED, self) |
145 |
|
self.changed(MAP_STACKING_CHANGED, self) |
146 |
|
|
147 |
def BoundingBox(self): |
def BoundingBox(self): |
148 |
"""Return the bounding box of the map in Lat/Lon coordinates. |
"""Return the bounding box of the map in Lat/Lon coordinates. |
218 |
def TreeInfo(self): |
def TreeInfo(self): |
219 |
items = [] |
items = [] |
220 |
if self.BoundingBox() != None: |
if self.BoundingBox() != None: |
221 |
items.append("Extent (lat-lon): (%g, %g, %g, %g)" |
items.append(_("Extent (lat-lon): (%g, %g, %g, %g)") |
222 |
% self.BoundingBox()) |
% self.BoundingBox()) |
223 |
if self.projection and len(self.projection.params) > 0: |
if self.projection and len(self.projection.params) > 0: |
224 |
items.append("Extent (projected): (%g, %g, %g, %g)" |
items.append(_("Extent (projected): (%g, %g, %g, %g)") |
225 |
% self.ProjectedBoundingBox()) |
% self.ProjectedBoundingBox()) |
226 |
items.append(("Projection", |
items.append((_("Projection"), |
227 |
[str(param) |
[str(param) |
228 |
for param in self.projection.params])) |
for param in self.projection.params])) |
229 |
|
|
231 |
layers.reverse() |
layers.reverse() |
232 |
items.extend(layers) |
items.extend(layers) |
233 |
|
|
234 |
return ("Map: %s" % self.title, items) |
return (_("Map: %s") % self.title, items) |
235 |
|
|