import gws
import gws.gis.shape
import gws.common.model
import gws.common.template
import gws.tools.units
import gws.types as t
_DEFAULT_PIXEL_TOLERANCE = 10
[docs]class Config(t.WithTypeAndAccess):
dataModel: t.Optional[gws.common.model.Config] #: feature data model
defaultContext: str = '' #: default spatial context ('view' or 'map')
templates: t.Optional[t.List[t.ext.template.Config]] #: feature formatting templates
tolerance: str = '10px' #: tolerance, in pixels or map units
withGeometry: bool = True #: enable geometry search
withKeyword: bool = True #: enable keyword search
CAPS_KEYWORD = 1 << 0
CAPS_GEOMETRY = 1 << 1
CAPS_FILTER = 1 << 2
#:export ISearchProvider
[docs]class Object(gws.Object, t.ISearchProvider):
[docs] def can_run(self, args: t.SearchArgs):
if not self.active:
return False
if args.keyword:
if not (CAPS_KEYWORD & self.capabilties) or not self.with_keyword:
return False
geom = args.bounds or args.shapes
if geom:
if not (CAPS_GEOMETRY & self.capabilties) or not self.with_geometry:
return False
if args.filter:
if not (CAPS_GEOMETRY & self.capabilties):
return False
return bool(args.keyword or geom or args.filter)
[docs] def context_shape(self, args: t.SearchArgs) -> t.IShape:
if args.get('shapes'):
return gws.gis.shape.union(args.shapes)
ctx = self.var('defaultContext')
if ctx == 'view' and args.bounds:
return gws.gis.shape.from_bounds(args.bounds)
return gws.gis.shape.from_bounds(args.project.map.bounds)
[docs] def run(self, layer: t.ILayer, args: t.SearchArgs) -> t.List[t.IFeature]:
return []