MapVisualItem.checkEnclosure

Syntax

checkEnclosure(x: Number, y: Number);

Parameters

x. Point abscissa.

y. Point ordinate.

Description

The checkEnclosure method checks whether the point with selected coordinates is conforming to any column of bar factor.

Comments

The method returns index of the column in bar factor corresponding to the point with selected coordinates. Otherwise the method returns the -1 value.

Example

To execute the example the HTML page must contain an object of the MapBar type named mapBar (see MapVisualItem Constructor). Check whether points with selected coordinates correspond to any column of bar factor and whether specified areas crosses it:

// The function checks whether point with selected coordinates corresponds to any column of bar factor
function checkEnclosure(position) {
    var enclosure = mapBar.checkEnclosure(position.getX(), position.getY());
    console.log("Point with coordinates (%s, %s) %s",
        position.getX(),
        position.getY(), (enclosure > 0) ? "corresponds to column " + enclosure : "does not belong to bar factor");
}
// The function checks if the specified area crosses any of bar factor columns
function checkIntersection(rect) {
    var left = rect.getLeft();
    var top = rect.getTop();
    var right = rect.getLeft() + rect.getWidth()
    var bottom = rect.getTop() + rect.getHeight();
    if (mapBar.checkIntersection(left, top, right, bottom, false)) {
        if (mapBar.checkIntersection(left, top, right, bottom, true)) {
            console.log("Area (%s, %s)-(%s, %s) is fully included into bar factor plot area",
                left, top, right, bottom);
        } else {
            console.log("Area (%s, %s)-(%s, %s) crosses bar factor",
                left, top, right, bottom);
        }
    } else {
        console.log("Area (%s, %s)-(%s, %s) does not cross bar factor",
            left, top, right, bottom);
    }
}
// Check if points with the specified coordinates correspond to any of bar factor columns
checkEnclosure(new PP.Point({
    X: mapBar.getLeft() + mapBar.getWidth() / 2,
    Y: Math.round(mapBar.getTop() - mapBar.getHeight() / 3)
}));
checkEnclosure(new PP.Point({
    X: mapBar.getLeft(),
    Y: mapBar.getTop()
}));
// Check if the specified areas cross any of bar factor columns
var rect1 = [mapBar.getLeft() + mapBar.getWidth() / 2,
    Math.round(mapBar.getTop() - mapBar.getHeight() / 3),
    mapBar.getWidth(),
    mapBar.getHeight()
];
checkIntersection(new PP.Rect(rect1.toString()));
var rect2 = [mapBar.getLeft(),
    mapBar.getTop(),
    mapBar.getWidth(),
    mapBar.getHeight()
];
checkIntersection(new PP.Rect(rect2.toString()));

After executing the example, the browser console displays results of all checks:

Point with the (362, 171) coordinates corresponds to column 1

Point with the (329.5, 182.5) coordinates does not belong to bar factor

The (362, 171)-(427, 206) area crosses bar factor

The (329.5, 182.5)-(394.5, 217.5) area does not cross bar factor

See also:

MapVisualItem