# RPC Functions

Functions from the SDK can be invoked via `rpc.invoke()`.

## Example usage

```ts
import { rpc } from '@gi-nx/iframe-sdk';

// Invoke a function
rpc.invoke('setTiles', [sourceId, newTiles]);

// With await
const result = await rpc.invoke('getProjects', []);
```

## Map & Navigation

| Function | Description |
|----------|-------------|
| [addHtmlPopup](/build/functions/addHtmlPopup) | **Needs Permission** - Add an HTML popup to the map at a specific location. |
| [addIframePopup](/build/functions/addIframePopup) | **Needs Permission** - LngLatLike and PopupOptions are mapbox gl types |
| [clearSDKPopup](/build/functions/clearSDKPopup) | Clear/remove the current SDK popup from the map. |
| [disableMapCamera](/build/functions/disableMapCamera) | if called, the map camera will no longer be dispatched to the SDK app. |
| [enableMapCamera](/build/functions/enableMapCamera) | if called, the map camera will be dispatched to the SDK app on every map move and can be accessed via the state key `mapCamera`. |
| [fitBounds](/build/functions/fitBounds) | Fit the map view to contain the specified bounds. |
| [flyTo](/build/functions/flyTo) | Animate the map camera to fly to a location. |
| [getFeatureState](/build/functions/getFeatureState) | Get the current state of a Mapbox GL feature. |
| [getMapBounds](/build/functions/getMapBounds) | Get the current map bounds as a GeoJSON FeatureCollection. |
| [getMapboxLayerIdsForLayer](/build/functions/getMapboxLayerIdsForLayer) | Resolve a layer name or full layer id to the list of mapbox style layer ids currently rendered for it on the map. |
| [getMapCamera](/build/functions/getMapCamera) | Where the map is looking, in the terms an app already thinks in: a ground point, a scale in metres per pixel, and two angles. |
| [getMapStyle](/build/functions/getMapStyle) | Get the current Mapbox style object. |
| [getQueriedFeature](/build/functions/getQueriedFeature) | Get the feature currently under the user's mouse cursor (hovered) or last clicked. |
| [getSelectedFeatures](/build/functions/getSelectedFeatures) | Returns the (raw) Giraffe features that are currently selected |
| [loadImage](/build/functions/loadImage) | Load an image from a URL to mapbox, the key of which can be further referenced by styles. |
| [queryRenderedFeatures](/build/functions/queryRenderedFeatures) | base on https://docs.mapbox.com/mapbox-gl-js/api/map/#map#queryrenderedfeatures |
| [removeFeatureState](/build/functions/removeFeatureState) | **Needs Permission** - Remove previously set state from a Mapbox GL feature. |
| [setDrawTool](/build/functions/setDrawTool) | Set the active drawing tool for map interactions. |
| [setFeatureState](/build/functions/setFeatureState) | **Needs Permission** - Set arbitrary state on a Mapbox GL feature. |
| [setHighlightedFeatures](/build/functions/setHighlightedFeatures) | Set the highlighted features on the map. |
| [setMapCamera](/build/functions/setMapCamera) | Move the map, and take back where it landed. |
| [setSelectedFeatures](/build/functions/setSelectedFeatures) | Set the selected features by their IDs. |

## Layers

