Class: Api

Api(camera, scene, renderer, controls, patchManager)

new Api(camera, scene, renderer, controls, patchManager)

An api object is included in the global scope so that it can be called from the developer console.
Parameters:
Name Type Description
camera THREE.Camera
scene THREE.Scene
renderer THREE.Renderer
controls MapControls
patchManager PatchManager
Source:

Methods

exportCSV(delimiter)

Export a CSV file containing all the data (including individual tree coordinates)
Parameters:
Name Type Default Description
delimiter string , Set it to "," for CSV, "\t" for TSV, etc.
Source:

exportGLTF(scene, binary, name)

Export the scene as a glTF/glb 3D shape file.
Parameters:
Name Type Default Description
scene THREE.Scene Scene to export
binary boolean false Set to true for binary glb or false for plaintext glTF
name string Name for the file @default this.patchManager.datasetName
Source:

exportImage(scaleFactor)

Export image of the current view
Parameters:
Name Type Description
scaleFactor number Multiplier to for higher resolution
Source:

exportOrbitingVideo(format, framerate, scaleFactor, distance, height, nOrbits, target)

Export video where the camera orbits a given target (by default the center of mass)ยจ while the trajectory advances. Change the window size to get a different aspect ratio.
Parameters:
Name Type Default Description
format string Video format ("webm", "gif", "png", or "jpg"), the latter two being a set of images in a tar file.
framerate number Number of frames per second
scaleFactor number Multiplier to increase the video resolution
distance number 100 Distance to orbit at
height number 50 Height to orbit at
nOrbits number 1 Number of orbits during the whole trajectory
target THREE.Vector3 Target to orbit around
Source:

exportVideo(format, framerate, scaleFactor, cameraPathFunction)

Create a video of the trees growing Change the window size to get a different aspect ratio.
Parameters:
Name Type Description
format string Video format ("webm", "gif", "png", or "jpg"), the latter two being a set of images in a tar file.
framerate number Number of frames per second
scaleFactor number Multiplier to increase the video resolution
cameraPathFunction function Optional function to move the camera as the trajectory progresses. See exportOrbitingVideo() for example usage.
Source:

hidePFTLegend()

Hide the PFT legend
Source:

nextYear()

Go to the next year (if any)
Source:

playTrajectory() → {function}

Starts going through the trajectory
Source:
Returns:
Function to stop the playback.
Type
function

prevYear()

Go to the previous year (if any)
Source:

redraw()

Redraw the patches
Source:

scaleCanvas(scalingFactor)

Scales the HTML canvas (used for higher resolution in image and video export). You are meant to scale it back again when the export is done, otherwise things will look odd.
Parameters:
Name Type Default Description
scalingFactor number 2 Multiplier to scale the canvas with
Source:

setColorMap(target, attribute, colorMap, legendPosition, labelParams, minValue, maxValue)

Color stems or crowns by a data attribute.
Parameters:
Name Type Default Description
target string Either "stem" or "crown"
attribute string Data column from the input file, e.g. "Diam"
colorMap string coolwarm A matplotlib color map name
legendPosition THREE.Vector2 Position of the legend, where (0,0) is the center of the canvas and one unit is the horisontal distance from the center to the canvas edge.
labelParams Object Legend parameters. "ticks" controls number of ticks, "decimal", the number of decimals shown, "title" the legend title (enclose LaTeX math expressions in $-signs). Set notation = "scientific" for exponentials.
minValue number Minimum value for the color map (leave undefined to calculate automatically)
maxValue number Minimum value for the color map (leave undefined to calculate automatically)
Source:

setCrownColorMap(attribute, colorMap, legendPosition, labelParams, verticalLegend, minValue, maxValue)

Color crowns by a data attribute. Call without arguments to clear.
Parameters:
Name Type Default Description
attribute string Data column from the input file, e.g. "Height"
colorMap string coolwarm A matplotlib color map name
legendPosition THREE.Vector2 Position of the legend, where (0,0) is the center of the canvas and one unit is the horisontal distance from the center to the canvas edge.
labelParams Object Legend parameters. "ticks" controls number of ticks, "decimal", the number of decimals shown, "title" the legend title (enclose LaTeX math expressions in $-signs). Set notation = "scientific" for exponentials.
verticalLegend boolean false If set to true, the legend will be vertical, otherwise horisontal.
minValue number Minimum value for the color map (leave undefined to calculate automatically)
maxValue number Minimum value for the color map (leave undefined to calculate automatically)
Source:

setDetailedTreeFactor(levels)

Set the number of times branches should split. Be aware that high values will make the visualisation really slow and might cause the WebGL context to crash.
Parameters:
Name Type Description
levels number Number of divisions per tree branch
Source:

setLaiOpacity(value)

Enable or disable crown opacity according to the LAI property, such that opacity = 1-exp(-0.5*LAI) and 0 == fully transparent.
Parameters:
Name Type Description
value boolean Set to true to enable, false to disable
Source:

setPFTLegendVisibility(visible)

Toggle the PFT legend on or off
Parameters:
Name Type Description
visible boolean
Source:

setStemColorMap(attribute, colorMap, legendPosition, labelParams, verticalLegend, minValue, maxValue)

Color stems by a data attribute. Call without arguments to clear.
Parameters:
Name Type Default Description
attribute string Data column from the input file, e.g. "Diam"
colorMap string coolwarm A matplotlib color map name
legendPosition THREE.Vector2 Position of the legend, where (0,0) is the center of the canvas and one unit is the horisontal distance from the center to the canvas edge.
labelParams Object Legend parameters. "ticks" controls number of ticks, "decimal", the number of decimals shown, "title" the legend title (enclose LaTeX math expressions in $-signs). Set notation = "scientific" for exponentials.
verticalLegend boolean false If set to true, the legend will be vertical, otherwise horisontal.
minValue number Minimum value for the color map (leave undefined to calculate automatically)
maxValue number Minimum value for the color map (leave undefined to calculate automatically)
Source:

setTerrainSmoothness(smooth)

Toggle between constant patch heights for each patch, or a smooth interpolated surface connecting the patches.
Parameters:
Name Type Description
smooth boolean True for interpolated terrain
Source:

setTreeDetail(detailed)

Toggle between detailed and simple tree visualisation
Parameters:
Name Type Description
detailed boolean True for detailed trees
Source:

showPFTEditor()

Show window with PFT editor
Source:

showPFTLegend(position, scale, fontSize, distance, margin)

Show a PFT legend in the scene. An HTML mesh is used instead of a normal HTML element so that the legend can be visible in exported images
Parameters:
Name Type Description
position THREE.Vector2 Legend position (where (0,0) is the center of the screen and (1,1) is the upper-left corner).
scale number Scale down (and use a large font size) to gain resolution
fontSize number Increase (and use a smaller scale) to gain resolution
distance number Distance from camera
margin number Margin from edge
Source:

updateMargins(patchMargins)

Updates the distance between patches
Parameters:
Name Type Description
patchMargins number A factor to distance patches from each other. A value of 1 means no margin. A value of 1.2 means 20% margin.
Source: