Creates an Action instance.
The returned action must either be an object of type Action
or an instance of a class derived from the class popups/Action
.
Type ID of action to be created.
action instance or undefined, if no Action could be created for this type.
ActionFactory returning a properties object
export class TweetActionFactory implements ActionFactory {
createAction(type: string): Action | undefined {
return {
id: "tweetablePopups.action.tweet",
type: "button",
title: "Tweet Feature",
className: "esri-icon-share2",
trigger(context) {
// Code to be performed, when the action is triggered,
// for example if someone clicks the link that is displayed in the popup.
const features = context.features; // All features that are hit by clicking on the map.
const selectedFeature = context.selectedFeature; // The selected and visible feature in the popup.
const location = context.location; // The point position where the popup is opened on the map.
// Tweet it: for example selectedFeature.attributes.description ...
}
};
}
getTypes(): string[] | Promise<string[]> {
return ["tweet"];
}
}
ActionFactory returning an instance from a class extending popups/Action
export class MyCustomAction extends Action {
trigger(context: ActionContext) {
// Do something when action is clicked
}
}
export class MyCustomActionFactory implements ActionFactory {
getTypes(): string[] | Promise<string[]> {
return ["mycustomaction"];
}
createAction(type: string): Action | undefined {
return new MyCustomAction({
id: type,
title: "customAction"
});
}
}
Factory for creating Actions.