| Function | Description |
|----------|-------------|
| [activateDrawingLayer](/build/functions/activateDrawingLayer) | **Needs Permission** - The active drawing layer is the layer that any new geometry will be added to. |
| [activateLensLayer](/build/functions/activateLensLayer) | **Needs Permission** - Activate the lens for a layer. |
| [addLayerToProject](/build/functions/addLayerToProject) | **Needs Permission** - Add the layer to the project. |
| [addTempLayer](/build/functions/addTempLayer) | **Needs Permission** - add (or update the style of) a temporary (exists only for the current session/client) layer with a tiled source NB the source cannot be updated once the layer has been added, but the style can. |
| [addTempLayerGeoJSON](/build/functions/addTempLayerGeoJSON) | add a temporary (exists only for the current session/client) layer with GeoJSON data source |
| [createDrawingLayer](/build/functions/createDrawingLayer) | **Needs Permission** - Creates a new drawing layer with the given name. |
| [createGeoJSONLayer](/build/functions/createGeoJSONLayer) | **Needs Permission** - Create a new GeoJSON layer from the provided data. |
| [createLayer](/build/functions/createLayer) | **Needs Permission** - Create a layer with full configuration options. |
| [deactivateLensLayer](/build/functions/deactivateLensLayer) | **Needs Permission** - Close the lens panel and deselect the current lens layer. |
| [deleteDrawingLayer](/build/functions/deleteDrawingLayer) | **Needs Permission** - Deletes a drawing layer and all associated sections. |
| [deleteProjectLayer](/build/functions/deleteProjectLayer) | **Needs Permission** - Removes a layer from the project |
| [duplicateDrawingLayer](/build/functions/duplicateDrawingLayer) | **Needs Permission** - Duplicates a drawing layer and its associated sections. |
| [getLayerContents](/build/functions/getLayerContents) | Get the layer contents filtered by lens and extent of the provided bounds. |
| [getLayerPermission](/build/functions/getLayerPermission) | Get the current user's permission for a layer (layer must be added to the current project). |
| [removeLayerFromProject](/build/functions/removeLayerFromProject) | **Needs Permission** - Removes a layer from the project |
| [removeLayers](/build/functions/removeLayers) | **Needs Permission** - Delete drawing and project layers. |
| [removeTempLayer](/build/functions/removeTempLayer) | Remove a temporary layer from the map. |
| [renameDrawingLayer](/build/functions/renameDrawingLayer) | **Needs Permission** - Renames an existing drawing layer and updates all associated sections and analytics references. |
| [resetLayerLens](/build/functions/resetLayerLens) | **Needs Permission** - Clear the saved lens (style, filters and property definitions) from a layer |
| [setDrawingLayerLocked](/build/functions/setDrawingLayerLocked) | **Needs Permission** - Locks or unlocks an existing drawing layer Like visibility and opacity, this applies to the session and is written to the backend when the layer tree is next saved. |
| [setLayerStyleByLens](/build/functions/setLayerStyleByLens) | **Needs Permission** - Choose whether a layer draws itself from its saved lens or from its own style. |
| [setTiles](/build/functions/setTiles) | **Needs Permission** - Can be used by an app to override the source of a vector tile layer |
| [updateGeoJSONLayerContents](/build/functions/updateGeoJSONLayerContents) | **Needs Permission** - Utility wrapper this uploads the geojson fc then calls patchLayer if layerName exists, otherwise createLayer then addProjectLayer. |
| [updateLayer](/build/functions/updateLayer) | **Needs Permission** - Update a layer's configuration (excluding vector source). |
| [updateLayerStyle](/build/functions/updateLayerStyle) | **Needs Permission** - Update the style of a layer. |
| [updateTempLayerGeoJSON](/build/functions/updateTempLayerGeoJSON) | update temporary layer data |

## Layer Tree

| Function | Description |
|----------|-------------|
| [activateViewLayers](/build/functions/activateViewLayers) | **Needs Permission** - Activate the layers of a view's layerTree and updates the sun position. |
| [changeLayerOpacity](/build/functions/changeLayerOpacity) | **Needs Permission** - Change the opacity of a layer. |
| [changeLayerVisibility](/build/functions/changeLayerVisibility) | **Needs Permission** - Change the visibility of a layer. |
| [createLayerGroup](/build/functions/createLayerGroup) | **Needs Permission** - Create an empty group in the layer tree. |
| [moveLayerTreeItemIntoGroup](/build/functions/moveLayerTreeItemIntoGroup) | **Needs Permission** - Move an item into a group. |
| [removeLayerGroup](/build/functions/removeLayerGroup) | **Needs Permission** - Remove a group from the layer tree. |
| [renameLayerGroup](/build/functions/renameLayerGroup) | **Needs Permission** - Rename a group in the layer tree |
| [reorderLayerTreeItem](/build/functions/reorderLayerTreeItem) | **Needs Permission** - Reorder any layer tree item or group. |
| [setLayerGroupExpanded](/build/functions/setLayerGroupExpanded) | **Needs Permission** - Expand or collapse a group in the layer tree |
| [updateLayerTreeVisibility](/build/functions/updateLayerTreeVisibility) | **Needs Permission** - Apply the visibility, opacity and (for groups) `enabled` state of a layerTree to the map. |

