Google map API - rotate polygon in z-direction

2019-09-02 21:27发布

I would like to rotate polygon on Z-direction. Please See below image. enter image description here

I got code from below post

Google Maps API rotate Rectangle

Which is working perfectly fine to rotate polygon on X-->Y or Y-->X direction. Please see below image.

enter image description here

I apologize for my English to explain this problem. I appreciate any help on this.

1条回答
一纸荒年 Trace。
2楼-- · 2019-09-02 22:13

The following example demonstrates how to rotate a polygon. Create a polygon from a rectangle object and display it on the map instead of rectangle. Rotate a polygon.

check Investigation results on SO docs for code snippet

Fiddle - https://jsfiddle.net/vo0yzp2t/1/

function rotatePolygon(polygon,angle) {
    var map = polygon.getMap();
    var prj = map.getProjection();
    var origin = prj.fromLatLngToPoint(polygon.getPath().getAt(0)); //rotate around first point

    var coords = polygon.getPath().getArray().map(function(latLng){
       var point = prj.fromLatLngToPoint(latLng);
       var rotatedLatLng =  prj.fromPointToLatLng(rotatePoint(point,origin,angle));
       return {lat: rotatedLatLng.lat(), lng: rotatedLatLng.lng()};
    });
    polygon.setPath(coords);
}

And you can also refer to When I rotate a rectangle, it's no longer rectangular.

查看更多
登录 后发表回答