通过旋转和倾斜向 Google 地图添加图像叠加层

发布于 2025-01-12 09:16:23 字数 1713 浏览 3 评论 0 原文

我正在尝试将图像叠加到 Google 地图上,并且使用此处找到的说明:

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

当我尝试使用“标题”属性时,地图会正确旋转,但是图像也会正确旋转。我尝试使用图像变换来旋转图片,但最终在地图上出现一个白色框。

下面是我的 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/

I am trying to overlay an image onto a Google Map and I am using the instructions found here:

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

When I try using the 'heading' attribute, the map correctly rotates, however, so does the image. I have tried using an image transform to rotate the picture, but I end up with a white box on the map.

Below is my 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);
}

And this is my 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/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟酒忠诚 2025-01-19 09:16:23

不要将按 url 的旋转与 URL 上的“a_120”部分一起使用。用这种方法你的图像并没有真正旋转。您需要使用自定义叠加层。在上一个链接的示例中,要旋转图像,请修改自定义叠加类的 draw 方法,添加类似“

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

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

Don't use the rotation by url with the "a_120" part on the URL. You're image don't really rotate with this method. You need to use custom overlay. In the exemple in the previous link, to rotate you're image, modify the draw method of the custom overlay class by adding something like

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

Take a look at this post for more infos.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文