## Commands

| Function | Description |
|----------|-------------|
| [getLensedFeatureMap](/build/functions/getLensedFeatureMap) | Get all features from the currently active lens layer as a Map. |

## Blocks

| Function | Description |
|----------|-------------|
| [createBlock](/build/functions/createBlock) | **Needs Permission** - Adds a new block definition to the project |
| [deleteBlock](/build/functions/deleteBlock) | **Needs Permission** - Removes a block definition from the project. |
| [getBlock](/build/functions/getBlock) | Returns the block definition for the given id, or undefined if not found. |
| [getBlocks](/build/functions/getBlocks) | Returns all block definitions, keyed by id. |
| [insertBlock](/build/functions/insertBlock) | **Needs Permission** - Prompts the user to click the map to place an instance of a block. |
| [updateBlock](/build/functions/updateBlock) | **Needs Permission** - Updates an existing block definition by merging the provided fields. |

## Flows

| Function | Description |
|----------|-------------|
| [addFlow](/build/functions/addFlow) | **Needs Permission** - Adds a flow to the project. |
| [deleteFlow](/build/functions/deleteFlow) | **Needs Permission** - Removes a flow from the project. |
| [getNode](/build/functions/getNode) | Returns the registered node definition for a given node instance id. |
| [getParameterNode](/build/functions/getParameterNode) | Returns the parameter node associated with a generative transform node type. |
| [getParameterNodeDefaultTransform](/build/functions/getParameterNodeDefaultTransform) | Returns the default transform object for a given generative transform node type. |
| [getProjectFlows](/build/functions/getProjectFlows) | Returns all flows in the current project, keyed by their id. |
| NodeIds | Node ID constants for use with flow functions. |
| [updateFlows](/build/functions/updateFlows) | **Needs Permission** - Updates flows by id. |

## Content Packs

| Function | Description |
|----------|-------------|
| [addContentPackToProject](/build/functions/addContentPackToProject) | **Needs Permission** - Fetches the content pack specified by `id` and imports everything in it into the current project. |
| [fetchContentPacks](/build/functions/fetchContentPacks) | Fetches all available content packs from the server. |
| [fetchPackContents](/build/functions/fetchPackContents) | Fetches the contents of a specific content pack by its URL or file ID. |

## Engine

| Function | Description |
|----------|-------------|
| [evaluateFeatures](/build/functions/evaluateFeatures) | Evaluates a set of raw sections against the current project state, producing pre-stacked sections keyed by feature ID. |
| [stackFeatures](/build/functions/stackFeatures) | Resolves stacking for pre-stacked sections. |

## Scenarios

| Function | Description |
|----------|-------------|
| [activateScenario](/build/functions/activateScenario) | Activate a scenario, making it the current working scenario. |
| [deleteScenario](/build/functions/deleteScenario) | **Needs Permission** - Delete a scenario from the project. |
| [duplicateScenario](/build/functions/duplicateScenario) | **Needs Permission** - Duplicate a scenario, creating a copy with all its features. |
| [getScenarioFeatures](/build/functions/getScenarioFeatures) | Get all features belonging to a specific scenario. |
| [getScenarios](/build/functions/getScenarios) | Retrieves all scenarios for the current project. |
| [getVisibleScenarios](/build/functions/getVisibleScenarios) | Gets the currently visible scenarios. |
| [renameScenario](/build/functions/renameScenario) | **Needs Permission** - Renames a scenario. |
| [setScenarioVisibility](/build/functions/setScenarioVisibility) | Sets the visibility of scenarios. |
| [soloScenario](/build/functions/soloScenario) |  |

## Panels

