1 |
# Copyright (c) 2001 by Intevation GmbH |
# Copyright (c) 2001, 2002 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Bernhard Herzog <[email protected]> |
# Bernhard Herzog <[email protected]> |
4 |
# |
# |
72 |
fill.blue * 255) |
fill.blue * 255) |
73 |
brush = wxBrush(color, wxSOLID) |
brush = wxBrush(color, wxSOLID) |
74 |
stroke = layer.stroke |
stroke = layer.stroke |
75 |
|
stroke_width = layer.stroke_width |
76 |
if stroke is None: |
if stroke is None: |
77 |
pen = wxTRANSPARENT_PEN |
pen = wxTRANSPARENT_PEN |
78 |
else: |
else: |
79 |
color = wxColour(stroke.red * 255, |
color = wxColour(stroke.red * 255, |
80 |
stroke.green * 255, |
stroke.green * 255, |
81 |
stroke.blue * 255) |
stroke.blue * 255) |
82 |
pen = wxPen(color, 1, wxSOLID) |
pen = wxPen(color, stroke_width, wxSOLID) |
83 |
|
|
84 |
map_proj = self.map.projection |
map_proj = self.map.projection |
85 |
layer_proj = layer.projection |
layer_proj = layer.projection |
87 |
shapetype = layer.ShapeType() |
shapetype = layer.ShapeType() |
88 |
|
|
89 |
if shapetype == SHAPETYPE_POLYGON: |
if shapetype == SHAPETYPE_POLYGON: |
90 |
for i in range(layer.NumShapes()): |
for i in self.layer_ids(layer): |
91 |
self.draw_polygon_shape(layer, i, pen, brush) |
self.draw_polygon_shape(layer, i, pen, brush) |
92 |
|
elif shapetype == SHAPETYPE_ARC: |
93 |
|
for i in self.layer_ids(layer): |
94 |
|
self.draw_polygon_shape(layer, i, pen, None) |
95 |
else: |
else: |
96 |
self.dc.SetBrush(brush) |
self.dc.SetBrush(brush) |
97 |
self.dc.SetPen(pen) |
self.dc.SetPen(pen) |
99 |
f = self.draw_arc_shape |
f = self.draw_arc_shape |
100 |
elif shapetype == SHAPETYPE_POINT: |
elif shapetype == SHAPETYPE_POINT: |
101 |
f = self.draw_point_shape |
f = self.draw_point_shape |
102 |
for i in range(layer.NumShapes()): |
for i in self.layer_ids(layer): |
103 |
f(layer, i) |
f(layer, i) |
104 |
|
|
105 |
|
def layer_ids(self, layer): |
106 |
|
"""Return the shape ids of the given layer that have to be drawn. |
107 |
|
|
108 |
|
The default implementation simply returns all ids in the layer. |
109 |
|
Override in derived classes to be more precise. |
110 |
|
""" |
111 |
|
return range(layer.NumShapes()) |
112 |
|
|
113 |
def draw_polygon_shape(self, layer, index, pen, brush): |
def draw_polygon_shape(self, layer, index, pen, brush): |
114 |
offx, offy = self.offset |
offx, offy = self.offset |
115 |
draw_polygon_shape(layer.shapefile.cobject(), index, |
draw_polygon_shape(layer.shapefile.cobject(), index, |
194 |
# On the screen we want to see only visible layers by default |
# On the screen we want to see only visible layers by default |
195 |
honor_visibility = 1 |
honor_visibility = 1 |
196 |
|
|
197 |
def RenderMap(self, map, selected_layer, selected_shape): |
def RenderMap(self, map, region, selected_layer, selected_shape): |
198 |
|
"""Render the map. |
199 |
|
|
200 |
|
Only the given region (a tuple in window coordinates as returned |
201 |
|
by a wxrect's asTuple method) needs to be redrawn. Highlight the |
202 |
|
shape with id selected_shape in the selected_layer. |
203 |
|
""" |
204 |
|
self.update_region = region |
205 |
self.selected_layer = selected_layer |
self.selected_layer = selected_layer |
206 |
self.selected_shape = selected_shape |
self.selected_shape = selected_shape |
207 |
self.render_map(map) |
self.render_map(map) |
225 |
f = self.draw_point_shape |
f = self.draw_point_shape |
226 |
f(layer, index) |
f(layer, index) |
227 |
|
|
228 |
|
def layer_ids(self, layer): |
229 |
|
"""Return the shapeids covered by the region that has to be redrawn |
230 |
|
|
231 |
|
Call the layer's ShapesInRegion method to determine the ids so |
232 |
|
that it can use the quadtree. |
233 |
|
""" |
234 |
|
# FIXME: the quad-tree should be built from the projected |
235 |
|
# coordinates not the lat-long ones because it's not trivial to |
236 |
|
# determine an appropriate rectangle in lat-long for a given |
237 |
|
# rectangle in projected coordinates which we have to start from |
238 |
|
# here. |
239 |
|
proj = self.map.projection |
240 |
|
if proj is not None: |
241 |
|
inverse = proj.Inverse |
242 |
|
else: |
243 |
|
inverse = None |
244 |
|
|
245 |
|
scale = self.scale |
246 |
|
offx, offy = self.offset |
247 |
|
xs = [] |
248 |
|
ys = [] |
249 |
|
x, y, width, height = self.update_region |
250 |
|
for winx, winy in ((x, y), (x + width, y), |
251 |
|
(x + width, y + height), (x, y + height)): |
252 |
|
px = (winx - offx) / scale |
253 |
|
py = -(winy - offy) / scale |
254 |
|
if inverse: |
255 |
|
px, py = inverse(px, py) |
256 |
|
xs.append(px) |
257 |
|
ys.append(py) |
258 |
|
left = min(xs) |
259 |
|
right = max(xs) |
260 |
|
top = max(ys) |
261 |
|
bottom = min(ys) |
262 |
|
|
263 |
|
return layer.ShapesInRegion((left, bottom, right, top)) |
264 |
|
|
265 |
|
|
266 |
class PrinterRender(MapRenderer): |
class PrinterRender(MapRenderer): |
267 |
|
|