Coverage for gws-app/gws/plugin/dimension/__init__.py: 0%
24 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-05 13:35 +0200
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-05 13:35 +0200
1"""Dimension tool.
3Client tool for drawing dimension lines on the map. While drawing, the pointer
4snaps to the vertices of the features of the layers given by ``layerUids``,
5within ``pixelTolerance`` screen pixels. Dimensions are listed in a sidebar,
6where they can be labeled and deleted, and are printed with the map. If a
7storage is configured, they can be saved on the server and loaded again.
9This module contains the ``dimension`` action. It passes the snapping settings
10and the storage settings to the client and implements the API command
11``dimensionStorage``, which reads and writes saved dimensions. The client part
12(``Sidebar.Dimension``, ``Toolbar.Dimension``) is in ``js``.
14Example::
16 actions+ {
17 type "dimension"
18 layerUids ["my_wfs_layer"]
19 pixelTolerance 10
20 storage {
21 permissions {
22 read "allow all"
23 write "allow all"
24 create "allow all"
25 }
26 }
27 }
29 client.addElements+ { tag "Sidebar.Dimension" }
30 client.addElements+ { tag "Toolbar.Dimension" }
31"""
33from typing import Optional
35import gws
36import gws.base.action
37import gws.base.storage
40@gws.ext.config.action('dimension')
41class Config(gws.base.action.Config):
42 """Tool for drawing dimensions on the map."""
44 layerUids: Optional[list[str]]
45 """UIDs of layers to snap to."""
46 pixelTolerance: int = 10
47 """Snapping distance in screen pixels."""
48 storage: Optional[gws.base.storage.Config]
49 """Storage for saved dimensions."""
52@gws.ext.props.action('dimension')
53class Props(gws.base.action.Props):
54 layerUids: Optional[list[str]]
55 pixelTolerance: int
56 storage: gws.base.storage.Props
59@gws.ext.object.action('dimension')
60class Object(gws.base.action.Object):
61 """Dimension action."""
63 storage: Optional[gws.base.storage.Object]
64 """Storage for saved dimensions, or ``None`` if not configured."""
66 def configure(self):
67 self.storage = self.create_child_if_configured(
68 gws.base.storage.Object, self.cfg('storage'), categoryName='Dimension')
70 def props(self, user):
71 return gws.u.merge(
72 super().props(user),
73 layerUids=self.cfg('layerUids') or [],
74 pixelTolerance=self.cfg('pixelTolerance'),
75 storage=self.storage,
76 )
78 @gws.ext.command.api('dimensionStorage')
79 def handle_storage(self, req: gws.WebRequester, p: gws.base.storage.Request) -> gws.base.storage.Response:
80 """Read or write saved dimensions."""
81 if not self.storage:
82 raise gws.NotFoundError()
83 return self.storage.handle_request(req, p)