127 |
def MouseUp(self, event): |
def MouseUp(self, event): |
128 |
if self.dragging: |
if self.dragging: |
129 |
Tool.MouseUp(self, event) |
Tool.MouseUp(self, event) |
130 |
self.view.FitRectToWindow(self.proj_rect()) |
sx, sy = self.start |
131 |
|
cx, cy = self.current |
132 |
|
if sx == cx and sy == cy: |
133 |
|
# Just a mouse click. Simply zoom in by a factor of two |
134 |
|
self.view.ZoomFactor(2, center = (cx, cy)) |
135 |
|
else: |
136 |
|
# A drag. Zoom in to the rectangle |
137 |
|
self.view.FitRectToWindow(self.proj_rect()) |
138 |
|
|
139 |
|
|
140 |
class ZoomOutTool(RectTool): |
class ZoomOutTool(RectTool): |
149 |
Tool.MouseUp(self, event) |
Tool.MouseUp(self, event) |
150 |
sx, sy = self.start |
sx, sy = self.start |
151 |
cx, cy = self.current |
cx, cy = self.current |
152 |
self.view.ZoomOutToRect((min(sx, cx), min(sy, cy), |
if sx == cx and sy == cy: |
153 |
max(sx, cx), max(sy, cy))) |
# Just a mouse click. Simply zoom out by a factor of two |
154 |
|
self.view.ZoomFactor(0.5, center = (cy, cy)) |
155 |
|
else: |
156 |
|
# A drag. Zoom out to the rectangle |
157 |
|
self.view.ZoomOutToRect((min(sx, cx), min(sy, cy), |
158 |
|
max(sx, cx), max(sy, cy))) |
159 |
|
|
160 |
|
|
161 |
class PanTool(Tool): |
class PanTool(Tool): |
263 |
|
|
264 |
def OnPaint(self, event): |
def OnPaint(self, event): |
265 |
dc = wxPaintDC(self) |
dc = wxPaintDC(self) |
266 |
if self.map is None or not self.map.HasLayers(): |
if self.map is not None and self.map.HasLayers(): |
267 |
return |
# We have a non-empty map. Redraw it in idle time |
268 |
self.redraw_on_idle = 1 |
self.redraw_on_idle = 1 |
269 |
|
else: |
270 |
|
# If we've got no map or if the map is empty, simply clear |
271 |
|
# the screen. |
272 |
|
|
273 |
|
# XXX it's probably possible to get rid of this. The |
274 |
|
# background color of the window is already white and the |
275 |
|
# only thing we may have to do is to call self.Refresh() |
276 |
|
# with a true argument in the right places. |
277 |
|
dc.BeginDrawing() |
278 |
|
dc.Clear() |
279 |
|
dc.EndDrawing() |
280 |
|
|
281 |
def do_redraw(self): |
def do_redraw(self): |
282 |
|
# This should only be called if we have a non-empty map. We draw |
283 |
|
# it into a memory DC and then blit it to the screen. |
284 |
width, height = self.GetSizeTuple() |
width, height = self.GetSizeTuple() |
285 |
bitmap = wx.wxEmptyBitmap(width, height) |
bitmap = wx.wxEmptyBitmap(width, height) |
|
|
|
286 |
dc = wx.wxMemoryDC() |
dc = wx.wxMemoryDC() |
287 |
dc.SelectObject(bitmap) |
dc.SelectObject(bitmap) |
|
|
|
288 |
dc.BeginDrawing() |
dc.BeginDrawing() |
289 |
|
|
290 |
|
# clear the background |
291 |
dc.SetBrush(wx.wxWHITE_BRUSH) |
dc.SetBrush(wx.wxWHITE_BRUSH) |
292 |
dc.SetPen(wx.wxTRANSPARENT_PEN) |
dc.SetPen(wx.wxTRANSPARENT_PEN) |
293 |
dc.DrawRectangle(0, 0, width, height) |
dc.DrawRectangle(0, 0, width, height) |
298 |
else: |
else: |
299 |
selected_layer = None |
selected_layer = None |
300 |
selected_shape = None |
selected_shape = None |
301 |
|
|
302 |
|
# draw the map into the bitmap |
303 |
renderer = ScreenRenderer(dc, self.scale, self.offset) |
renderer = ScreenRenderer(dc, self.scale, self.offset) |
304 |
renderer.RenderMap(self.map, selected_layer, selected_shape) |
renderer.RenderMap(self.map, selected_layer, selected_shape) |
305 |
|
|
306 |
|
dc.EndDrawing() |
307 |
|
|
308 |
|
# blit the bitmap to the screen |
309 |
clientdc = wxClientDC(self) |
clientdc = wxClientDC(self) |
310 |
clientdc.BeginDrawing() |
clientdc.BeginDrawing() |
311 |
clientdc.Blit(0, 0, width, height, dc, 0, 0) |
clientdc.Blit(0, 0, width, height, dc, 0, 0) |
312 |
clientdc.EndDrawing() |
clientdc.EndDrawing() |
313 |
|
|
|
|
|
314 |
def Print(self): |
def Print(self): |
315 |
printer = wx.wxPrinter() |
printer = wx.wxPrinter() |
316 |
printout = MapPrintout(self.map) |
printout = MapPrintout(self.map) |
331 |
self.map.Subscribe(channel, self.redraw) |
self.map.Subscribe(channel, self.redraw) |
332 |
self.map.Subscribe(MAP_PROJECTION_CHANGED, self.projection_changed) |
self.map.Subscribe(MAP_PROJECTION_CHANGED, self.projection_changed) |
333 |
self.FitMapToWindow() |
self.FitMapToWindow() |
334 |
|
# force a redraw. If map is not empty, it's already been called |
335 |
|
# by FitMapToWindow but if map is empty it hasn't been called |
336 |
|
# yet so we have to explicitly call it. |
337 |
|
self.redraw() |
338 |
|
|
339 |
def Map(self): |
def Map(self): |
340 |
return self.map |
return self.map |
387 |
if bbox is not None: |
if bbox is not None: |
388 |
self.FitRectToWindow(bbox) |
self.FitRectToWindow(bbox) |
389 |
|
|
390 |
def ZoomFactor(self, factor): |
def ZoomFactor(self, factor, center = None): |
391 |
|
"""Multiply the zoom by factor and center on center. |
392 |
|
|
393 |
|
The optional parameter center is a point in window coordinates |
394 |
|
that should be centered. If it is omitted, it defaults to the |
395 |
|
center of the window |
396 |
|
""" |
397 |
width, height = self.GetSizeTuple() |
width, height = self.GetSizeTuple() |
398 |
scale = self.scale * factor |
scale = self.scale * factor |
399 |
offx, offy = self.offset |
offx, offy = self.offset |
400 |
offset = (factor * (offx - width / 2) + width / 2, |
if center is not None: |
401 |
factor * (offy - height / 2) + height / 2) |
cx, cy = center |
402 |
|
else: |
403 |
|
cx = width / 2 |
404 |
|
cy = height / 2 |
405 |
|
offset = (factor * (offx - cx) + width / 2, |
406 |
|
factor * (offy - cy) + height / 2) |
407 |
self.set_view_transform(scale, offset) |
self.set_view_transform(scale, offset) |
408 |
|
|
409 |
def ZoomOutToRect(self, rect): |
def ZoomOutToRect(self, rect): |