| Function | Description |
|----------|-------------|
| [closeAppPanel](/build/functions/closeAppPanel) | Close a panel this app opened, or all of them. |
| [getAppPanels](/build/functions/getAppPanels) | Where every panel this app has open currently sits, and whether the user can see it. |
| [openAppPanel](/build/functions/openAppPanel) | Open a second view of the calling app in its own panel, anchored to an existing panel. |

## Project

| Function | Description |
|----------|-------------|
| [createProjectAttachmentPrompt](/build/functions/createProjectAttachmentPrompt) | Open a file picker dialog for the user to upload a new project attachment. |
| [createRawSection](/build/functions/createRawSection) | **Needs Permission** - create a Point, LineString or Polygon geometry that will be saved on Giraffe and that users can edit. |
| [createRawSections](/build/functions/createRawSections) | **Needs Permission** - Bulk method of createRawSection. |
| [deleteRawSection](/build/functions/deleteRawSection) | **Needs Permission** - Delete a raw section from the project. |
| [deleteRawSections](/build/functions/deleteRawSections) | **Needs Permission** - Delete multiple raw sections from the project. |
| [fetchAppCredentials](/build/functions/fetchAppCredentials) | Fetch credentials for an app. |
| [fetchCredentials](/build/functions/fetchCredentials) | Fetch credentials that both the current user and the current app have access to. |
| [importRawSections](/build/variables/importRawSections) | **Needs Permission** - Import RawSections into the current project, with options for usages, flows, etc. |
| [openProject](/build/functions/openProject) | Open a project in a new browser tab. |
| [selectProjectAttachmentPrompt](/build/functions/selectProjectAttachmentPrompt) | Open a dialog for the user to select from existing project attachments. |
| [updateProjectApp](/build/functions/updateProjectApp) | **Needs Permission** - Update a project app configuration. |
| [updateRawSection](/build/functions/updateRawSection) | **Needs Permission** - Update an existing `RawSection`. |
| [updateRawSections](/build/functions/updateRawSections) | **Needs Permission** - Same as `updateRawSection` but for many features. |
| [uploadProjectAttachment](/build/functions/uploadProjectAttachment) | **Needs Permission** - Upload a file as a project attachment. |

## Projects

| Function | Description |
|----------|-------------|
| [bulkCreateProjects](/build/variables/bulkCreateProjects) | **Needs Permission** - Bulk-create projects from an array of boundary features, each with optional per-project overrides. |
| [createProject](/build/variables/createProject) | **Needs Permission** - Create a project from a boundary feature. |
| [getProjectBundle](/build/functions/getProjectBundle) | Get the full project bundle including all sections, layers, and configuration. |
| [getProjects](/build/functions/getProjects) | Get all projects in the current workspace as a FeatureCollection. |
| [patchProperties](/build/variables/patchProperties) | **Needs Permission** - Patch properties on multiple projects. |
| [shareWithTeam](/build/variables/shareWithTeam) | **Needs Permission** - Share projects with a team. |
| [syncToProjects](/build/variables/syncToProjects) | Useful to bulk sync a list of projects/geometries from outside of Giraffe and make corresponding projects in Giraffe. |
| [updateProject](/build/variables/updateProject) | **Needs Permission** - Update a project's geometry or properties. |

## Utilities

