user4773894
user4773894

Reputation:

Openlayers-3 rotate Linestring geometry

Is there a way to rotate a generated linestring geometry around one of its points? I've built a length string that is pointing north (only adding length to the one co-oordinate) but I now need to rotate it to a given compass heading.

Geometry objects don't seem to have the ability to be rotated around a point (OL2 did?)

What can I do to rotate this geometry?

Upvotes: 0

Views: 541

Answers (1)

user4773894
user4773894

Reputation:

I eventually went with generating the geometry dynamically and solving pythagoras.

Given the length of the current linestring geometry segment and the angle in radians, I worked out how to offset the coordinates when extending the LineGeometry to correctly angle the segments.

calculateCoordinateOffset = function(length, angle) {
        var _a = angle,
            _l = length,
            _x,
            _y;

        _x = _l * Math.sin(_a);
        _y = _l * Math.cos(_a);

        return [_x, _y];
    };

The I add X and Y to the geometry coordinates of the last segment and add those coordinates onto the linestring geometry (addCoordinates()).

Any feedback would be good. My maths is traditionally VERY bad.

Upvotes: 1

Related Questions