Build a Custom Command and Operation
tip
Geocortex Web has many built-in Commands and Operations which can be chained together to build custom behaviors with. If these commands and operations are not enough to accomplish your goal, you can use Geocortex Workflow to take custom behavior even further without writing custom code. If Workflow is still not enough to accomplish your needs, then it might be time to implement a custom command or operation.
This article will walk you through implementing a custom command in Geocortex Web that can record actions and a custom operation that returns a list of the executed actions.
Prerequisites
- Download and setup the Geocortex Web SDK.
- Check out the deployment instructions to learn more about deploying custom code to a Geocortex Web App.
Create the Backing Service
Every command or operation in Geocortex Web needs to be registered and implemented by a service or component, so the first thing we will do is create a service.
Create a new folder structure with the following files. These files define a new service and export it from the CustomService
folder.
src/services/CustomService/CustomService.ts
src/services/CustomService/index.ts
- Service
- Index
tip
Learn more about implementing custom services
Register the Service with the Web SDK
Every service needs to be registered with the Web SDK in order to be discovered and initialized.
- Add a call to
registerService
insrc/index.ts
.
Register the Command and Operation
Commands and operations are registered in src/index.ts
. The serviceId
of the command or operation registration must match the id
used in the registerService
call.
Implement the Custom Command and Operation
It's now time to implement the command to record an action, and the operation that returns a history of executed actions in the CustomService
. We can define each command and operation with an appropriately named protected
method that is decorated with @command
and @operation
respectively.
Test the Custom Command and Operation
You can test your custom command and operation by adding entries to the I Want to Menu in the app config that run your commands and operation. For more information on customizing your app with commands and operations, see commands and operations.
The following app config and layout adds three entries to an I Want To Menu that run the custom commands and operations implemented in this article. The operation custom-service.get-action-history
has been slightly changed to return an argument that is compatible with the inputs of ui.alert
.
- App Config
- Layout
- Custom Service
- UI
Next Steps
Commands and operations are the logical building blocks of executing custom behavior in Geocortex Web, but sometimes you need to take things a bit further. Creating custom components can allow you to design completely custom UI for Geocortex Web, and creating services can enable shared logic and background tasks.
Commands and Operations in Services
Learn more about commands and operations in services
Implement a Custom Component with UI
Learn how to implement a custom component using the Geocortex Web SDK
Custom Services
Learn more about custom services