简体   繁体   English

中心窗口位于信息窗口,而不是Google地图中的路线

[英]Center map at infowindow, not at route in google maps

My google map centers around a route, that is given by a Direction Service and rendered by a Direction Renderer (called directionsDisplay here). 我的Google地图以路线为中心,该路线由Directions服务提供,并由Directions Renderer渲染(此处称为DirectionsDisplay)。

According to the docs and many threads and forums I've read, the infoWindow should autoPan to center at version 3.0 (which I am using). 根据我读过的文档以及许多主题和论坛,infoWindow应该自动以3.0版(我正在使用)为中心。

I'm waiting till all callbacks are called, I have tried to open the window when gmaps tileloaded-Event is fired, as well as the idle event. 我一直等到所有回调都被调用为止,在gmaps tileloaded-Event以及idle事件被触发时,我试图打开窗口。

No matter what: The map centers always around the route (and hence pushing the infowindow out of the viewport). 无论如何:地图始终以路线为中心(因此将信息窗口推出视口)。

What am I doing wrong here? 我在这里做错了什么?

directionsService.route(request, function(result, status) {

        if (status == google.maps.DirectionsStatus.OK) {
            directionsDisplay.setDirections(result);
            directionsDisplay.suppressMarkers = true;

            if(this.marker){
                this.marker.setPosition(result.routes[0].overview_path[result.routes[0].overview_path.length-1]);
            } else{
                this.marker = new google.maps.Marker({
                    position: result.routes[0].overview_path[result.routes[0].overview_path.length-1], 
                    map: Gmap.map
                });

            }

                var contentString = '<div id="infowindow_title">Hello World</div><div id="infowindow_cat">Lorem Ipsum</div>';
                if(!this.infoWindow){
                    this.infoWindow = new google.maps.InfoWindow({
                        content: contentString                      
                    });
                } else {
                    this.infowindow.setContent(contentString);
                }

                this.infoWindow.open(Gmap.map, this.marker);


        }
    });

I have found the error: gMaps did everything right; 我发现了错误:gMaps所做的一切都正确; there was some css (in the theme of the cms i was using), that set some layer in the stack to overflow: hidden. 有一些css(以我使用的cms为主题),将堆栈中的某些层设置为溢出:隐藏。

Thus, gMaps thought it had more space to show the infoWindow than it was acutally visible. 因此,gMaps认为它显示信息窗口的空间比实际可见的空间大。

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

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