叠加Google Maps API v3后不会再出现 [英] Overlay with Google Maps API v3 not reappearing after hide

查看:136
本文介绍了叠加Google Maps API v3后不会再出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了很多例子。他们都提到要隐藏叠加层。

  overlay.setMap(null); 

这很好。但在隐藏之前再次显示它不起作用,虽然它将在初始化过程中显示。所有示例都告诉我使用

  overlay.setMap(map); 

但叠加层不会重新出现?!什么是错的?



http: //jsbin.com/oworor/3/edit

MJ

解决方案 变量是mapInitialize函数的本地变量:

 函数mapInitialize(){
var myLatlng = new google.maps.LatLng(47.72,13.48);
var myOptions = {
zoom:13,
center:myLatlng,
mapTypeId:google.maps.MapTypeId.TERRAIN
}
var map = new google.maps.Map(document.getElementById(map_canvas),myOptions);

到:

  function mapInitialize(){
var myLatlng = new google.maps.LatLng(47.72,13.48);
var myOptions = {
zoom:13,
center:myLatlng,
mapTypeId:google.maps.MapTypeId.TERRAIN
}
map = new google .maps.Map(document.getElementById(map_canvas),myOptions);


I read a lot of examples. They all mention to hide the overlay by

overlay.setMap(null);

That works fine. But showing it again after hiding it before does not work although it will be shown during initialization. All examples tell me to use

overlay.setMap(map);

But the overlay does not reappear ?! What is wrong?

See my code at http://jsbin.com/oworor/3/edit

MJ

解决方案

The "map" variable is local to the mapInitialize function, change:

        function mapInitialize() {
            var myLatlng = new google.maps.LatLng(47.72, 13.48);
            var myOptions = {
                zoom: 13,
                center: myLatlng,
                mapTypeId: google.maps.MapTypeId.TERRAIN
            }
            var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

to:

        function mapInitialize() {
            var myLatlng = new google.maps.LatLng(47.72, 13.48);
            var myOptions = {
                zoom: 13,
                center: myLatlng,
                mapTypeId: google.maps.MapTypeId.TERRAIN
            }
            map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

这篇关于叠加Google Maps API v3后不会再出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