Script reference for App Engine
Everything a script in the App Engine can use without further setup: the map, queries, workflows, files, messages between panels, forms and tables.
POSTED: | UPDATED: | by Stefan Schüttenkopf
A browser app consists of panels that you arrange in the App Engine. A panel can carry a script written in TypeScript. This page lists what such a script can use. It describes version 17.2.
Where a script runs
| Panel | Script | Available in the script |
|---|---|---|
| Map View | yes | Everything on this page, including the map |
| Custom panel | yes, together with its own HTML and CSS | Everything except the map |
| Recipes | yes | Everything except the map |
| Dashboard | no. A dashboard has scripts of its own in its widgets. | – |
| Workflow | no | – |
The editor offers the same suggestions in every panel. A suggestion for window.map in a custom panel does not mean that the map exists there: in a custom panel window.map is undefined.
Names you can use directly
These names exist in every script. You do not import them.
| Name | What it does | Section |
|---|---|---|
window.map | The map of the panel. Map View only. | The map |
executeQuery | Runs a query that was defined in Studio. | Queries |
openWorkflow | Opens a workflow in a new window. | Workflows |
getWarehouseFilePublicgetWarehouseFilePrivate | Load a file that you placed on the server. | Files from the server |
ready, post, listen, listenTo | Messages between the panels of the app. | Messages between panels |
FormInstance, TableInstanceQuickSearchAction, FilterAction, SettingsAction | Forms and tables. New in 17.2. | Forms and tables |
addPointCloudClassificationStyle | Defines the classes and colors of a point cloud layer. | Point clouds |
performQuery | Deprecated. Use executeQuery. | Queries |
Do not declare a function or a constant of your own with one of these names at the top level of your script. The script then fails to start.
Imports
A script can import from LuciadRIA, the map library of the browser app:
import * as ShapeFactory from '@luciad/ria/shape/ShapeFactory';
import { WebGLMap } from '@luciad/ria/view/WebGLMap';
Other imports do not work:
- Imports from
@mui/material,reactor other packages make the script fail. JSX does not work either. - An import that is only used as a type is harmless, because types are removed before the script runs.
To use another library, load it at run time with a script element. The editor has the snippet Load an external library for this.
The map
In the script of a Map View, window.map is the LuciadRIA map (WebGLMap) with everything LuciadRIA offers: layers, camera, selection, events. In addition it has the object stores with functions of the browser app. The editor has no suggestions for stores.
| Call | What it does |
|---|---|
stores.sidebarMenu.addMenuItem(item, openOnAdd) | Adds a tab with a panel, or a plain button, to the menu of the app. See below. |
stores.overlays.addModelessOverlay(options) | Opens a floating window on the map. |
stores.overlays.showModalOverlay(options) | Opens a window that blocks the app until it is closed. Only one at a time. |
stores.mapState.notificationHandler.displayNotification(options) | Shows a notification. |
stores.copyright.addCopyright(text) | Adds a line to the copyright note of the map. |
stores.navigation | Limits for zoom, rotation and tilt. See the snippet Define navigation restrictions. |
A tab in the menu
const panelRoot = document.createElement('div');
panelRoot.textContent = 'Hello';
const tab = window.map.stores.sidebarMenu.addMenuItem({
id: 'example-panel',
icon: {
svgIcon: { path: 'M4 4h16v16H4z', viewWidth: 24, viewHeight: 24 },
tooltip: 'Example'
},
panel: { domContent: panelRoot, title: 'Example' }
}, true);
| Property | Meaning |
|---|---|
id | Optional. An id is generated if you leave it out. |
icon.svgIcon | An SVG path with the size of its view box. Instead you can pass icon.hrefIcon with the address of an image in href. |
icon.tooltip | Text shown when the pointer is on the icon. |
panel.domContent | A div element with the content of the panel. |
panel.title | Title in the header of the panel. |
panel.hideHeader, panel.userRemovable, panel.unmountOnClose | Hide the header, show a close button in the header, remove the content from the page while the panel is closed. |
onClick | Called when the user clicks the icon. An item without panel is a plain button. |
bottomTab | true places the item in the lower group of the menu. |
The second argument true opens the new tab at once. The call returns a handle with open(), close(), remove(), setLoading(value), disableIcon(), enableIcon(), hideIcon() and showIcon(). There is no function to change an item: remove it and add it again.
A notification
window.map.stores.mapState.notificationHandler.displayNotification({
message: "Test Notification <br /><br /> Second Line",
severity: 'info', // 'success' | 'info' | 'warning' | 'error',
position: {
vertical: 'top', // 'top' | 'bottom'
horizontal: 'right' // 'left' | 'center' | 'right'
},
duration: 10000
});
duration is given in milliseconds. Without it the notification stays for six seconds.
Queries
executeQuery runs a query that an administrator defined in Studio and returns its result. You pass the name of the query and a request:
const queryName = 'Query_Name';
const queryRequest: QueryJsonRequest = {
format: 'json',
parameters: {},
srid: 3857
}
executeQuery(queryName, queryRequest).then(result => {
console.log(result)
});
| Property of the request | Meaning |
|---|---|
format | 'json', 'geoJson' or 'csv' |
parameters | Values for the placeholders of the query, by name. Pass {} if the query has none. |
srid | EPSG code into which the geometries are transformed, or null. |
| Format | Result |
|---|---|
'json' | { rowCount, rows }, with one object per row |
'geoJson' | A GeoJSON FeatureCollection |
'csv' | The result as text |
See Query execution for Browser Apps for a complete example and Queries for how to define a query.
performQuery, which sends SQL text from the script, is deprecated. The server rejects it unless Enable deprecated SQL query is switched on in the settings in Management.
Workflows
const name = 'EditBuildingsWF';
const nodeId = 'EditBuildingForm';
const id = '344273';
openWorkflow(name, nodeId, id);
| Argument | Meaning |
|---|---|
workflowName | Name of the workflow |
nodeId | The node of the workflow to open |
id | Optional. The id of a record, for example of the feature to edit. |
windowOptions | Optional. Size and position of the window, in the form the browser function window.open expects. Default: 'width=700,height=600'. |
The workflow opens in a new browser window. The current state of the map, such as the selection, is not passed to a workflow opened this way. To open a workflow with the map state, use an action set.
Files from the server
A script can load files that an administrator placed in the warehouse folder of the server: configuration, lookup lists, small data files.
| Function | Reads from | Who can read it |
|---|---|---|
getWarehouseFilePublic(fileName) | <warehouse>\_public | Anyone who can reach the server, without a login. Subfolders are allowed. |
getWarehouseFilePrivate(fileName) | <warehouse>\<tenant>\_public | Users who are logged in to this tenant. No subfolders. |
Both functions return a promise. getWarehouseFilePublic resolves to the response of the request; read it with text(), json() or blob():
const response = await getWarehouseFilePublic('settings.json');
const settings = await response.json();
A file that does not exist rejects the promise.
For the administrator:
- The two folders do not exist after the installation. Create them and copy the files into them. There is no upload in Studio.
- Do not put anything confidential into the folder
_publicat the top of the warehouse. Its files can be read without a login. - The folders are not part of a tenant export. Include them in your backup.
Messages between panels
The scripts of the panels of one app can send each other messages. A panel is addressed by its title in the App Engine.
| Function | Meaning |
|---|---|
ready(callback) | Calls callback when all panels that have a script are loaded. |
post(payload, to?) | Sends payload to the panel with the title to. Without to, to all other panels. The payload can be any value, also a function. |
listen((from, payload) => { ... }) | Receives the messages of all panels. from is the title of the sender. |
listenTo(from, (payload) => { ... }) | Receives only the messages of the panel with the title from. |
In the receiving panel:
listen((from: string, message: any) => {
console.log(`Message received from ${from}: ${message}`);
})
In the sending panel:
ready(() => {
post('Hi there!');
});
Only panels with a script take part. A dashboard panel or a workflow panel cannot send or receive messages this way.
Forms and tables
FormInstance.create(parent, config) and TableInstance.create(parent, config) build a form or a table inside an HTML element of your panel. Both return an object with destroy() and further functions. They are described on their own pages:
- Form configuration in AppEngine
- Form field reference for App Engine
- Table configuration in AppEngine
- Form and Table UI configuration for App Engine
Point clouds
addPointCloudClassificationStyle(layerId, attributeList) defines, for a point cloud layer, which classes the user can switch on and off and in which color they are drawn. For each attribute you pass a list of entries with label, color and, optionally, visible. See Integration of PEGASUS Data.
Snippets in the editor
The editor of the App Engine comes with 43 snippets that you drag into your script. They are the quickest way to a working start:
| Group | Examples |
|---|---|
| Map | Pan to point, Pan to bounds, Zoom in/out, Add a copyright notice, Define navigation restrictions |
| Layer | Find layer by label, Show/hide layer, Add custom tooltip, Create WMS layer |
| Vector | Add event handler for SelectionChanged event, Create a custom painter |
| Transformations | Point transformation, Bounds transformation, Register a custom coordinate system |
| Point Cloud | Point Cloud Styling, Point Cloud Classification |
| Communication | The message functions described above |
| MAE Interface | Open a workflow, Show a notification, Execute Query, Load an external library, Show mouse location, Address search, Change selection style |
| Recipes | Listen for process start, Listen for process finish, Get process outputs |
| Utility, Markup, Style | Load external libraries, a simple header for a custom panel and its style |
A snippet marked as map script only works in the script of a Map View.