【问题标题】:Google map is not visible in jquery modal dialog谷歌地图在 jquery 模态对话框中不可见
【发布时间】:2012-07-29 05:38:37
【问题描述】:

我不想在 jquery ui 模式对话框中显示谷歌地图。我打开对话框,但地图不可见。然而它存在在那里只是不可见。

这是页面来源:

<div class="dialog ui-dialog-content ui-widget-content" id="photoLocation" style="padding: 0px; background-color: rgb(255, 255, 255); overflow: hidden; width: auto; min-height: 0px; height: 390px; background-position: initial initial; background-repeat: initial initial; " scrolltop="0" scrollleft="0">
    <div id="map" style="width: 300px; height: 300px;"></div>
</div>

似乎 z-index 不知何故是错误的,但我试图在地图 div 上更改它,但这无济于事。 当我打开模态对话框时,这是其中应该显示地图的代码。

<script>
    var map;
    var styleArray = [
                      {
                          featureType: "all",
                          stylers: [
                          { visibility: "off" }
                        ]
                      },
                      {
                          featureType: "road",
                          stylers: [
                          { visibility: "on" }
                        ]
                      },
                      {
                          featureType: "administrative",
                          stylers: [
                          { visibility: "on" }
                        ]
                      }
                    ];

    (function () {
        window.onload = function() {
            var mapDiv = document.getElementById('map');

            var latlng = new google.maps.LatLng('44.339565', '-114.960937');
            var options = { styles: styleArray,
                center: latlng,
                zoom: 15,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                mapTypeControl: false
            };
            map = new google.maps.Map(mapDiv, options);

            var marker = new google.maps.Marker({
                    position: latlng,
                    icon: '../Content/Pointer.png',
                    map: map,
                    draggable: true
                });
        };
    })();
</script>
<div id="map" style="width: 300px; height: 300px;"></div>

这就是我呈现模态对话框的方式:

$(".openDialog").live("click", function (e) {
        e.preventDefault();
        $("<div></div>")
                    .addClass("dialog")
                    .attr("id", $(this).attr("data-dialog-id"))
                    .appendTo("body")
                    .dialog({
                        title: $(this).attr("data-dialog-title"),
                        close: function () { $(this).remove() },
                        modal: true,
                        resizable: false,
                        show: 'fade',
                        width: 460,
                        height: 390,
                        create: function (event, ui) {
                            $(this).parents(".ui-dialog:first").find(".ui-dialog-titlebar").css("display", "none");

                            $(this).parents(".ui-dialog").css("padding", 0);
                            $(this).parents(".ui-dialog").css("border", 4);
                            $(this).parents(".ui-dialog:first").find(".ui-dialog-content").css("padding", 0);

                            $(this).parents(".ui-dialog:first").find(".ui-dialog-content").css("background", "#ffffff");
                            $(this).parents(".ui-dialog:first").find(".ui-dialog-content").css("overflow", "hidden");

                        }

                    })
                    .load(this.href);
    });


@Html.ActionLink("Title", "Method", "Controller", new {imageId = @Model.ItemId}, new {data_dialog_id = "plid", @class = "openDialog button"})

【问题讨论】:

    标签: javascript jquery asp.net-mvc google-maps jquery-ui-dialog


    【解决方案1】:

    试试这个

    HTML:

    <div id="mymodal">
        <div id="map" style="width: 300px; height: 300px;"></div>
    </div>
    

    JS:

    $(function(){
        var map;
        var elevator;
        var latlng=new google.maps.LatLng('44.339565', '-114.960937');
        var styleArray = [
            {featureType: "all", stylers: [{ visibility: "off" }]},
            {featureType: "road", stylers: [{ visibility: "on" }]},
            {featureType: "administrative", stylers: [{ visibility: "on" }]}
        ];
        var myOptions = {
            styles: styleArray,
            zoom: 6,
            center: latlng,
            mapTypeId: 'terrain'
        };
    
        map = new google.maps.Map($('#map')[0], myOptions);
    
        var marker = new google.maps.Marker({
            position: latlng,
            map: map,
            icon: 'http://google-maps-icons.googlecode.com/files/walking-tour.png',
            draggable: true
        });
    
        $('#mymodal').dialog({width:335, height:355});
    });​
    

    An Working Example.

    【讨论】:

    • 您好,我添加了一张使用此代码获得的图片。正如你所看到的,地图 div 在那里,但它接缝它由于某种原因被隐藏了。在控制台中我得到了这个:Uncaught SyntaxError: Unexpected token ILLEGAL。我也尝试在这个函数中添加 alert(..) 并且它没有被调用。
    • 可能你在其他地方犯了错误,你能用你当前的代码创建一个jsfiddle吗?
    • 还有图中的黑色区域是什么?
    • 我添加了用于呈现有问题的模态对话框的代码。黑色区域是模态对话框覆盖。
    • 你要做什么,你添加的代码中map的代码在哪里?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多