/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/Model/map.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/Model/map.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1099 by jonathan, Fri May 30 06:28:02 2003 UTC revision 2569 by jan, Thu Feb 17 11:02:28 2005 UTC
# Line 1  Line 1 
1  # Copyright (c) 2001, 2002 by Intevation GmbH  # Copyright (c) 2001-2003, 2005 by Intevation GmbH
2  # Authors:  # Authors:
3  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
4    # Jonathan Coles <[email protected]>
5  #  #
6  # This program is free software under the GPL (>=v2)  # This program is free software under the GPL (>=v2)
7  # Read the file COPYING coming with Thuban for details.  # Read the file COPYING coming with Thuban for details.
# Line 21  from label import LabelLayer Line 22  from label import LabelLayer
22    
23  class Map(TitledObject, Modifiable):  class Map(TitledObject, Modifiable):
24    
25      """Represent a map. A map is simply a list of layers.      """Represent a map.
26    
27        A map is a list of layers. Additionally
28        there is a special label layer containing all labels that
29        are defined for the map.
30    
31      Map objects send the following message types:      Map objects send the following message types:
32    
# Line 50  class Map(TitledObject, Modifiable): Line 55  class Map(TitledObject, Modifiable):
55          self.projection = projection          self.projection = projection
56    
57      def Destroy(self):      def Destroy(self):
58          # call Modifiable.Destroy first since it will call          """Destroys the map object with all layers including the label layer.
59          # Publisher.Destroy which removes all subscriptions. Otherwise  
60          # clearing the layers results in messages to be sent which can          Calls Modifiable. Destroy first since it will call
61          # cause problems.          Publisher.Destroy which removes all subscriptions. Otherwise
62            clearing the layers results in messages to be sent which can
63            cause problems.
64            """
65          Modifiable.Destroy(self)          Modifiable.Destroy(self)
66          self.ClearLayers()          self.ClearLayers()
67          self.label_layer.Unsubscribe(CHANGED, self.forward, MAP_LAYERS_CHANGED)          self.label_layer.Unsubscribe(CHANGED, self.forward, MAP_LAYERS_CHANGED)
68          self.label_layer.Destroy()          self.label_layer.Destroy()
69    
70      def AddLayer(self, layer):      def AddLayer(self, layer):
71          """Append layer to the map on top opf all."""          """Append layer to the map on top of all."""
72          self.layers.append(layer)          self.layers.append(layer)
73          self.subscribe_layer_channels(layer)          self.subscribe_layer_channels(layer)
74          self.changed(MAP_LAYERS_CHANGED, self)          self.changed(MAP_LAYERS_CHANGED, self)
75          self.changed(MAP_LAYERS_ADDED, self)          self.changed(MAP_LAYERS_ADDED, self)
76    
77      def RemoveLayer(self, layer):      def RemoveLayer(self, layer):
78          """Remove layer from the map."""          """Remove layer from the map.
79    
80            This can not be applied for the label layer of the map.
81            """
82          self.unsubscribe_layer_channels(layer)          self.unsubscribe_layer_channels(layer)
83          self.layers.remove(layer)          self.layers.remove(layer)
84          self.changed(MAP_LAYERS_CHANGED, self)          self.changed(MAP_LAYERS_CHANGED, self)
# Line 84  class Map(TitledObject, Modifiable): Line 95  class Map(TitledObject, Modifiable):
95          return 1          return 1
96    
97      def ClearLayers(self):      def ClearLayers(self):
98          """Delete all layers."""          """Delete all layers and also remove all labels from the label layer.
99            """
100          for layer in self.layers:          for layer in self.layers:
101              self.unsubscribe_layer_channels(layer)              self.unsubscribe_layer_channels(layer)
102              layer.Destroy()              layer.Destroy()
# Line 110  class Map(TitledObject, Modifiable): Line 122  class Map(TitledObject, Modifiable):
122      def Layers(self):      def Layers(self):
123          """Return the list of layers contained in the map.          """Return the list of layers contained in the map.
124    
125          The list does not include the label layer"""          The list does not include the label layer which
126            can be retrieved by a separate method."""
127          return self.layers          return self.layers
128    
129      def HasLayers(self):      def HasLayers(self):
130          """Return true if the map has at least one shape layer"""          """Information whether this map has layers.
131    
132            Returns true if the map has at least one layer other
133            than the label layer."""
134          return len(self.layers) > 0          return len(self.layers) > 0
135    
136      def MoveLayerToTop(self, layer):      def MoveLayerToTop(self, layer):
137          """Put the layer on top of the layer stack.          """Put the layer on top of the layer stack.
138    
139            This can not be applied to the label layer.
140    
141          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
142          order has been changed, issue a MAP_LAYERS_CHANGED message.          order has been changed, issue a MAP_LAYERS_CHANGED message.
143          """          """
# Line 130  class Map(TitledObject, Modifiable): Line 148  class Map(TitledObject, Modifiable):
148              self.changed(MAP_LAYERS_CHANGED, self)              self.changed(MAP_LAYERS_CHANGED, self)
149              self.changed(MAP_STACKING_CHANGED, self)              self.changed(MAP_STACKING_CHANGED, self)
150    
           
151      def RaiseLayer(self, layer):      def RaiseLayer(self, layer):
152          """Swap the layer with the one above it.          """Swap the layer with the one above it.
153    
154            This does not apply to the label layer.
155    
156          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
157          order has been changed, issue a MAP_LAYERS_CHANGED message.          order has been changed, issue a MAP_LAYERS_CHANGED message.
158          """          """
# Line 147  class Map(TitledObject, Modifiable): Line 166  class Map(TitledObject, Modifiable):
166      def LowerLayer(self, layer):      def LowerLayer(self, layer):
167          """Swap the layer with the one below it.          """Swap the layer with the one below it.
168    
169            This does not apply to the label layer.
170    
171          If the layer is already at the bottom do nothing. If the          If the layer is already at the bottom do nothing. If the
172          stacking order has been changed, issue a MAP_LAYERS_CHANGED message.          stacking order has been changed, issue a MAP_LAYERS_CHANGED message.
173          """          """
# Line 160  class Map(TitledObject, Modifiable): Line 181  class Map(TitledObject, Modifiable):
181      def MoveLayerToBottom(self, layer):      def MoveLayerToBottom(self, layer):
182          """Put the layer at the bottom of the stack.          """Put the layer at the bottom of the stack.
183    
184            This does not apply to the label layer.
185    
186          If the layer is already at the bottom do nothing. If the          If the layer is already at the bottom do nothing. If the
187          stacking order has been changed, issue a MAP_LAYERS_CHANGED message.          stacking order has been changed, issue a MAP_LAYERS_CHANGED message.
188          """          """
# Line 173  class Map(TitledObject, Modifiable): Line 196  class Map(TitledObject, Modifiable):
196      def BoundingBox(self):      def BoundingBox(self):
197          """Return the bounding box of the map in Lat/Lon coordinates.          """Return the bounding box of the map in Lat/Lon coordinates.
198    
199          Return None if there are no layers or no layer contains any shapes.          The label layer is not considered for the computation of the
200            bounding box.
201    
202            Return None if there are no layers (except the label layer) or
203            no layer contains any shapes.
204          """          """
205          if not self.layers:          if not self.layers:
206              return None              return None
# Line 182  class Map(TitledObject, Modifiable): Line 209  class Map(TitledObject, Modifiable):
209          urx = []          urx = []
210          ury = []          ury = []
211          for layer in self.layers:          for layer in self.layers:
             if layer is self.label_layer:  
                 continue  
212              # the layer's bbox may be None if it doesn't have any shapes              # the layer's bbox may be None if it doesn't have any shapes
213              bbox = layer.LatLongBoundingBox()              bbox = layer.LatLongBoundingBox()
214              if bbox is not None:              if bbox is not None:
# Line 202  class Map(TitledObject, Modifiable): Line 227  class Map(TitledObject, Modifiable):
227      def ProjectedBoundingBox(self):      def ProjectedBoundingBox(self):
228          """Return the bounding box of the map in projected coordinates.          """Return the bounding box of the map in projected coordinates.
229    
230          Return None if there are no layers or no layer contains any shapes.          The label layer is not considered for the computation of the
231            bounding box.
232    
233            Return None if there are no layers (except the label layer) or
234            no layer contains any shapes.
235          """          """
236          # This simply returns the rectangle given by the projected          # This simply returns the rectangle given by the projected
237          # corners of the non-projected bbox.          # corners of the non-projected bbox.
# Line 212  class Map(TitledObject, Modifiable): Line 241  class Map(TitledObject, Modifiable):
241          return bbox          return bbox
242    
243      def GetProjection(self):      def GetProjection(self):
244            """Return the projection of the map."""
245          return self.projection          return self.projection
246    
247      def SetProjection(self, projection):      def SetProjection(self, projection):
248          """Set the projection of the map.          """Set the projection of the map.
249    
250          Issue a MAP_PROJECTION_CHANGED message."""          Issue a MAP_PROJECTION_CHANGED message.
251            """
252            old_proj = self.projection
253          self.projection = projection          self.projection = projection
254          self.changed(MAP_PROJECTION_CHANGED, self)          self.changed(MAP_PROJECTION_CHANGED, self, old_proj)
255    
256      def forward(self, *args):      def forward(self, *args):
257          """Reissue events"""          """Reissue events"""
# Line 245  class Map(TitledObject, Modifiable): Line 277  class Map(TitledObject, Modifiable):
277          self.label_layer.UnsetModified()          self.label_layer.UnsetModified()
278    
279      def TreeInfo(self):      def TreeInfo(self):
280            """Return a description of the object.
281    
282            A tuple of (title, tupel) describing the contents
283            of the object in a tree-structure is returned.
284            """
285          items = []          items = []
286          if self.BoundingBox() != None:          if self.BoundingBox() != None:
287              items.append(_("Extent (lat-lon): (%g, %g, %g, %g)")              items.append(_("Extent (lat-lon): (%g, %g, %g, %g)")
# Line 259  class Map(TitledObject, Modifiable): Line 296  class Map(TitledObject, Modifiable):
296          layers = self.layers[:]          layers = self.layers[:]
297          layers.reverse()          layers.reverse()
298          items.extend(layers)          items.extend(layers)
299            items.append(self.label_layer)
300    
301          return (_("Map: %s") % self.title, items)          return (_("Map: %s") % self.title, items)
   

Legend:
Removed from v.1099  
changed lines
  Added in v.2569

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26