gws.base.layer.core

Base layer object and the configuration shared by all layers.

Source code: gws.base.layer.core

Module Contents

class gws.base.layer.core.AutoLayersConfig(*args, **kwargs)

Bases: gws.ConfigWithAccess

Configuration merged into automatically created layers that match a filter.

applyTo: gws.gis.source.LayerFilter | None

Filter for the source layers the configuration applies to.

config: dict

Layer configuration to merge into each matching layer.

class gws.base.layer.core.ClientConfig(*args, **kwargs)

Bases: gws.Data

Display options for the layer in the client layer tree.

exclusive: bool = False

Allow only one child layer to be visible at a time.

expanded: bool = False

Show the layer’s children expanded in the layer tree.

hidden: bool = False

Hide the layer on the map initially.

selected: bool = False

Select the layer in the layer tree initially.

treeClassName = ''

CSS class for the layer’s item in the layer tree.

unfolded: bool = False

Show the layer’s children in the tree instead of the layer itself.

unlisted: bool = False

Hide the layer from the layer tree.

class gws.base.layer.core.ClientOptions(*args, **kwargs)

Bases: gws.Data

Client options for a layer.

exclusive: bool

Only one of this layer children is visible at a time.

expanded: bool

A layer is expanded in the list view.

hidden: bool

A layer is initially hidden.

selected: bool

A layer is initially selected.

treeClassName: str

CSS class name for the layer tree item.

unfolded: bool

A layer is not listed, but its children are.

unlisted: bool

A layer is hidden in the list view.

class gws.base.layer.core.Config(*args, **kwargs)

Bases: gws.ConfigWithAccess

Layer configuration

cache: gws.gis.cache.LayerConfig | None

Tile cache options.

clientOptions: ClientConfig | None

Display options in the client layer tree.

cssSelector: str = ''

CSS selector for styling the layer’s features in the client.

display: gws.LayerDisplayMode

The way the layer is rendered in the client.

extent: gws.Extent | None

Layer extent in map CRS coordinates, clipped to the parent extent.

extentBuffer: int | None

Buffer around the layer extent.

finders: list[gws.ext.config.finder] | None

Search providers for the layer’s features.

grid: dict | None

Ignored. (deprecated in 8.5)

imageFormat: gws.lib.image.FormatConfig | None

Format of rendered and cached images.

legend: gws.ext.config.legend | None

Custom legend or legend options for the layer.

loadingStrategy: gws.FeatureLoadingStrategy

When the client loads the layer’s features.

metadata: gws.base.metadata.Config | None

Layer metadata.

models: list[gws.ext.config.model] | None

Data models for the layer’s features.

opacity: float = 1

Layer opacity, from 0 to 1.

ows: Config.ows | None

Layer names, namespace and allowed services for OWS services.

templates: list[gws.ext.config.template] | None

Templates for the layer’s description and feature info.

title: str = ''

Layer title, shown in the layer tree.

withCache: bool | None = True

Store rendered tiles in the persistent cache. (changed in 8.5)

withLegend: bool | None = True

Show a legend for the layer.

withOws: bool | None = True

Publish the layer in OWS services.

withSearch: bool | None = True

Include the layer in searches.

zoom: gws.gis.zoom.Config | None

Scales or zoom levels at which the layer is visible.

zoomExtent: gws.Extent | None

Extent to zoom to when zooming to the layer.

gws.base.layer.core.DEFAULT_IMAGE_FORMAT
class gws.base.layer.core.Object

Bases: gws.Layer

Base layer.

Provides the attributes common to all layers, the configuration protocol configure_layer, client props and the URLs of the map action commands. Subclasses call configure_layer from their configure method, override the configure_* steps they need and implement render_box, render_tile or render_svg for the outputs they support.

canRenderBox = False

The layer can render a single image for an arbitrary extent.

canRenderInClient = False

The layer can be drawn by the client directly from its source (display: client).

canRenderSvg = False

The layer can render its features as SVG.

canRenderTile = False

The layer can render tiles in a fixed grid.

clientOptions: ClientOptions

Display options for the client layer tree.

hasLegend = False

The layer has a legend.

isEnabledForOws = False

The layer can be used by OWS services.

isGroup = False

The layer is a group of other layers.

isSearchable = False

The layer has at least one search provider.

parent: gws.Layer

Parent layer.

parentResolutions: list[float]

Resolutions of the parent layer or map.

parentWgsExtent: gws.Extent

WGS84 extent of the parent layer or map.

configure()

Configuration hook.

