通过旋转和倾斜将图像覆盖添加到谷歌地图



我正在尝试将图像覆盖到谷歌地图上,我正在使用此处的说明:

https://developers.google.com/maps/documentation/javascript/examples/groundoverlay-simple

当我尝试使用"heading"属性时,贴图会正确旋转,但图像也会正确旋转。我尝试过使用图像变换来旋转图片,但最终在地图上出现了一个白色方框。

下面是我的javascript

let historicalOverlay;
function initMap() {
const map = new google.maps.Map(document.getElementById("map"), {
center: { lat: 24.960864, lng: 55.150841 },
zoom: 16,
tilt: 47.5,
heading: 120,
mapId: "90f87356969d889c",
});
const imageBounds = {
north: 24.9717265,
south: 24.9500015,
east: 55.161841,
west: 55.139841,
};
historicalOverlay = new google.maps.GroundOverlay("https://res.cloudinary.com/defmmlrqg/image/upload/a_120/v1646695548/test/img32_iidhie.jpg", imageBounds);
historicalOverlay.setMap(map);
}

这是我的HTML

<!DOCTYPE html>
<html>
<head>
<title>Tilt and Rotation</title>
<script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>
<!-- jsFiddle will insert css and js -->
</head>
<body>
<div id="map"></div>
<!-- Async script executes immediately and must be after any DOM elements used in callback. -->
<script
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap&v=beta&channel=2" async></script>
</body>
</html>

https://jsfiddle.net/ef79tL45/21/

不要使用带有"a_120";部分。使用此方法,您的图像不会真正旋转。您需要使用自定义覆盖。在上一个链接中的示例中,要旋转您的图像,请通过添加类似的内容来修改自定义覆盖类的draw方法

this.div_.style.transform = 'rotate(120deg)';

看看这篇文章,了解更多信息。

最新更新