【问题标题】:GeoMap not working inside update panelGeoMap 在更新面板中不起作用
【发布时间】:2011-02-16 06:31:44
【问题描述】:

我在我的应用程序中使用 geomap-linechart api。我想在下拉选择的索引更改事件上查看地图和图表。如果我把它放在更新面板中它不起作用。它变成空白..但是如果我将控件放在更新面板之外就可以了..这个问题有什么理由或建议吗?更新面板里面不能用geomap吗??

这是我的代码..

<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);

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

谢谢你..

【问题讨论】:

  • 你能告诉我你的代码或你做的方式吗?我有解决方案。
  • 我已经通过 javascript 解决了同样的问题
  • 您好,感谢您的回复。我在更新面板 1 中使用了两个 div 来显示地图,另一个用于显示图表。我使用 javascript 函数来创建地图。
  • 我认为你在 javascript 代码中做了除法可见的 false 和 true 。
  • 我有两种方法可以解决这种问题。
  • 标签: c# javascript asp.net geomap


    【解决方案1】:

    第一个解决方案是再次调用加载谷歌地图的函数,如 javascript 中的 initMap() 函数。 第二种解决方案是从地图制作 iframe 页面并在您单击地图的 div 时加载它。

    您的问题出在更新面板中,它没有正确加载。

    所以。当您再次单击地图的 div 时,按第一个解决方案加载地图。 否则,通过加载 iframe 来使用第二个解决方案。

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

    希望这会对你有所帮助。

    【讨论】:

    • 你能不能解释一下,并给我一个例子来说明如何做到这一点..??
    • 这就是为什么我告诉你把你的整个代码放好,这样我就能理解你的需要了?
    • 嗨,我已经在我的帖子中添加了我的代码。你现在可以告诉我哪里出错了吗?
    【解决方案2】:
    <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;
            }
    

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

    【讨论】:

    • 你能告诉我这个 iframe 是否接受 usercontrol 作为 src 吗??
    猜你喜欢
    • 2014-07-30
    • 2017-01-31
    • 2010-10-13
    • 2011-11-07
    • 2010-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多