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 |
|
from Thuban.Model.proj import PROJ_UNITS_METERS |
13 |
|
|
14 |
from wxPython.wx import * |
from wxPython.wx import * |
15 |
|
|
18 |
def __init__(self, map): |
def __init__(self, map): |
19 |
self.map = map |
self.map = map |
20 |
|
|
21 |
def DrawScalebar(self, scale, dc): |
def DrawScaleBar(self, scale, dc, position, size): |
22 |
"""Draw a scalebar on a given DC""" |
"""Draw a scalebar on a given DC""" |
23 |
|
|
24 |
# Only draw a legend if the corresponding map has a layer |
# Only draw a legend if the corresponding map has a layer |
25 |
if self.map is not None and len(self.map.layers) > 0 and scale > 0.0: |
if self.map is not None \ |
26 |
|
and self.map.projection is not None \ |
27 |
# If no projection is specified, the scale information _might_ |
and len(self.map.layers) > 0 \ |
28 |
# be reasonable. So gray out the scalebar in these cases. |
and scale > 0.0: |
29 |
if self.map.projection is None: |
|
30 |
BlackPen = wxGREY_PEN |
# We have a projection, draw the scalebar in bw |
31 |
BlackBrush = wxGREY_BRUSH |
BlackPen = wxBLACK_PEN |
32 |
BlackText = wxColor(127,127,127) |
BlackBrush = wxBLACK_BRUSH |
33 |
else: |
BlackText = wxBLACK |
|
BlackPen = wxBLACK_PEN |
|
|
BlackBrush = wxBLACK_BRUSH |
|
|
BlackText = wxBLACK |
|
34 |
|
|
35 |
# Get the dimension |
# Get the dimension |
36 |
width, height = dc.GetSizeTuple() |
width, height = size |
37 |
|
posx, posy = position |
38 |
l1width, l1height = dc.GetTextExtent("%d"%0) |
l1width, l1height = dc.GetTextExtent("%d"%0) |
39 |
|
|
40 |
# 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 |
47 |
interval, unit = deriveInterval(width, scale) |
interval, unit = deriveInterval(width, scale) |
48 |
interval, label = roundInterval(interval) |
interval, label = roundInterval(interval) |
49 |
|
|
50 |
# We draw 2 rectangles with half the width |
if interval > 0.0: |
51 |
if unit == 'km': |
# We draw 2 rectangles with half the width |
52 |
width = int(interval*1000.0*scale/2) |
if unit == 'km': |
53 |
else: |
width = int(interval*1000.0*scale/2) |
54 |
width = int(interval*scale/2) |
else: |
55 |
|
width = int(interval*scale/2) |
56 |
|
|
57 |
dc.SetPen(BlackPen) |
dc.SetPen(BlackPen) |
58 |
|
|
59 |
brush = wxBrush(wxWHITE, wxSOLID) |
brush = wxBrush(wxWHITE, wxSOLID) |
60 |
dc.SetBrush(brush) |
dc.SetBrush(brush) |
61 |
dc.DrawRectangle(4,2,width,8) |
dc.DrawRectangle(posx+4,posy+2,width,8) |
62 |
|
|
63 |
dc.SetBrush(BlackBrush) |
dc.SetBrush(BlackBrush) |
64 |
dc.DrawRectangle(width+4,2,width,8) |
dc.DrawRectangle(posx+width+4,posy+2,width,8) |
65 |
|
|
66 |
dc.SetTextForeground(BlackText) |
dc.SetTextForeground(BlackText) |
67 |
dc.DrawText("%d"%0, 4 - l1width/2, 12) |
dc.DrawText("%d"%0, posx+ 4 - l1width/2, posy+12) |
68 |
|
|
69 |
l2width, l2height = dc.GetTextExtent("%s %s"%(label, unit)) |
l2width, l2height = dc.GetTextExtent("%s %s"%(label, unit)) |
70 |
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) |
71 |
|
|