import Graphic from "@arcgis/core/Graphic"; import GraphicsLayer from "@arcgis/core/layers/GraphicsLayer"; import Point from "@arcgis/core/geometry/Point"; import SimpleMarkerSymbol from "@arcgis/core/symbols/SimpleMarkerSymbol"; import PopupTemplate from "@arcgis/core/PopupTemplate"; import { IActivityHandler } from "@vertigis/workflow"; /** An interface that defines the inputs of the activity. */ interface CreateGraphicLayerInputs { /** * @displayName Graphic * @description the graphic of the point data includeing geometry and attributes and symbol. * @required */ graphics: { geometry: { x: number; y: number; z?: number }; attributes: any; symbol?: SimpleMarkerSymbol; }[]; /** * @displayName Popup Template * @description The popup template for the graphics. */ popupTemplate?: PopupTemplate; /** * @displayName Spatial Reference WKID * @description The Well-Known ID (WKID) of the spatial reference system. */ spatialReferenceWKID: number; } /** An interface that defines the outputs of the activity. */ interface CreateGraphicLayerOutputs { /** * @description The result of the activity. */ result: GraphicsLayer; } function createGraphicsLayer(inputs: CreateGraphicLayerInputs): GraphicsLayer { const { graphics, popupTemplate, spatialReferenceWKID } = inputs; // Create a graphics layer const graphicsLayer = new GraphicsLayer(); // Add graphics based on the provided geometry, symbol, attributes, and popup template graphics.forEach((gr) => { const graphic = new Graphic({ geometry: new Point({ x: gr.geometry.x, y: gr.geometry.y, z: gr.geometry.z, spatialReference: { wkid: spatialReferenceWKID }, }), symbol: gr.symbol !== null ? gr.symbol : undefined, attributes: gr.attributes, popupTemplate: popupTemplate ? new PopupTemplate(popupTemplate) : undefined, }); graphicsLayer.add(graphic); }); return graphicsLayer; } /** * @displayName Create Graphic Layer * @category Geocortex * @description Create Graphic Point Layer v1.1 */ export default class CreateGraphicLayerActivity implements IActivityHandler { /** Perform the execution logic of the activity. */ execute(inputs: CreateGraphicLayerInputs): CreateGraphicLayerOutputs { const graphicsLayer = createGraphicsLayer(inputs); return { result: graphicsLayer, }; } }