1

In openlayers3, is there a method for removing the Z when getting the coordinates of a feature with layout=XYZ? Something akin to this but built into ol3?

function strip(geom, test) {
    if (!geom.length) return;
    if (typeof geom[0] !== "number") {
        return geom.map(function(g) { return strip(g, test); });
    }
    return geom.filter(test);
}

1 Answer 1

2

Lacking a better answer, here's a custom solution that seems to be working:

function strip(geom, test: (a, b) => boolean) {
if (!geom.length) return;
if (typeof geom[0] !== "number") {
    return geom.map(g => strip(g, test));
}
return geom.filter(test);

}

Usage:

coords = geom.getCoordinates();
if (geom.stride > 2) {
    strip(coords, (v, i) => 2 > i % geom.stride);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.