在此处的地图中旋转多边形 api

Rotate a polygon in here maps api

我正在制作一个围绕建筑物的导航程序,我试图围绕右上角的点作为原点旋转多边形。我尝试了多个方程式,但似乎没有任何效果。

这是显示多边形的代码,我已经注释掉了旋转多边形的代码。

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)')
            
   
}
   
}); ```




这是我的解决方案,我必须 re-calculate 比例尺和计算必须在 co-ordinates 转换为经度和纬度之前完成。

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)
        }
    });