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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6 - (show annotations)
Tue Aug 28 15:41:52 2001 UTC (23 years, 6 months ago) by bh
Original Path: trunk/thuban/Thuban/Model/map.py
File MIME type: text/x-python
File size: 4296 byte(s)
import all the source files

1 # Copyright (c) 2001 by Intevation GmbH
2 # Authors:
3 # Bernhard Herzog <[email protected]>
4 #
5 # This program is free software under the GPL (>=v2)
6 # Read the file COPYING coming with Thuban for details.
7
8 __version__ = "$Revision$"
9
10 from messages import LAYERS_CHANGED, MAP_PROJECTION_CHANGED, \
11 CHANGED, LAYER_PROJECTION_CHANGED, LAYER_LEGEND_CHANGED, \
12 LAYER_VISIBILITY_CHANGED
13
14 from base import TitledObject, Modifiable
15
16 from label import LabelLayer
17
18
19
20 class Map(TitledObject, Modifiable):
21
22 """Represent a map. A map is simply a list of layers.
23
24 Map objects send the following message types:
25
26 TITLE_CHANGED -- The title has changed. Parameter: the map.
27
28 LAYERS_CHANGED -- Layers were added, removed or rearranged.
29 Parameters: the map
30
31 MAP_PROJECTION_CHANGED -- the map's projection has changed.
32 Parameter: the map
33 """
34
35 forwarded_channels = (LAYER_PROJECTION_CHANGED,
36 LAYER_LEGEND_CHANGED,
37 LAYER_VISIBILITY_CHANGED)
38
39 def __init__(self, title, projection = None):
40 """Initialize the map."""
41 TitledObject.__init__(self, title)
42 self.layers = []
43 self.label_layer = LabelLayer("Labels")
44 self.label_layer.Subscribe(CHANGED, self.forward, LAYERS_CHANGED)
45 self.projection = projection
46
47 def Destroy(self):
48 for layer in self.layers:
49 layer.Destroy()
50 Modifiable.Destroy(self)
51
52 def AddLayer(self, layer):
53 self.layers.append(layer)
54 for channel in self.forwarded_channels:
55 layer.Subscribe(channel, self.forward, channel)
56 self.changed(LAYERS_CHANGED, self)
57
58 def RemoveLayer(self, layer):
59 for channel in self.forwarded_channels:
60 layer.Unsubscribe(channel, self.forward, channel)
61 self.layers.remove(layer)
62 self.changed(LAYERS_CHANGED, self)
63 layer.Destroy()
64
65 def LabelLayer(self):
66 """Return the Map's label layer"""
67 return self.label_layer
68
69 def Layers(self):
70 return self.layers
71
72 def HasLayers(self):
73 return len(self.layers) > 0
74
75 def RaiseLayer(self, layer):
76 index = self.layers.index(layer)
77 if index < len(self.layers) - 1:
78 del self.layers[index]
79 self.layers.insert(index + 1, layer)
80 self.changed(LAYERS_CHANGED, self)
81
82 def LowerLayer(self, layer):
83 index = self.layers.index(layer)
84 if index > 0:
85 del self.layers[index]
86 self.layers.insert(index - 1, layer)
87 self.changed(LAYERS_CHANGED, self)
88
89 def BoundingBox(self):
90 if not self.layers:
91 return None
92 llx = []
93 lly = []
94 urx = []
95 ury = []
96 for layer in self.layers:
97 if layer is self.label_layer:
98 continue
99 left, bottom, right, top = layer.LatLongBoundingBox()
100 llx.append(left)
101 lly.append(bottom)
102 urx.append(right)
103 ury.append(top)
104 return (min(llx), min(lly), max(urx), max(ury))
105
106 def ProjectedBoundingBox(self):
107 # This simply returns the rectangle given by the projected
108 # corners of the non-projected bbox.
109 bbox = self.BoundingBox()
110 if bbox is not None and self.projection is not None:
111 bbox = self.projection.ForwardBBox(bbox)
112 return bbox
113
114 def SetProjection(self, projection):
115 self.projection = projection
116 self.changed(MAP_PROJECTION_CHANGED, self)
117
118 def forward(self, *args):
119 """Reissue events"""
120 if len(args) > 1:
121 args = (args[-1],) + args[:-1]
122 apply(self.issue, args)
123
124 def WasModified(self):
125 """Return true if the map or one of the layers was modified"""
126 if self.modified:
127 return 1
128 else:
129 for layer in self.layers:
130 if layer.WasModified():
131 return 1
132 return self.label_layer.WasModified()
133
134 def UnsetModified(self):
135 """Unset the modified flag of the map and the layers"""
136 Modifiable.UnsetModified(self)
137 for layer in self.layers:
138 layer.UnsetModified()
139 self.label_layer.UnsetModified()
140
141

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26