/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/scalebar.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/UI/scalebar.py

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

revision 866 by frank, Thu May 8 13:40:32 2003 UTC revision 1240 by frank, Thu Jun 19 09:25:31 2003 UTC
# Line 8  Line 8 
8  __version__ = "$Revision$"  __version__ = "$Revision$"
9    
10  from Thuban import _  from Thuban import _
11  from Thuban.Model.scalebar import *  from Thuban.Model.scalebar import deriveInterval, roundInterval
12    
13  from wxPython.wx import *  from wxPython.wx import *
14    
# Line 17  class ScaleBar: Line 17  class ScaleBar:
17      def __init__(self, map):      def __init__(self, map):
18          self.map = map          self.map = map
19    
20      def DrawScalebar(self, scale, dc):      def DrawScaleBar(self, scale, dc, position, size):
21          """Draw a scalebar on a given DC"""          """Draw a scalebar on a given DC"""
22    
23          # Only draw a legend if the corresponding map has a layer          # Only draw a legend if the corresponding map has a layer
# Line 30  class ScaleBar: Line 30  class ScaleBar:
30                  BlackBrush = wxGREY_BRUSH                  BlackBrush = wxGREY_BRUSH
31                  BlackText = wxColor(127,127,127)                  BlackText = wxColor(127,127,127)
32              else:              else:
33                    params = {}
34                    # For geographic projection we have to convert the scale from
35                    # Unit DD to meters.
36                    for p in self.map.projection.params:
37                        key, value = p.split('=')
38                        params[key] = value
39                    if params['proj'] == 'latlong':
40                        scale = scale * 0.017453 / 1000.0
41                    # We have a projection, draw the scalebar in bw
42                  BlackPen = wxBLACK_PEN                  BlackPen = wxBLACK_PEN
43                  BlackBrush = wxBLACK_BRUSH                  BlackBrush = wxBLACK_BRUSH
44                  BlackText = wxBLACK                  BlackText = wxBLACK
45                                    
46              # Get the dimension              # Get the dimension
47              width, height = dc.GetSizeTuple()              width, height = size
48                posx, posy    = position
49              l1width, l1height = dc.GetTextExtent("%d"%0)              l1width, l1height = dc.GetTextExtent("%d"%0)
50    
51              # Make a first guess for the interval (to get the size we have              # Make a first guess for the interval (to get the size we have
# Line 48  class ScaleBar: Line 58  class ScaleBar:
58              interval, unit  = deriveInterval(width, scale)              interval, unit  = deriveInterval(width, scale)
59              interval, label = roundInterval(interval)              interval, label = roundInterval(interval)
60                            
61              # We draw 2 rectangles with half the width              if interval > 0.0:
62              if unit == 'km':                  # We draw 2 rectangles with half the width
63                  width = int(interval*1000.0*scale/2)                  if unit == 'km':
64              else:                      width = int(interval*1000.0*scale/2)
65                  width = int(interval*scale/2)                  else:
66                        width = int(interval*scale/2)
67                            
68              dc.SetPen(BlackPen)                  dc.SetPen(BlackPen)
69    
70              brush = wxBrush(wxWHITE, wxSOLID)                  brush = wxBrush(wxWHITE, wxSOLID)
71              dc.SetBrush(brush)                  dc.SetBrush(brush)
72              dc.DrawRectangle(4,2,width,8)                  dc.DrawRectangle(posx+4,posy+2,width,8)
73    
74              dc.SetBrush(BlackBrush)                  dc.SetBrush(BlackBrush)
75              dc.DrawRectangle(width+4,2,width,8)                  dc.DrawRectangle(posx+width+4,posy+2,width,8)
76    
77              dc.SetTextForeground(BlackText)                  dc.SetTextForeground(BlackText)
78              dc.DrawText("%d"%0, 4 - l1width/2, 12)                  dc.DrawText("%d"%0, posx+ 4 - l1width/2, posy+12)
79    
80              l2width, l2height = dc.GetTextExtent("%s %s"%(label, unit))                  l2width, l2height = dc.GetTextExtent("%s %s"%(label, unit))
81              dc.DrawText("%s %s"%(interval, unit), 2*width+4 - l2width/2, 12)                  dc.DrawText("%s %s"%(interval, unit), posx+ 2*width+4 - l2width/2, posy + 12)
82    

Legend:
Removed from v.866  
changed lines
  Added in v.1240

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26