MCPcopy Create free account
hub / github.com/OpenOrienteering/mapper / rasterizeMap

Method rasterizeMap

src/tools/fill_tool.cpp:250–317  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

248}
249
250QImage FillTool::rasterizeMap(const QRectF& extent, QTransform& out_transform)
251{
252 // Draw map into a QImage with the following settings:
253 // - specific zoom factor (resolution)
254 // - no antialiasing
255 // - encode object ids in object colors
256 // - draw baselines in advance to normal rendering
257 // This makes it possible to fill areas bounded by e.g. dashed paths.
258
259 constexpr auto zoom_level = qreal(4);
260
261 // Create map view centered on the extent
262 MapView view{ map() };
263 view.setCenter(MapCoord{ extent.center() });
264 view.setZoom(zoom_level);
265
266 // Allocate the image
267 auto image_size = view.calculateViewBoundingBox(extent).toAlignedRect().size();
268 QImage image = QImage(image_size, QImage::Format_RGB32);
269 image.fill(background);
270
271 // Draw map
272 RenderConfig::Options options = RenderConfig::DisableAntialiasing | RenderConfig::ForceMinSize;
273 RenderConfig config = { *map(), extent, view.calculateFinalZoomFactor(), options, 1.0 };
274
275 QPainter painter;
276 painter.begin(&image);
277 painter.translate(image_size.width() / 2.0, image_size.height() / 2.0);
278 painter.setWorldTransform(view.worldTransform(), true);
279
280 auto original_area_hatching = map()->isAreaHatchingEnabled();
281 if (original_area_hatching)
282 {
283 map()->setAreaHatchingEnabled(false);
284 }
285
286 if (!map()->isBaselineViewEnabled())
287 {
288 // Temporarily enable baseline view and draw map once.
289 map()->setBaselineViewEnabled(true);
290 map()->getCurrentPart()->applyOnAllObjects(&Object::forceUpdate);
291 drawObjectIDs(map(), &painter, config);
292 map()->setBaselineViewEnabled(false);
293 map()->getCurrentPart()->applyOnAllObjects(&Object::forceUpdate);
294 }
295 else if (original_area_hatching)
296 {
297 map()->getCurrentPart()->applyOnAllObjects(&Object::forceUpdate);
298 }
299
300 // Draw the map in original mode (but without area hatching)
301 drawObjectIDs(map(), &painter, config);
302
303 if (original_area_hatching)
304 {
305 map()->setAreaHatchingEnabled(original_area_hatching);
306 map()->getCurrentPart()->applyOnAllObjects(&Object::forceUpdate);
307 }

Callers

nothing calls this directly

Calls 15

centerMethod · 0.80
setZoomMethod · 0.80
fillMethod · 0.80
getCurrentPartMethod · 0.80
QImageClass · 0.50
setCenterMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
translateMethod · 0.45
widthMethod · 0.45

Tested by

no test coverage detected