35 |
from wxproj import point_in_polygon_shape, shape_centroid |
from wxproj import point_in_polygon_shape, shape_centroid |
36 |
|
|
37 |
from Thuban.Model.messages import MAP_PROJECTION_CHANGED, \ |
from Thuban.Model.messages import MAP_PROJECTION_CHANGED, \ |
38 |
|
LAYER_PROJECTION_CHANGED, \ |
39 |
MAP_LAYERS_CHANGED, LAYER_CHANGED, LAYER_VISIBILITY_CHANGED |
MAP_LAYERS_CHANGED, LAYER_CHANGED, LAYER_VISIBILITY_CHANGED |
40 |
from Thuban.Model.layer import SHAPETYPE_POLYGON, SHAPETYPE_ARC, \ |
from Thuban.Model.layer import SHAPETYPE_POLYGON, SHAPETYPE_ARC, \ |
41 |
SHAPETYPE_POINT |
SHAPETYPE_POINT |
303 |
# the map displayed in this canvas. Set with SetMap() |
# the map displayed in this canvas. Set with SetMap() |
304 |
self.map = None |
self.map = None |
305 |
|
|
306 |
|
# current map projection. should only differ from map.projection |
307 |
|
# when the map's projection is changing and we need access to the |
308 |
|
# old projection. |
309 |
|
self.current_map_proj = None |
310 |
|
|
311 |
# scale and offset describe the transformation from projected |
# scale and offset describe the transformation from projected |
312 |
# coordinates to window coordinates. |
# coordinates to window coordinates. |
313 |
self.scale = 1.0 |
self.scale = 1.0 |
508 |
for channel in redraw_channels: |
for channel in redraw_channels: |
509 |
self.map.Unsubscribe(channel, self.full_redraw) |
self.map.Unsubscribe(channel, self.full_redraw) |
510 |
self.map.Unsubscribe(MAP_PROJECTION_CHANGED, |
self.map.Unsubscribe(MAP_PROJECTION_CHANGED, |
511 |
self.projection_changed) |
self.map_projection_changed) |
512 |
|
self.map.Unsubscribe(LAYER_PROJECTION_CHANGED, |
513 |
|
self.layer_projection_changed) |
514 |
self.map = map |
self.map = map |
515 |
|
self.current_map_proj = self.map.GetProjection() |
516 |
self.selection.ClearSelection() |
self.selection.ClearSelection() |
517 |
if self.map is not None: |
if self.map is not None: |
518 |
for channel in redraw_channels: |
for channel in redraw_channels: |
519 |
self.map.Subscribe(channel, self.full_redraw) |
self.map.Subscribe(channel, self.full_redraw) |
520 |
self.map.Subscribe(MAP_PROJECTION_CHANGED, self.projection_changed) |
self.map.Subscribe(MAP_PROJECTION_CHANGED, self.map_projection_changed) |
521 |
|
self.map.Subscribe(LAYER_PROJECTION_CHANGED, self.layer_projection_changed) |
522 |
self.FitMapToWindow() |
self.FitMapToWindow() |
523 |
# force a redraw. If map is not empty, it's already been called |
# force a redraw. If map is not empty, it's already been called |
524 |
# by FitMapToWindow but if map is empty it hasn't been called |
# by FitMapToWindow but if map is empty it hasn't been called |
536 |
self.bitmap = None |
self.bitmap = None |
537 |
self.redraw() |
self.redraw() |
538 |
|
|
539 |
def projection_changed(self, *args): |
def map_projection_changed(self, *args): |
540 |
self.FitMapToWindow() |
|
541 |
|
proj = self.current_map_proj |
542 |
|
self.current_map_proj = self.map.GetProjection() |
543 |
|
|
544 |
|
bbox = None |
545 |
|
|
546 |
|
if proj is not None and self.current_map_proj is not None: |
547 |
|
width, height = self.GetSizeTuple() |
548 |
|
llx, lly = self.win_to_proj(0, height) |
549 |
|
urx, ury = self.win_to_proj(width, 0) |
550 |
|
bbox = proj.Inverse(llx, lly) + proj.Inverse(urx, ury) |
551 |
|
bbox = self.current_map_proj.ForwardBBox(bbox) |
552 |
|
|
553 |
|
if bbox is not None: |
554 |
|
self.FitRectToWindow(bbox) |
555 |
|
else: |
556 |
|
self.FitMapToWindow() |
557 |
|
|
558 |
|
self.full_redraw() |
559 |
|
|
560 |
|
def layer_projection_changed(self, *args): |
561 |
self.full_redraw() |
self.full_redraw() |
562 |
|
|
563 |
def set_view_transform(self, scale, offset): |
def set_view_transform(self, scale, offset): |