地理地图在更新面板内不起作用
我在我的应用程序中使用 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);
如果您有任何想法,请帮助..
谢谢..
I am using geomap-linechart api in my application.. I want to view the map and the chart on a drop down selected index changed event.. It doesn't work if i put it inside update panel.. it becomes blank.. but it woks fine if i put the control outside the update panel.. Is there any reason or suggestion for this prob?? is it not possible to use the geomap inside update panel??
this is my code..
<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;
// map function
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..
}
//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>
and i'm calling the drawworldmap function from code behind like this..
ScriptManager.RegisterStartupScript(lblmap, this.GetType(), "js2", "google.setOnLoadCallback(DrawWorldMap('" + contry + "','" + city + "','" + langitude + "','" + longitude + "'," + count + "," + usercount + ",'" + username + "','" + bandwidth + "','Bandwidth','UserName','User','BandWidth'));", true);
Pls help if you have any idea..
Thank you..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第一个解决方案是再次调用加载谷歌地图的函数,例如 JavaScript 中的 initMap() 函数。
第二个解决方案是从地图创建 iframe 页面,并在单击地图的 div 时加载它。
您的问题是在更新面板中,它无法正确加载。
所以。当您再次单击地图的 div 时,按第一个解决方案加载地图。
否则,通过加载 iframe 使用第二种解决方案。
我在我的项目中已经完成了这两件事。
希望这会对您有所帮助。
First solution is call function of load google map again, like initMap() function from javascript.
second solution is make iframe page from map and load it when you click on div of map.
your problem is in update panel it is not loading properly.
so.When you click on div of map again load map by first solution.
other wise use second soluction by loading iframe.
I have done both this thing in my projects.
Hope this will help you.
在代码隐藏处
,当您从下拉列表中选择地图时,请在选定的索引上调用此 javascript 函数。
将 iframe 放在您现在放置地图 div 的位置。并将地图功能移至新页面。
这是在此 iframe 中加载的。最后一个函数是代码隐藏函数,您必须在其中设置新页面
已经写了地图代码。
At Code Behind
When you select map from dropdown call this javascript function on selected indexchanged.
put iframe where you put div of map right now. and put map functionality over to new page.
which is loaded in this iframe.and last function is code behind function where you have to set your new page where you
have write map code.