javascripthere-apiheremaps

Rotate a polygon in here maps api


I am making a navigation program around a building, i am trying to rotate the polygons around the top right point as the origin. I have tried multiple equations, but nothing seems to work.

SS of the website

this is the code to display the polygons, i have commented out the code that rotates the polygons.

const scaleX = 0.000000114939702;
const scaleY = 0.000000152939702;
const originX = 53.4724642;
const originY = -2.2393615;

//usage:
readTextFile("result.json", function(text){
    const data = JSON.parse(text);
    for (const i in data) {
        const list = [];

        list.push(data[i].C1, data[i].C2, data[i].C3, data[i].C4);

        for (const j in list) {
            list[j][0] = (originX-list[j][0]*scaleX)
            list[j][1] = (-(list[j][1]*scaleY)+originY)
        }

        var width = list[0][0] - list[1][0];
        var height = list[0][1] - list[3][1];

        var distanceToOriginX = originX-list[0][0]
        var distanceToOriginY = originY-list[0][1]

        //list[0][0] = originX - Math.sin(0.524)*distanceToOriginX+height
        //list[0][1] = originY + Math.cos(0.524)*distanceToOriginY+width
        



        addPolygonToMap(map, (list[0][0]), (list[0][1]), (list[1][0]), (list[1][1]), (list[2][0]), (list[2][1]), (list[3][0]), (list[3][1]), 'rgba(0, 0, 255, 1)')
            
   
}
   
}); ```





Solution

  • This is my solution, i had to re-calculate the scale and the calculations had to be done before the co-ordinates were converted into longitude and latitude.

    const scaleX = 0.000000107;
    const scaleY = 0.000000171;
    const originX = 53.4724642;
    const originY = -2.2393615;
    
    function readFile(filename, floor, colour) {
        readTextFile(filename, function(text){
            const data = JSON.parse(text);
            for (const i in data) {
                const list = [];
        
                list.push(data[i].C1, data[i].C2, data[i].C3, data[i].C4);
        
                var angle = 0.484
        
                for (const j in list) {
                    var distanceToOrigin = pythagorean(list[j][1], list[j][0])
                    var ang = 1.5708-(angle + Math.atan(list[j][0]/list[j][1]))
                    
                    list[j][0] = originX-(Math.cos(ang)*distanceToOrigin)*scaleX
                    list[j][1] = originY-(Math.sin(ang)*distanceToOrigin)*scaleY
                }
        
                addPolygonToMap(map, (list[0][0]), (list[0][1]), (list[1][0]), (list[1][1]), (list[2][0]), (list[2][1]), (list[3][0]), (list[3][1]), colour, floor)
            }
        });