45 |
self.projection = projection |
self.projection = projection |
46 |
|
|
47 |
def Destroy(self): |
def Destroy(self): |
48 |
for layer in self.layers: |
# call Modifiable.Destroy first since it will call |
49 |
layer.Destroy() |
# Publisher.Destroy which removes all subscriptions. Otherwise |
50 |
self.label_layer.Unsubscribe(CHANGED, self.forward, LAYERS_CHANGED) |
# clearing the layers results in messages to be sent which can |
51 |
|
# cause problems. |
52 |
Modifiable.Destroy(self) |
Modifiable.Destroy(self) |
53 |
|
self.ClearLayers() |
54 |
|
self.label_layer.Unsubscribe(CHANGED, self.forward, LAYERS_CHANGED) |
55 |
|
self.label_layer.Destroy() |
56 |
|
|
57 |
def AddLayer(self, layer): |
def AddLayer(self, layer): |
58 |
|
"""Append layer to the map on top opf all.""" |
59 |
self.layers.append(layer) |
self.layers.append(layer) |
60 |
for channel in self.forwarded_channels: |
self.subscribe_layer_channels(layer) |
|
layer.Subscribe(channel, self.forward, channel) |
|
61 |
self.changed(LAYERS_CHANGED, self) |
self.changed(LAYERS_CHANGED, self) |
62 |
|
|
63 |
def RemoveLayer(self, layer): |
def RemoveLayer(self, layer): |
64 |
for channel in self.forwarded_channels: |
"""Remove layer from the map.""" |
65 |
layer.Unsubscribe(channel, self.forward, channel) |
self.unsubscribe_layer_channels(layer) |
66 |
self.layers.remove(layer) |
self.layers.remove(layer) |
67 |
self.changed(LAYERS_CHANGED, self) |
self.changed(LAYERS_CHANGED, self) |
68 |
layer.Destroy() |
layer.Destroy() |
69 |
|
|
70 |
|
def CanRemoveLayer(self, layer): |
71 |
|
"""Return true if the layer can be deleted. |
72 |
|
|
73 |
|
The default implementation always returns 1. Derived classes |
74 |
|
should override this method if they have e.g. special layers |
75 |
|
that the user should not be able to remove. |
76 |
|
""" |
77 |
|
return 1 |
78 |
|
|
79 |
|
def ClearLayers(self): |
80 |
|
"""Delete all layers.""" |
81 |
|
for layer in self.layers: |
82 |
|
self.unsubscribe_layer_channels(layer) |
83 |
|
layer.Destroy() |
84 |
|
del self.layers[:] |
85 |
|
self.label_layer.ClearLabels() |
86 |
|
self.changed(LAYERS_CHANGED, self) |
87 |
|
|
88 |
|
def subscribe_layer_channels(self, layer): |
89 |
|
"""Subscribe to some of layer's channels.""" |
90 |
|
for channel in self.forwarded_channels: |
91 |
|
layer.Subscribe(channel, self.forward, channel) |
92 |
|
|
93 |
|
def unsubscribe_layer_channels(self, layer): |
94 |
|
"""Unsubscribe to some of layer's channels.""" |
95 |
|
for channel in self.forwarded_channels: |
96 |
|
layer.Unsubscribe(channel, self.forward, channel) |
97 |
|
|
98 |
def LabelLayer(self): |
def LabelLayer(self): |
99 |
"""Return the Map's label layer""" |
"""Return the Map's label layer""" |
100 |
return self.label_layer |
return self.label_layer |
101 |
|
|
102 |
def Layers(self): |
def Layers(self): |
103 |
|
"""Return the list of layers contained in the map. |
104 |
|
|
105 |
|
The list does not include the label layer""" |
106 |
return self.layers |
return self.layers |
107 |
|
|
108 |
def HasLayers(self): |
def HasLayers(self): |
109 |
|
"""Return true if the map has at least one shape layer""" |
110 |
return len(self.layers) > 0 |
return len(self.layers) > 0 |
111 |
|
|
112 |
def RaiseLayer(self, layer): |
def RaiseLayer(self, layer): |
113 |
|
"""Swap the layer with the one above it. |
114 |
|
|
115 |
|
If the layer is already at the top do nothing. If the stacking |
116 |
|
order has been changed, issue a LAYERS_CHANGED message. |
117 |
|
""" |
118 |
index = self.layers.index(layer) |
index = self.layers.index(layer) |
119 |
if index < len(self.layers) - 1: |
if index < len(self.layers) - 1: |
120 |
del self.layers[index] |
del self.layers[index] |
121 |
self.layers.insert(index + 1, layer) |
self.layers.insert(index + 1, layer) |
122 |
self.changed(LAYERS_CHANGED, self) |
self.changed(LAYERS_CHANGED, self) |
123 |
|
|
124 |
def LowerLayer(self, layer): |
def LowerLayer(self, layer): |
125 |
|
"""Swap the layer with the one below it. |
126 |
|
|
127 |
|
If the layer is already at the bottom do nothing. If the |
128 |
|
stacking order has been changed, issue a LAYERS_CHANGED message. |
129 |
|
""" |
130 |
index = self.layers.index(layer) |
index = self.layers.index(layer) |
131 |
if index > 0: |
if index > 0: |
132 |
del self.layers[index] |
del self.layers[index] |
133 |
self.layers.insert(index - 1, layer) |
self.layers.insert(index - 1, layer) |
134 |
self.changed(LAYERS_CHANGED, self) |
self.changed(LAYERS_CHANGED, self) |
135 |
|
|
136 |
def BoundingBox(self): |
def BoundingBox(self): |
137 |
"""Return the bounding box of the map in projected coordinates. |
"""Return the bounding box of the map in Lat/Lon coordinates. |
138 |
|
|
139 |
Return None if there are no layers or no layer contains any shapes. |
Return None if there are no layers or no layer contains any shapes. |
140 |
""" |
""" |
163 |
return None |
return None |
164 |
|
|
165 |
def ProjectedBoundingBox(self): |
def ProjectedBoundingBox(self): |
166 |
|
"""Return the bounding box of the map in projected coordinates. |
167 |
|
|
168 |
|
Return None if there are no layers or no layer contains any shapes. |
169 |
|
""" |
170 |
# This simply returns the rectangle given by the projected |
# This simply returns the rectangle given by the projected |
171 |
# corners of the non-projected bbox. |
# corners of the non-projected bbox. |
172 |
bbox = self.BoundingBox() |
bbox = self.BoundingBox() |
175 |
return bbox |
return bbox |
176 |
|
|
177 |
def SetProjection(self, projection): |
def SetProjection(self, projection): |
178 |
|
"""Set the projection of the map. |
179 |
|
|
180 |
|
Issue a MAP_PROJECTION_CHANGED message.""" |
181 |
self.projection = projection |
self.projection = projection |
182 |
self.changed(MAP_PROJECTION_CHANGED, self) |
self.changed(MAP_PROJECTION_CHANGED, self) |
183 |
|
|
204 |
layer.UnsetModified() |
layer.UnsetModified() |
205 |
self.label_layer.UnsetModified() |
self.label_layer.UnsetModified() |
206 |
|
|
207 |
|
def TreeInfo(self): |
208 |
|
items = [] |
209 |
|
if self.BoundingBox() != None: |
210 |
|
items.append("Extent (lat-lon): (%g, %g, %g, %g)" |
211 |
|
% self.BoundingBox()) |
212 |
|
if self.projection and len(self.projection.params) > 0: |
213 |
|
items.append("Extent (projected): (%g, %g, %g, %g)" |
214 |
|
% self.ProjectedBoundingBox()) |
215 |
|
items.append(("Projection", |
216 |
|
[str(param) |
217 |
|
for param in self.projection.params])) |
218 |
|
|
219 |
|
layers = self.layers[:] |
220 |
|
layers.reverse() |
221 |
|
items.extend(layers) |
222 |
|
|
223 |
|
return ("Map: %s" % self.title, items) |
224 |
|
|