Google map API - rotate polygon in z-direction

点点圈 提交于 2019-12-12 03:35:00

问题


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

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.

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


回答1:


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.



来源:https://stackoverflow.com/questions/35878395/google-map-api-rotate-polygon-in-z-direction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!