| Function | Description |
|----------|-------------|
| [addMapboxEventListener](/build/functions/addMapboxEventListener) | add a listener to mapbox events. |
| appPanelRegistry |  |
| [clearIsolatedFeatures](/build/functions/clearIsolatedFeatures) | Clear the isolated features and disable isolate mode if it was enabled. |
| [disableBottomBarIframe](/build/functions/disableBottomBarIframe) | Disable and hide the bottom bar iframe. |
| [disableIsolateMode](/build/functions/disableIsolateMode) | Disables isolate mode. |
| [disableMapContentEvents](/build/functions/disableMapContentEvents) | if called, map content events (e.g. layer added, style updated, etc.) will no longer be dispatched to the SDK app. |
| [disableMapHover](/build/functions/disableMapHover) | if called, mouse coordinates will no longer be dispatched to the SDK app. |
| [disableSecondaryAppOverlay](/build/functions/disableSecondaryAppOverlay) | Disable the currently active secondary app overlay. |
| [enableBottomBarIframe](/build/functions/enableBottomBarIframe) | Enable a bottom bar iframe for displaying custom content. |
| [enableIsolateMode](/build/functions/enableIsolateMode) | Enables isolate mode. |
| [enableMapContentEvents](/build/functions/enableMapContentEvents) | if called, map content events (e.g. layer added, style updated, etc.) will be dispatched to the SDK app. By default this is enabled. |
| [enableMapHover](/build/functions/enableMapHover) | if called, mouse coordinates will be dispatched to the SDK app and can be accessed via the state key `mapHoverCoords`. |
| [enableSecondaryAppOverlay](/build/functions/enableSecondaryAppOverlay) | Enable a secondary app overlay (Urban, Analytics, Solar, or Terrain). |
| [featureArea](/build/functions/featureArea) | Calculate the area of a GeoJSON feature in square meters. |
| [fetchProjectDetails](/build/functions/fetchProjectDetails) | Fetches details (including project attachments) for a given project. |
| [fetchUserFiles](/build/functions/fetchUserFiles) | Fetches files for the user. |
| [fetchVistas](/build/functions/fetchVistas) | Fetches vistas for a project. |
| [fromProjected](/build/functions/fromProjected) | Convert local meter coordinates back to geographic coordinates (lng/lat). |
| [getAnalyticsResult](/build/functions/getAnalyticsResult) | Get the analytics result for the current project. |
| [getFlowHandleNodeTypes](/build/functions/getFlowHandleNodeTypes) | The flow node types that have an editable handle, for finding a feature to pass to {@link setFlowDrawingOverlay}. |
| [getGeoTiff](/build/functions/getGeoTiff) | Export the current 2D map view as a GeoTiff image. |
| [getGltf](/build/functions/getGltf) | Export the current 3D scene as a GLTF model. |
| [getIsolatedFeatures](/build/functions/getIsolatedFeatures) | Get the currently isolated features. |
| [getIsolateMode](/build/functions/getIsolateMode) | Check if isolate mode is enabled. |
| [getPng](/build/functions/getPng) | Export the current map view as a PNG image. |
| [getSourceLayerDetails](/build/functions/getSourceLayerDetails) | get layer info to pass to `getVectorLayerContents` from a layer in the base style eg  `roads` |
| [getTeamList](/build/functions/getTeamList) | Get the list of teams in the current organization. |
| [getTempUrl](/build/variables/getTempUrl) | get a temporary (valid for 60s) URL to access resources (files, content library packs, project attachments, etc.). Works for urls of the form /api/storage-proxy/... |
| [getTerrainMeshes](/build/functions/getTerrainMeshes) | Get the terrain meshes as a JSON string. |
| [getTiles](/build/functions/getTiles) | get the tile bounding boxes at a given zoom level covering the provided fc, used to start a GIS pipeline eg query or join per tile |
| [getUrlParams](/build/functions/getUrlParams) | Get the current page URL and Giraffe routing context. |
| [getUserClaimsJwt](/build/functions/getUserClaimsJwt) | Fetches a signed JWT (RS256) encoding the current user's claims. |
| [getUserData](/build/functions/getUserData) | Gets the current user's meta data for a specific app. |
| [getVectorLayerContents](/build/functions/getVectorLayerContents) | Get the contents of a vector tile layer as GeoJSON. |
| [navigateTo](/build/functions/navigateTo) | Navigate to a different page. |
| [readyToClose](/build/functions/readyToClose) | Signal that the SDK app is ready to close. |
| [removeMapboxEventListener](/build/functions/removeMapboxEventListener) | Remove a previously added Mapbox event listener. |
| [setContextMenuItems](/build/functions/setContextMenuItems) | Set custom context menu items that appear on right-click. |
| [setFlowDrawingOverlay](/build/functions/setFlowDrawingOverlay) | Open the drawing overlay for a flow block. |
| [setIsolatedFeatures](/build/functions/setIsolatedFeatures) | Set the features that should be isolated in isolate mode. |
| [setTopView](/build/functions/setTopView) | Set the map camera mode to flat 2D or perspective 3D. |
| [setUserData](/build/functions/setUserData) | **Needs Permission** - Sets the current user's meta data for a specific app. |
| [toProjected](/build/functions/toProjected) | Convert geographic coordinates (lng/lat) to local meters relative to an origin point. |
| [updateUiLayout](/build/functions/updateUiLayout) | Update UI layout settings (lens table, overlays, bottom-bar iframe). |