Called when the node is initialized. Raising an exception here aborts the creation of the node.

configure_bounds()

Set bounds in the map CRS.

The bounds are the WGS extent clipped to the parent extent and to the CRS. If the extent lies outside of the parent extent, a configuration warning is issued and the parent extent is used.

Returns:

True.

Raises:

gws.ConfigurationError – If no extent can be determined.

configure_extent()

Set wgsExtent from the configured extent.

Returns:

True if an extent is configured, None otherwise.

Raises:

gws.ConfigurationError – If the configured extent is invalid.

configure_group()

Create child layers. Does nothing in the base class.

Returns:

True if child layers were created, None otherwise.

configure_layer()

Run the layer configuration steps in a fixed order.

The steps are provider, sources, group, models, extent, bounds, zoom bounds, resolutions, legend, metadata, templates, search and OWS.

configure_legend()

Create the legend from the legend configuration.

Returns:

True if a legend is configured or legends are disabled with withLegend, None otherwise.

configure_metadata()

Set metadata from the metadata configuration.

Returns:

True if metadata is configured, None otherwise.

configure_models()

Create the models from the models configuration.

Returns:

True if models are configured, False otherwise.

configure_ows()

Create the OWS binding and set isEnabledForOws from withOws.

The OWS layer and feature names default to the layer title converted to a UID.

configure_provider()

Set up the data provider. Does nothing in the base class.

Returns:

True if a provider was configured, None otherwise.

configure_resolutions()

Set resolutions from the zoom configuration.

Without a zoom configuration the layer keeps the parent resolutions.

Returns:

True if a zoom configuration is present, None otherwise.

Raises:

gws.Error – If the zoom configuration yields no resolutions.

Create the search providers from the finders configuration.

Returns:

True if finders are configured or search is disabled with withSearch, False otherwise.

configure_sources()

Set up the source layers. Does nothing in the base class.

Returns:

True if sources were configured, None otherwise.

configure_templates()

Create the templates from the templates configuration.

Returns:

True if at least one template was created, False otherwise.

configure_zoom_bounds()

Set zoomBounds from the configured zoomExtent.

Returns:

True if a zoom extent is configured, None otherwise.

Raises:

gws.ConfigurationError – If the configured zoom extent is invalid.

find_features(search, user)

Find features in the layer.

Vector layers search in the first model the user can read; other layers return an empty list.

Parameters:
  • search – Search query.

  • user – The user who searches.

Returns:

Found features.

post_configure()

Post-configuration hook.

Called after the whole object tree has been created.

props(user)

Generate a Props struct for this object.

Do not call this method directly, use gws.props_of instead, which also checks permissions.

Parameters:

user – The user for which the props should be generated.

Returns:

A Props object or a dict. Nested objects are converted to props as well.

render(lri)

Render a box, a tile or an SVG fragment, depending on the input type.

Parameters:

lri – Render input.

Returns:

Render output with image content or SVG tags, or None if the layer has nothing to render.

render_box(lri)

Render the layer as a single image. Returns nothing in the base class.

Parameters:

lri – Render input with the map view.

Returns:

Render output with the encoded image, or None.

render_legend(args=None)

Render the layer legend.

Without args the output is cached for the server lifetime.

Parameters:

args – Arguments passed to the legend renderer.

Returns:

Legend output, or None if the layer has no legend.

render_svg(lri)

Render the layer as SVG. Returns nothing in the base class.

Parameters:

lri – Render input with the map view and style.

Returns:

Render output with SVG tags, or None.

render_tile(lri)

Render a single tile. Returns nothing in the base class.

Parameters:

lri – Render input with the tile coordinates.

Returns:

Render output with the encoded tile, or None.

url_path_for(kind)

Return the URL path for requests to this layer.

Parameters:

kind – box, tile, legend or features. The tile path contains {z}, {x} and {y} placeholders.

Returns:

URL path.

Raises:

gws.Error – If kind is not recognized.

class gws.base.layer.core.Props(*args, **kwargs)

Bases: gws.Props

Object properties.

clientOptions: ClientOptions
cssSelector: str
displayMode: str
extent: gws.Extent | None
geometryType: gws.GeometryType | None
grid: gws.lib.grid.Props
layers: list[Props] | None
loadingStrategy: gws.FeatureLoadingStrategy
metadata: gws.base.metadata.Props
model: gws.base.model.Props | None
opacity: float | None
resolutions: list[float] | None
title: str = ''
type: str
uid: str

Unique ID.

url: str = ''
zoomExtent: gws.Extent | None