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 wxRect in window coordinates) needs to |
201 |
|
be redrawn. Highlight the shape with id selected_shape in the |
202 |
|
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.asTuple() |
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 |
|
|