Area Polygon

5/5/2022

# Arbitrary Irregular Polygon MxDbArea

We can use Mx.MxDbArea() to create a line segment.

Click on Mx.MxDbArea API (opens new window) for details on the properties and method descriptions.

import Mx from "mxdraw"
// Instantiate the get-point object
const getPoint = new Mx.MrxDbgUiPrPoint();

// Instantiate the area object
const area = new Mx.MxDbArea();

// Mouse click
getPoint.goWhile((status) => {
    if (status !== Mx.MrxDbgUiPrBaseReturn.kOk) {
        return
    }
    // Add vertex coordinates
    area.addPoint(getPoint.value())
    // Set up dynamic drawing only once
    if (area.getPoints().length === 1) {
        getPoint.setUserDraw((currentPoint, worldDrawComment) => {
            // Clone the polygon object
            const tmp = area.clone()
            // Add vertices
            tmp.addPoint(currentPoint)
            // Dynamically draw the clone object to achieve the animation effect of dynamic drawing
            worldDrawComment.drawCustomEntity(tmp);
        });        
    }
}, () => {
    // Get the control object and add the polygon area to the canvas
    Mx.MxFun.getCurrentDraw().addMxEntity(area);
})

Note:

Result:

# Regular Polygon MxDbRegularPolygon

Click on Mx.MxDbRegularPolygon API (opens new window) for details on the properties and method descriptions.

const getPoint = new Mx.MrxDbgUiPrPoint();
  
// Mouse click
getPoint.go(async (status) => {
    if (status != 0) {
        return
    }
    let regularPolygon = new Mx.MxDbRegularPolygon();
    // Set the center point of the polygon edge
    regularPolygon.centerPoint = getPoint.value()
    // Set the number of edges of the polygon
    regularPolygon.sidesNumber = 6

    getPoint.setUserDraw((currentPoint, worldDrawComment) => {
        // Set the connection point of two edges of the polygon
        regularPolygon.otherPoint = currentPoint
        worldDrawComment.drawCustomEntity(regularPolygon);
    });
    regularPolygon.otherPoint = await getPoint.go()
    Mx.MxFun.getCurrentDraw().addMxEntity(regularPolygon);
})

Note:

Result: