繁体   English   中英

GeoMap在更新面板中不起作用

[英]GeoMap not working inside update panel

我在我的应用程序中使用geomap-linechart api。我想查看下拉列表中的索引更改事件的地图和图表。如果将其放在更新面板中,它将不起作用。但是,如果我将控件放到更新面板之外,它就可以正常工作。这个问题有任何原因或建议吗? 无法在更新面板中使用地理地图?

这是我的代码。

<script src="Scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
<script type='text/javascript' src='http://www.google.com/jsapi'></script>
<script src='http://maps.google.com/maps?file=api&v=2&key=ABCDEFG' type='text/javascript'></script>
<script type='text/javascript'>

google.load('visualization', '1', { 'packages': ['geomap'], 'language': 'fr'});        

    var countryCode;

//地图功能

    function DrawWorldMap(country, lat, lang, name, count, usercount, user, bandwidth, vtitle, htitle, title1, title2) {
        try {
            var data = new google.visualization.DataTable();
            data.addRows(count);
            data.addColumn('string', 'Country');
            data.addColumn('number', 'BandWidth');
            var contry = country.split(',');
            var band = bandwidth.split(',');

            for (var i = 0; i < count; i++) {
                data.setValue(i, 0, contry[i]);
            }
            for (var h = 0; h < count; h++) {
                data.setValue(h, 1, Number(band[h]));
            }
            var options = {};
            options['dataMode'] = 'regions';

            var container = document.getElementById('<%=map_canvas.ClientID%>');
            var geomap = new google.visualization.GeoMap(container);
            geomap.draw(data, options);
            var lati = lat;
            var langi = lang;
            var loop = count;
            google.visualization.events.addListener(
    geomap, 'regionClick', function (e) {
        countryCode = e['region'];
        CreateCountryMap(lati, langi, name, loop, usercount, country, user, bandwidth, vtitle, htitle, title1, title2);

    });

        }            
        catch (exception) {
            alert('drawworldmap: ' + exception);
        } 
        drawVisualization(user, bandwidth, usercount, vtitle, htitle, title1, title2); // here am calling the chart function..
    }

//图表功能

   function drawVisualization(User, Bandwidth, counts, vtitle, htitle, title1, title2) {
        try {
            // Create and populate the data table.
            var data = new google.visualization.DataTable();
            data.addColumn('string', title1);
            data.addColumn('number', title2);
            var username = User.split(',');
            var BandWidth = Bandwidth.split(',');
            for (var i = 0; i < counts; i++) {
                data.addRow([String(username[i]), Number(BandWidth[i])]);
            }

            // Create and draw the visualization.
            new google.visualization.LineChart(document.getElementById('<%=visualization.ClientID%>')).
        draw(data, { curveType: "function", pointSize: 5, title: 'User Chart', titlePosition: 'out',
            width: 400, height: 350, backgroundColor: 'AliceBlue',
            vAxis: { maxValue: 100, title: vtitle }, fontSize: 8, hAxis: { title: htitle }
        }
            );
        }
        catch (exception) {
            alert(exception);
        }
    }       

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>

<asp:DropDownList ID="ddlusername" runat="server" AutoPostBack="true" 
        OnSelectedIndexChanged="ddlusername_SelectedIndexChanged" Height="17px" 
        Width="132px">   </asp:DropDownList>    

<div id="visualization" align="center" style="border: thin solid grey;" runat="server"> </div>

<div id='map_canvas' style="border: thin solid grey;" align="center" runat="server"> </div>

<asp:Label ID="lblmap" runat="server"></asp:Label>

</ContentTemplate>
</asp:UpdatePanel>

我从这样的后面的代码中调用drawworldmap函数。

   ScriptManager.RegisterStartupScript(lblmap, this.GetType(), "js2", "google.setOnLoadCallback(DrawWorldMap('" + contry + "','" + city + "','" + langitude + "','" + longitude + "'," + count + "," + usercount + ",'" + username + "','" + bandwidth + "','Bandwidth','UserName','User','BandWidth'));", true);

请帮助,如果您有任何想法..

谢谢..

第一个解决方案是再次加载google map的调用函数,就像来自javascript的initMap()函数一样。 第二种解决方案是从地图制作iframe页面,然后在点击地图div时加载它。

您的问题是在更新面板中,无法正确加载。

因此,当您再次单击地图的div时,将通过第一个解决方案加载地图。 否则,请通过加载iframe使用第二种解决方案。

我在项目中都做过这件事。

希望这会帮助你。

<script type="text/javascript">
      function ActiveTabChanged(sender, e) {
        if (sender.get_activeTab().get_headerText().toLowerCase().indexOf('contact') > -1) {
            var FrameSrc = ('<%=SetFrameSrc() %>');
            document.getElementById('<%=ifrmMap.ClientID %>').src = FrameSrc;
        }   
    }
</script>

<iframe id="ifrmMap" runat="server" height="324px" width="462px" frameborder="0" scrolling="no" marginwidth="0" marginheight="0"></iframe>

在背后的代码

/// <summary>
        /// Get the iframe source when contact tab active.
        /// </summary>
        /// <returns></returns>
        public string SetFrameSrc()
        {
            string strSrc = string.Empty;
            if (!string.IsNullOrEmpty(queryID))
            {
                strSrc = //Add Google Map New page url;
            }
            return strSrc;
        }

当您从下拉列表中选择地图时,在选定的indexed上调用此javascript函数。 将iframe放在您现在放置地图div的位置。 并将地图功能放到新页面上。 这是在此iframe中加载的。最后一个函数是函数后面的代码,您必须在其中编写地图代码的地方设置新页面。

暂无
暂无

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

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