/[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 178 by bh, Wed May 15 14:02:20 2002 UTC revision 249 by bh, Tue Jul 30 14:17:33 2002 UTC
# Line 45  class Map(TitledObject, Modifiable): Line 45  class Map(TitledObject, Modifiable):
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 ClearLayers(self):
71            """Delete all layers."""
72            for layer in self.layers:
73                self.unsubscribe_layer_channels(layer)
74                layer.Destroy()
75            del self.layers[:]
76            self.label_layer.ClearLabels()
77            self.changed(LAYERS_CHANGED, self)
78    
79        def subscribe_layer_channels(self, layer):
80            """Subscribe to some of layer's channels."""
81            for channel in self.forwarded_channels:
82                layer.Subscribe(channel, self.forward, channel)
83    
84        def unsubscribe_layer_channels(self, layer):
85            """Unsubscribe to some of layer's channels."""
86            for channel in self.forwarded_channels:
87                layer.Unsubscribe(channel, self.forward, channel)
88    
89      def LabelLayer(self):      def LabelLayer(self):
90          """Return the Map's label layer"""          """Return the Map's label layer"""
91          return self.label_layer          return self.label_layer
92    
93      def Layers(self):      def Layers(self):
94            """Return the list of layers contained in the map.
95    
96            The list does not include the label layer"""
97          return self.layers          return self.layers
98    
99      def HasLayers(self):      def HasLayers(self):
100            """Return true if the map has at least one shape layer"""
101          return len(self.layers) > 0          return len(self.layers) > 0
102    
103      def RaiseLayer(self, layer):      def RaiseLayer(self, layer):
104            """Swap the layer with the one above it.
105    
106            If the layer is already at the top do nothing. If the stacking
107            order has been changed, issue a LAYERS_CHANGED message.
108            """
109          index = self.layers.index(layer)          index = self.layers.index(layer)
110          if index < len(self.layers) - 1:          if index < len(self.layers) - 1:
111              del self.layers[index]              del self.layers[index]
112              self.layers.insert(index + 1, layer)              self.layers.insert(index + 1, layer)
113          self.changed(LAYERS_CHANGED, self)              self.changed(LAYERS_CHANGED, self)
114    
115      def LowerLayer(self, layer):      def LowerLayer(self, layer):
116            """Swap the layer with the one below it.
117    
118            If the layer is already at the bottom do nothing. If the
119            stacking order has been changed, issue a LAYERS_CHANGED message.
120            """
121          index = self.layers.index(layer)          index = self.layers.index(layer)
122          if index > 0:          if index > 0:
123              del self.layers[index]              del self.layers[index]
124              self.layers.insert(index - 1, layer)              self.layers.insert(index - 1, layer)
125          self.changed(LAYERS_CHANGED, self)              self.changed(LAYERS_CHANGED, self)
126    
127      def BoundingBox(self):      def BoundingBox(self):
128          """Return the bounding box of the map in projected coordinates.          """Return the bounding box of the map in Lat/Lon coordinates.
129    
130          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.
131          """          """
# Line 117  class Map(TitledObject, Modifiable): Line 154  class Map(TitledObject, Modifiable):
154              return None              return None
155    
156      def ProjectedBoundingBox(self):      def ProjectedBoundingBox(self):
157            """Return the bounding box of the map in projected coordinates.
158    
159            Return None if there are no layers or no layer contains any shapes.
160            """
161          # This simply returns the rectangle given by the projected          # This simply returns the rectangle given by the projected
162          # corners of the non-projected bbox.          # corners of the non-projected bbox.
163          bbox = self.BoundingBox()          bbox = self.BoundingBox()
# Line 125  class Map(TitledObject, Modifiable): Line 166  class Map(TitledObject, Modifiable):
166          return bbox          return bbox
167    
168      def SetProjection(self, projection):      def SetProjection(self, projection):
169            """Set the projection of the map.
170    
171            Issue a MAP_PROJECTION_CHANGED message."""
172          self.projection = projection          self.projection = projection
173          self.changed(MAP_PROJECTION_CHANGED, self)          self.changed(MAP_PROJECTION_CHANGED, self)
174    
# Line 151  class Map(TitledObject, Modifiable): Line 195  class Map(TitledObject, Modifiable):
195              layer.UnsetModified()              layer.UnsetModified()
196          self.label_layer.UnsetModified()          self.label_layer.UnsetModified()
197    
198        def TreeInfo(self):
199            items = []
200            if self.BoundingBox() != None:
201                items.append("Extent (lat-lon): (%g, %g, %g, %g)"
202                             % self.BoundingBox())
203                if self.projection and len(self.projection.params) > 0:
204                    items.append("Extent (projected): (%g, %g, %g, %g)"
205                                 % self.ProjectedBoundingBox())
206                    items.append(("Projection",
207                                  [str(param)
208                                   for param in self.projection.params]))
209    
210            layers = self.layers[:]
211            layers.reverse()
212            items.extend(layers)
213    
214            return ("Map: %s" % self.title, items)
215    

Legend:
Removed from v.178  
changed lines
  Added in v.249

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26