简体   繁体   English

在放大/缩小Google地图的同时更改信息窗口的位置

[英]Change the position of info window while zoom in/out the google map

I'm using a snazzy google map plugin in my website. 我在网站上使用了时髦的Google Map插件。 But there exists an issue that is, the info window retains in the same position when the google map zooms in/out. 但是存在一个问题,即当Google地图放大/缩小时,信息窗口会保留在相同的位置。 How can we change the info window position depends on the google map? 我们如何更改信息窗口的位置取决于Google地图?

You would need to track position on zoom, and manualy place the window. 您需要跟踪缩放位置,然后手动放置窗口。

Use this for detecting zoom: 使用它来检测缩放:

  map.addListener('zoom_changed', function() {
    infowindow.setContent('Zoom: ' + map.getZoom());
  });

Then get DOM element and swap its positions, how ever. 然后获取DOM元素并交换位置。 If you would make your DOM element on fixed or absolute positon it shouldnt change. 如果要使DOM元素处于固定位置或绝对位置,则不应更改。 If you want to make it using google maps api. 如果您想使用Google Maps API做到这一点。 You could use this: 您可以使用此:

infobox = new InfoBox({
         content: document.getElementById("infobox"),
         disableAutoPan: false,
         maxWidth: 150,
         pixelOffset: new google.maps.Size(-140, -45),
         zIndex: null,
         boxStyle: {
            background: "url('http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/examples/tipbox.gif') 0% 100% no-repeat",
            opacity: 0.75,
            width: "280px"
        },
        infoBoxClearance: new google.maps.Size(1, 1),
        alignBottom: true
    });

infobox is your DOM element, which will take content from. infobox是您的DOM元素,将从中获取内容。 alignBottom: makes it so it would allways stick on bottom. alignBottom:使其始终贴在底部。

If you would like to customize its position on zoom, use the zoom event listener and then swap its offsets. 如果要自定义其在缩放上的位置,请使用zoom事件侦听器,然后交换其偏移量。

var ib= new InfoBox({
    ....//other properties,
    pixelOffset: new google.maps.Size(-25, 0) //where your marker's height is 25px
});

Sources: 资料来源:

Fitbounds [Stackoverflow] Fitbounds [Stackoverflow]

Info Box position[Stackoverflow] 信息框位置[Stackoverflow]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM