简体   繁体   English

自定义Google Maps API InfoWindow无法正常工作

[英]Custom Google Maps API InfoWindow not working

I am using the InfoWindow domready event handler to modify the look and feel of the InfoWindow. 我正在使用InfoWindow domready事件处理程序来修改InfoWindow的外观。

google.maps.event.addListener(popup, 'domready', function() {

I am changing the height of some of the inner divs of the InfoWindow using jquery. 我正在使用jquery更改InfoWindow的某些内部div的高度。

The problem is the height changes and immediately resets back to default size. 问题在于高度会发生变化,并立即重置为默认大小。 Also, the event handler is called twice. 同样,事件处理程序被调用两次。

Not all of the divs reset their size, only some do. 并非所有的div都会重置其大小,只有一些会重置。

Part of my code: 我的部分代码:

popup = new google.maps.InfoWindow({
    content:'<image id="pin_' + pin_count + '" src="question.png"/>'
});

// Parent.Parent.Parent
e = $('#pin_' + pin_count).parent().parent().parent();
console.log(e.height());
h = parseFloat(e.height());
e.css({
    'position' : 'absolute',
    'top' : '-100px',
    'height' : (h + 100) + 'px',
    'border-radius' : '16px 16px 16px 16px',
    'border' : '2px solid red',
});
console.log(e.height());
console.log("...");

Is there any other events other than domready I can use, which lets me modify the InfoWindow after it is fully drawn? 除了domready之外,还有其他事件可以使用吗,它可以让我在完全绘制InfoWindow之后对其进行修改?

I got a way out... what is happening is whenever a InfoWindow is added to a Map, all the tiles are redrawn and along with it all the InfoWindow markers are reset too. 我有一个出路...发生的事情是,每当将InfoWindow添加到地图中时,所有图块都会重新绘制,并且所有InfoWindow标记也会随之重置。

So, I tried with 所以,我尝试了

google.maps.event.addListener(map, 'tilesloaded', function() {

It keeps my changes, but I came across a different issue. 它保留了我的更改,但遇到了另一个问题。

This will be invoked whenever anything happens on the map, like drag, zoom etc. I will have to keep flags for each marker and execute this only if the marker is being loaded. 每当地图上发生任何事情(例如拖动,缩放等)时,都将调用此方法。我将必须保留每个标记的标志,并且仅在加载标记时才执行此操作。

Is there anyway to wait for two events to happen together? 无论如何,是否有两个事件同时发生?

Update: 更新:

I am setting a flag when I get domready event. 我收到domready事件时正在设置标志。 When I get the next tilesloaded , I check for the flag and resize my InfoWindow. 当我tilesloaded下一个tilesloaded ,我检查标志并调整InfoWindow的大小。 It is working. 这是工作。 But again an issue. 但是又是一个问题。

If I add one more marker at the same coordinates, tiles are not reloaded and tilesloaded event is not generated. 如果我在相同的坐标处再添加一个标记,则不会重新加载tilesloaded也不会生成tilesloaded事件。

One more question, can I get all the events in the map into a single handler? 还有一个问题,我可以将地图中的所有事件整合到一个处理程序中吗?

Update 2 更新2

I found the issue. 我发现了问题。 The div which is the third parent of the actual InfoWindow content is the only element whose size is reset. 作为实际InfoWindow内容的第三个父级的div是重置大小的唯一元素。

So, I am checking the height of div when I get tilesloaded event, if it has been reset, then I set the height again... 因此,当我获取tileloaded事件时,我正在检查div的高度,如果已重置,则再次设置高度...

google.maps.event.addListener(map, 'tilesloaded', function() {
    e = $('#pin_' + pin_count).parent().parent().parent();
    // default height is saved before the div is resized in domready event handler
    if (e.css("height") < default_height) {
        h = parseFloat(e.height());
        e.css({
            'height' : (h + 100) + 'px',
        });
    }
});

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

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