在jquery模式对话框中看不到Google地图

时间:2012-07-28 12:30:08

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

我不想在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>

enter image description here 这就是我提出模态对话框的方式:

$(".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"})

1 个答案:

答案 0 :(得分:3)

试试这个

<强> 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