## Edit

| Function | Description |
|----------|-------------|
| [enterBlockEditMode](/build/functions/enterBlockEditMode) | **Needs Permission** - Opens the block editor on a block instance, exploding it into its child features so they can be edited in place. |
| [enterGroupEditMode](/build/functions/enterGroupEditMode) | Focuses a group so its members can be selected and edited individually, instead of clicking one selecting the whole group. |
| [exitBlockEditMode](/build/functions/exitBlockEditMode) | **Needs Permission** - Closes the block editor, writing the edited features back to the block definition when `save` is true and discarding them otherwise. |
| [exitGroupEditMode](/build/functions/exitGroupEditMode) | Leaves group edit mode, so clicking a grouped feature selects its whole group again. |
| [getBlockEditStatus](/build/functions/getBlockEditStatus) | Reports the current block edit, if any. |
| [getGroupEditMode](/build/functions/getGroupEditMode) | The `groupID` currently being edited, or null when not in group edit mode. |

## Layout

| Function | Description |
|----------|-------------|
| [updateLayout](/build/functions/updateLayout) | **Needs Permission** - Replace the panel tree of the active layout, and optionally show or hide its bars. |

## Render

| Function | Description |
|----------|-------------|
| [disableSdkRender](/build/functions/disableSdkRender) | Disable SDK-controlled rendering and restore features to their project state. |
| [getSdkRenderEnabled](/build/functions/getSdkRenderEnabled) | Whether SDK-controlled rendering is currently enabled. |
| [setSdkRender](/build/functions/setSdkRender) | Take control of what the map renders. |

## Select

| Function | Description |
|----------|-------------|
| [getLassoedProjectFeatures](/build/functions/getLassoedProjectFeatures) | Prompt the user to draw a lasso and return all project features within the selection. |
| [getLassoShape](/build/functions/getLassoShape) | Prompt the user to draw a freehand lasso shape on the map. |
| [getSelectableProjectFeatures](/build/functions/getSelectableProjectFeatures) | Get all project features that are currently selectable on the map. |
| [getUserDrawnLineString](/build/functions/getUserDrawnLineString) | Prompt the user to draw a line on the map. |
| [getUserDrawnPoint](/build/functions/getUserDrawnPoint) | Prompt the user to place a point on the map. |
| [getUserDrawnPolygon](/build/functions/getUserDrawnPolygon) | Prompt the user to draw a polygon on the map. |
| [pickRawSections](/build/functions/pickRawSections) | Prompts the user to pick one or more raw sections from the map. |

## Usage

| Function | Description |
|----------|-------------|
| [createUsage](/build/functions/createUsage) | **Needs Permission** - Create a new usage definition in the current project. |
| [deleteUsage](/build/functions/deleteUsage) | **Needs Permission** - Delete a usage definition from the current project. |
| [getProjectUsages](/build/functions/getProjectUsages) | Get all usage definitions for the current project. |
| [getUsage](/build/functions/getUsage) | Get a single usage definition by name. |
| [updateUsage](/build/functions/updateUsage) | **Needs Permission** - Update an existing usage definition. |

## Workspace

| Function | Description |
|----------|-------------|
| [fetchWorkspaceDetails](/build/functions/fetchWorkspaceDetails) |  |
| [updateWorkspaceDetails](/build/variables/updateWorkspaceDetails) | **Needs Permission** - NB `settings` is shallow-merged with the existing settings; `properties` is replaced wholesale when provided. |
