Measuring Area

Change the mouse mode to area measurement mode, then measure the area of the selected region. The measurement result values are returned as events and visualized using JSPoint and JSPolygon.

Interface Features

When you click on the point you wish to measure, the area including that point is displayed as a polygon, and double-clicking ends the area measurement. After ending one measurement, clicking on another point starts a new set of measurement results.

chevron-rightHere is the complete code that implements the above functionality.hashtag

Following are the detailed steps of the code.

Feature Implementation

Global Variables

Before implementing the feature, global variables are declared.

This manages the number of measurement objects after measurement ends.

step 1. Creating a Layer

A layer is created to visualize the area measurement icon and area values.

Since the area measurement values need to be output as POI, the layer type is set to ELT_3DPOINT.

For more information on layer types, see here.

step 2 - 1. Setting Callback Functions

Callback functions are registered to receive the calculated area from the engine.

The callback functions are registered through JSOption.

For detailed API descriptions, see the explanations of callBackAddPoint and callBackCompletePoint.

Two callback functions are registered:

step 2 - 2. Creating Area Measurement Callback Function

This callback function is executed on left mouse click.

The calculated area is received and visualized.

When the mouse mode is set to MML_ANALYS_AREA_PLANE, the callback function set here is called when you click on the point you want to measure.

For the mouse mode setting part, refer to step 3. Changing Mouse Mode.

step 2 - 3. Creating Area Measurement End Callback Function

This callback function is executed on double mouse click. It ends the area measurement.

step 3. Changing Mouse Mode

The mouse mode is changed for area measurement.

For more information on mouse modes, see here.

step 4 - 1. Creating Area Icon

An icon is created to render the received area value.

The icon image created in this step will be applied to the POI object that will display the measurement value.

For the POI object creation and result image application step, refer to step 5. Creating Area Object.

Executing the above function creates an icon image like the one shown below.

step 4 - 2. Drawing Area Balloon

A background balloon is drawn to display the accumulated area in text.

step 4 - 3. Drawing Text

The received area value is drawn as text on the balloon.

step 4 - 4. Inserting Text Comma

A comma (,) is added as a unit separator in the text composed of numbers.

step 5. Creating Area Object

An object is created with the created icon and added to the layer.

The JSSymbol class is used to store and manage textures.

For a brief description of JSSymbol, refer to the explanation of JSSymbol in the step 5. Creating Distance Object section of the distance measurement tutorial.

circle-info

It is also possible to simply register image data without using JSSymbol.

This process is described in the Creating POI tutorial.

step 6. Resetting Area Measurement

The area measurement results and objects are reset.

Result Screen

After completing the above process, the area measurement feature that displays the area information of the specified region is completed.

If you want to see the live code for the area measurement process, click herearrow-up-right.

Last updated