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 |
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 |
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 |
|
|