Coverage for gws-app/gws/plugin/template/map/__init__.py: 0%
38 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 01:37 +0200
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 01:37 +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 pass
18class Props(gws.base.template.Props):
19 pass
22class Object(gws.base.template.Object):
24 def render(self, tri):
25 notify = tri.notify or (lambda *args: None)
26 mp = tri.maps[0]
28 mri = gws.MapRenderInput(
29 backgroundColor=mp.backgroundColor,
30 bbox=mp.bbox,
31 center=mp.center,
32 crs=tri.crs,
33 dpi=tri.dpi,
34 mapSize=self.pageSize,
35 notify=notify,
36 planes=mp.planes,
37 project=tri.project,
38 rotation=mp.rotation,
39 scale=mp.scale,
40 user=tri.user,
41 )
43 notify('begin_print')
44 notify('begin_page')
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('end_page')
52 notify('finalize_print')
54 if not tri.mimeOut or tri.mimeOut == gws.lib.mime.HTML:
55 notify('end_print')
56 return gws.ContentResponse(mime=gws.lib.mime.HTML, content=html)
58 if tri.mimeOut == gws.lib.mime.PDF:
59 res_path = gws.u.printtemp('map.pdf')
60 gws.lib.htmlx.render_to_pdf(
61 html,
62 out_path=res_path,
63 page_size=self.pageSize,
64 )
65 notify('end_print')
66 return gws.ContentResponse(contentPath=res_path)
68 if tri.mimeOut == gws.lib.mime.PNG:
69 res_path = gws.u.printtemp('map.png')
70 gws.lib.htmlx.render_to_png(
71 html,
72 out_path=res_path,
73 page_size=self.pageSize,
74 )
75 notify('end_print')
76 return gws.ContentResponse(contentPath=res_path)
78 raise gws.Error(f'invalid output mime: {tri.mimeOut!r}')