Custom Actions
Scenario
When configuring widget interaction, you can compile code to customize interaction actions to meet service requirements.

Parameters for Customizing an Action
In custom actions, the following parameters can be directly used:
- eventParam: parameter transferred by the widget.
The following uses the date selector widget as an example to describe how to obtain eventParam.
- On the page, drag a date selector widget to the canvas.
Figure 2 Dragging the date selector to the canvas
- Select the date selector and click
. The interaction setting page is displayed.
- Set the custom action, as shown in the following figure.
When customizing a widget action, add a keyword to associate the widget information.
/* * You can obtain the widget object as shown in the example and compile the JavaScript code. * In the example, widget 16 is hidden after the current event is triggered. * Help document: https://support.huaweicloud.com/intl/en-us/usermanualcanvas-astrozero/astrozero_05_7025.html * Parameters that can be directly used * eventParam: parameter transferred by the widget. * data: interaction action information object. * $pageStore: object for storing global variables on the page. * You can use $pageStore.setItems([{key:'id',value:'123'}]) to update global variables in batches. */ // {widget16}.hideWidget() console.log(eventParam); console.log(data); console.log($pageStore);
- Click
at the top to save the page.
- Click
. On the preview page, set the start time and end time of the date selector.
Figure 4 Preview - After the setting is complete, press F12. On the Console tab page, view eventParam.
Figure 5 eventParam
- On the page, drag a date selector widget to the canvas.
- data: stores the most detailed action information object.
Figure 6 Viewing data
- $pageStore: object for storing global variables on the page.
If a field variable is configured and the default value is 1, you can obtain it by printing $pageStore (as shown in Figure 3) in a custom action.
Figure 7 Defining global variable fieldFigure 8 Viewing $pageStore - $pageStore.setItems([{key:'id',value:'123'}]): updates global variables in batches. Key indicates the global variable name, and value indicates the global variable value.
Figure 9 Global variable
Obtaining and Operating Widget
- Obtain the widget.
- On the Layers tab page, select the date selector widget.
Figure 10 Choosing the date selector widget
- Hover the pointer over the date selector widget. The widget name is the widget ID.
Figure 11 Obtaining the widget ID
- On the Layers tab page, select the date selector widget.
- Perform operations on a widget.
After obtaining the widget ID, you can use the platform's API to display or hide the widget. For details about the APIs, see Built-in APIs.
// Display widget {widget2}.showWidget(); // Hide widget {widget2}.hideWidget();
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot