# JSTransparency

> Creates with the Module.getTransparency API.

```javascript
var transparency = Module.getTransparency();
```

### clear()

> Deletes all created excavations.

{% tabs %}
{% tab title="Template" %}

```javascript
Module.getTransparency().clear();
```

{% endtab %}
{% endtabs %}

### create(coordinates) → number

> Creates an excavation object with the given coordinates.
>
> The coordinates input is a list of area coordinates ([JSVector3D](https://egiscorp.gitbook.io/xdworld_global_manual/introduce-1/core/jsvector3d), [JSVector3D](https://egiscorp.gitbook.io/xdworld_global_manual/introduce-1/core/jsvector3d), ...).

{% tabs %}
{% tab title="Information" %}

| Name        | Type                                                                                          | Description                          |
| ----------- | --------------------------------------------------------------------------------------------- | ------------------------------------ |
| coordinates | [JSVec3Array](https://egiscorp.gitbook.io/xdworld_global_manual/introduce-1/core/jsvec3array) | List of excavation area coordinates. |

* Return
  * Success (returns the size of the coordinate list) or failure (-1)
* Sample
  * Refer to function createTransparency.
  * [Sandbox\_Creating Excavation](https://sandbox.egiscloud.com/code/main.do?id=analysis_transparency_create)
    {% endtab %}

{% tab title="Template" %}

```javascript
var AreaVertices = Module.getMap().getInputPoints();
var nIndex = Module.getTransparency().create(AreaVertices);
```

{% endtab %}
{% endtabs %}

### setAutoMove(coordinates, frame) → boolean

> Sets the path and speed for an automatically moving circular excavation.
>
> The coordinates input is a list of path coordinates ([JSVector2D](https://egiscorp.gitbook.io/xdworld_global_manual/introduce-1/core/jsvector2d), [JSVector2D](https://egiscorp.gitbook.io/xdworld_global_manual/introduce-1/core/jsvector2d), ...).

{% tabs %}
{% tab title="Information" %}

| Name        | Type                                                                                          | Description                                       |
| ----------- | --------------------------------------------------------------------------------------------- | ------------------------------------------------- |
| coordinates | [JSVec2Array](https://egiscorp.gitbook.io/xdworld_global_manual/introduce-1/core/jsvec2array) | List of excavation path coordinates.              |
| frame       | number                                                                                        | Frame count for updating the excavation position. |

* Return
  * true : Setting successful.
  * false : Setting failed.
* Sample
  * Refer to function setTransparencyAutoMove.
  * [Sandbox\_Moving Excavation](https://sandbox.egiscloud.com/code/main.do?id=analysis_transparency_move)
    {% endtab %}

{% tab title="Template" %}

```javascript
var movePositionList = new Module.JSVec2Array();
movePositionList.push(new Module.JSVector2D(127.03691229708741, 37.509635136930626));
movePositionList.push(new Module.JSVector2D(127.03987097629198, 37.50932526196098));
movePositionList.push(new Module.JSVector2D(127.03695802409491, 37.50865005215346));
movePositionList.push(new Module.JSVector2D(127.03985503640686, 37.50816724210336));
movePositionList.push(new Module.JSVector2D(127.03711645791172, 37.50779863443866));
movePositionList.push(new Module.JSVector2D(127.03978095384555, 37.50738212410067));
// Set auto-move for excavation
Module.getTransparency().setAutoMove(movePositionList, 5);
```

{% endtab %}
{% endtabs %}

### setDepth(depth)

> Sets the depth of the excavation.

{% tabs %}
{% tab title="Information" %}

| Name  | Type   | Description                                                  |
| ----- | ------ | ------------------------------------------------------------ |
| depth | number | Depth of the excavation from the ground surface (in meters). |

* Sample
  * Refer to function createTransparency.
  * [Sandbox\_Setting Excavation Depth](https://sandbox.egiscloud.com/code/main.do?id=analysis_transparency_depth)
    {% endtab %}

{% tab title="Template" %}

```javascript
Module.getTransparency().setDepth(5.5);
```

{% endtab %}
{% endtabs %}

### setRadius(radius)

> Sets the radius of the circular excavation.

{% tabs %}
{% tab title="Information" %}

| Name   | Type   | Description                                    |
| ------ | ------ | ---------------------------------------------- |
| radius | number | Radius of the circular excavation (in meters). |

* Sample
  * Refer to function setTransparencyRadius.
  * [Sandbox\_Setting Excavation Radius](https://sandbox.egiscloud.com/code/main.do?id=analysis_transparency_radius)
    {% endtab %}

{% tab title="Template" %}

```javascript
Module.getTransparency().setRadius(500.0);
```

{% endtab %}
{% endtabs %}

### setTexture(data, width, height, type) → boolean

> Sets the texture image for the excavation surface.
>
> The data variable is a binary array data based on Uint8Array.

{% tabs %}
{% tab title="Information" %}

| Name   | Type    | Description                                                |
| ------ | ------- | ---------------------------------------------------------- |
| data   | object  | Image Byte Array                                           |
| width  | number  | Image width                                                |
| height | number  | Image height                                               |
| type   | boolean | <p>true for side texture.<br>false for bottom texture.</p> |

* Return
  * true : Setting successful.
  * false : Setting failed.
* Sample
  * Refer to function setTransparencyTexture.
  * [Sandbox\_Excavation Texture](https://sandbox.egiscloud.com/code/main.do?id=analysis_transparency_texture)
    {% endtab %}

{% tab title="Template" %}

```javascript
var img = new Image();
// Load texture image
img.onload = function () {
    var canvas = document.createElement("canvas");
    canvas.width = img.width;
    canvas.height = img.height;
    var ctx = canvas.getContext("2d");
    ctx.drawImage(img, 0, 0);
    var imageSize = new Module.JSSize2D(img.width, img.height);
    var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
    // Set excavation texture
    var transparency = Module.getTransparency();
    transparency.setTexture(imageData, canvas.width, canvas.height, true); // floor texture
    transparency.setTexture(imageData, canvas.width, canvas.height, false); // wall texture
};
img.src = "./image/FaceImage.jpg";
```

{% endtab %}
{% endtabs %}

### startAutoMove() → boolean

> Starts the automatic movement of the excavation along a predefined path.

{% tabs %}
{% tab title="Information" %}

* Return
  * true : Movement start successful.
  * false : Movement start failed.
* Sample
  * Refer to function startTransparencyAutoMove.
  * [Sandbox\_Moving Excavation](https://sandbox.egiscloud.com/code/main.do?id=analysis_transparency_move)
    {% endtab %}

{% tab title="Template" %}

```javascript
Module.getTransparency().startAutoMove();
```

{% endtab %}
{% endtabs %}

### stopAutoMove()

> Stops the automatic movement of the excavation along a predefined path.

{% tabs %}
{% tab title="Information" %}

* Sample
  * Refer to function stopTransparencyAutoMove.
  * [Sandbox\_Moving Excavation](https://sandbox.egiscloud.com/code/main.do?id=analysis_transparency_move)
    {% endtab %}

{% tab title="Template" %}

```javascript
Module.getTransparency().stopAutoMove();
```

{% endtab %}
{% endtabs %}
