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) |
216 |
index = self.selected_shape |
index = self.selected_shape |
217 |
if shapetype == SHAPETYPE_POLYGON: |
if shapetype == SHAPETYPE_POLYGON: |
218 |
self.draw_polygon_shape(layer, index, pen, brush) |
self.draw_polygon_shape(layer, index, pen, brush) |
219 |
|
elif shapetype == SHAPETYPE_ARC: |
220 |
|
self.draw_polygon_shape(layer, index, pen, None) |
221 |
else: |
else: |
222 |
self.dc.SetBrush(brush) |
self.dc.SetBrush(brush) |
223 |
self.dc.SetPen(pen) |
self.dc.SetPen(pen) |
224 |
if shapetype == SHAPETYPE_ARC: |
if shapetype == SHAPETYPE_POINT: |
225 |
f = self.draw_arc_shape |
self.draw_point_shape(layer, index) |
226 |
elif shapetype == SHAPETYPE_POINT: |
else: |
227 |
f = self.draw_point_shape |
raise TypeError("Unhandled shape type %s" % shapetype) |
228 |
f(layer, index) |
|
229 |
|
def layer_ids(self, layer): |
230 |
|
"""Return the shapeids covered by the region that has to be redrawn |
231 |
|
|
232 |
|
Call the layer's ShapesInRegion method to determine the ids so |
233 |
|
that it can use the quadtree. |
234 |
|
""" |
235 |
|
# FIXME: the quad-tree should be built from the projected |
236 |
|
# coordinates not the lat-long ones because it's not trivial to |
237 |
|
# determine an appropriate rectangle in lat-long for a given |
238 |
|
# rectangle in projected coordinates which we have to start from |
239 |
|
# here. |
240 |
|
proj = self.map.projection |
241 |
|
if proj is not None: |
242 |
|
inverse = proj.Inverse |
243 |
|
else: |
244 |
|
inverse = None |
245 |
|
|
246 |
|
scale = self.scale |
247 |
|
offx, offy = self.offset |
248 |
|
xs = [] |
249 |
|
ys = [] |
250 |
|
x, y, width, height = self.update_region |
251 |
|
for winx, winy in ((x, y), (x + width, y), |
252 |
|
(x + width, y + height), (x, y + height)): |
253 |
|
px = (winx - offx) / scale |
254 |
|
py = -(winy - offy) / scale |
255 |
|
if inverse: |
256 |
|
px, py = inverse(px, py) |
257 |
|
xs.append(px) |
258 |
|
ys.append(py) |
259 |
|
left = min(xs) |
260 |
|
right = max(xs) |
261 |
|
top = max(ys) |
262 |
|
bottom = min(ys) |
263 |
|
|
264 |
|
return layer.ShapesInRegion((left, bottom, right, top)) |
265 |
|
|
266 |
|
|
267 |
class PrinterRender(MapRenderer): |
class PrinterRender(MapRenderer): |