Coverage for gws-app/gws/plugin/template/map/__init__.py: 0%
36 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-16 23:09 +0200
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-16 23:09 +0200
1"""Map-only template"""
3import re
5import gws
6import gws.base.template
7import gws.lib.htmlx
8import gws.lib.mime
9import gws.gis.render
11gws.ext.new.template('map')
14class Config(gws.base.template.Config):
15 """Map-only template."""
16 pass
19class Props(gws.base.template.Props):
20 pass
23class Object(gws.base.template.Object):
25 def render(self, tri):
26 notify = tri.notify or (lambda *args: None)
27 mp = tri.maps[0]
29 mri = gws.MapRenderInput(
30 backgroundColor=mp.backgroundColor,
31 bbox=mp.bbox,
32 center=mp.center,
33 crs=tri.crs,
34 dpi=tri.dpi,
35 mapSize=self.pageSize,
36 notify=notify,
37 planes=mp.planes,
38 project=tri.project,
39 rotation=mp.rotation,
40 scale=mp.scale,
41 user=tri.user,
42 )
44 notify('begin_print')
45 notify('begin_map')
47 mro = gws.gis.render.render_map(mri)
48 html = gws.gis.render.output_to_html_string(mro, wrap='fixed')
50 notify('end_map')
51 notify('finalize_print')
53 if not tri.mimeOut or tri.mimeOut == gws.lib.mime.HTML:
54 notify('end_print')
55 return gws.ContentResponse(mime=gws.lib.mime.HTML, content=html)
57 if tri.mimeOut == gws.lib.mime.PDF:
58 res_path = gws.u.ephemeral_path('map.pdf')
59 gws.lib.htmlx.render_to_pdf(
60 html,
61 out_path=res_path,
62 page_size=self.pageSize,
63 )
64 notify('end_print')
65 return gws.ContentResponse(contentPath=res_path)
67 if tri.mimeOut == gws.lib.mime.PNG:
68 res_path = gws.u.ephemeral_path('map.png')
69 gws.lib.htmlx.render_to_png(
70 html,
71 out_path=res_path,
72 page_size=self.pageSize,
73 )
74 notify('end_print')
75 return gws.ContentResponse(contentPath=res_path)
77 raise gws.Error(f'invalid output mime: {tri.mimeOut!r}')