Actions and Services

GeoMoose 3+ supports two different types of tools in the toolbar. In general the two can be described as follows:

Actions

Actions do one thing, they execute the code in the run method when clicked from the toolbar.

Example custom action

alert.js

function AlertAction(Application, config) {
    this.run = function() {
        alert(config.message);
    }
}

The application’s index.html would then need to include alert.js:

<script type="text/javascript" src="alert.js"></script>

And the new action would then need to be registered with the application in the app.js file:

app.registerAction('say-hello', AlertAction, {message: 'Hello, World'});

Finally, the action needs to be linked to a tool in the toolbar. In mapbook.xml, in the <toolbar> section, the following would be added:

<tool type="action" name="say-hello" title="Say Hello"/>

When the application is reloaded, a new toolbar button will appear with the text “Say Hello,” clicking on it will cause the action to execute the code in this.run – alerting the contents of config.message which was set to 'Hello, World'.

Services

Services are more complex. A service is used to collect information from the user and the map then use that information to generate a query. After the query has executed, the results are then rendered into HTML.

Unlike an action, services require defining more members for them to function properly:

The title, tools, and fields definitions will be used to render a set of user inputs when the service is clicked in the toolbar.

Services also have different methods which handle different phases of the query cycle:

Writing a custom query

The default behavior for a service is to query the chosen layer(s) for features. For example, if a layer is on a WFS-type map-source, GeoMoose will dispatch a WFS GetFeatures query with the appropriate filters to get the relevant features back to the user. However, there are time where this functionality is not desired. The example included in GeoMoose’s example desktop application is geocoding. When running a geocode query the user will not query the underlying layers but call a different script which will return features. This requires defining a different runQuery method. E.G.:

function MyCustomService(Application, config) {
  runQuery(queryId, query) {
    // Do some stuff...
  }
}

See src/services/geocode-osm.js for more details.