如何使用 JS 通过外部点击以不同颜色显示地理地图
我正在尝试使用使用两种配色方案的地理地图。用户将单击页面上的链接,然后使用 js,我将更改地图的颜色并重新绘制它。
我会改变
options['colors'] = [0xbaecc7, 0x3bc75f]; // light to dark green
问题是,每次我调用函数重绘时,它似乎都会重新加载地理地图。我有两个功能..下面的一个是绿色的,另一个是绘制蓝色地图的。 首先,我通过调用 setOnLoadCallBack
使用 drawMap
绘制蓝色地图
google.setOnLoadCallback(drawMap);
任何帮助或想法将不胜感激!
function drawGoalsMap() {
var options = {};
options['dataMode'] = 'regions';
options['region'] = 'world';
options['colors'] = [0xbaecc7, 0x3bc75f]; // light to dark green
options['width'] = '900px';
options['height'] = '400px';
var data = new google.visualization.DataTable();
data.addRows(6);
data.addColumn('string', 'Country');
data.addColumn('number', 'Messages');
data.setValue(0, 0, 'Germany');
data.setValue(0, 1, 200);
data.setValue(1, 0, 'United States');
data.setValue(1, 1, 300);
data.setValue(2, 0, 'Brazil');
data.setValue(2, 1, 400);
data.setValue(3, 0, 'Canada');
data.setValue(3, 1, 500);
data.setValue(4, 0, 'France');
data.setValue(4, 1, 600);
data.setValue(5, 0, 'RU');
data.setValue(5, 1, 700);
var container = document.getElementById('map_canvas');
var geomap = new google.visualization.GeoMap(container);
geomap.draw(data, options);
google.visualization.events.addListener(geomap, 'regionClick',
function(e) {
var countryCode = e['region'];
DrillDown(countryCode);
}
);
};
I'm trying to use a geomap using 2 color schemes. the user will click a link on the page and then, using js, i will change the color of the map and redraw it.
i would change
options['colors'] = [0xbaecc7, 0x3bc75f]; // light to dark green
The problem is that every time i call the function to redraw it seems to reload the geomap. I have two functions.. the one below is for green and the otherone is for drawing the blue map.
At the start i draw the blue map using drawMap
by calling setOnLoadCallBack
google.setOnLoadCallback(drawMap);
Any help or ideas would be appreaciated!
function drawGoalsMap() {
var options = {};
options['dataMode'] = 'regions';
options['region'] = 'world';
options['colors'] = [0xbaecc7, 0x3bc75f]; // light to dark green
options['width'] = '900px';
options['height'] = '400px';
var data = new google.visualization.DataTable();
data.addRows(6);
data.addColumn('string', 'Country');
data.addColumn('number', 'Messages');
data.setValue(0, 0, 'Germany');
data.setValue(0, 1, 200);
data.setValue(1, 0, 'United States');
data.setValue(1, 1, 300);
data.setValue(2, 0, 'Brazil');
data.setValue(2, 1, 400);
data.setValue(3, 0, 'Canada');
data.setValue(3, 1, 500);
data.setValue(4, 0, 'France');
data.setValue(4, 1, 600);
data.setValue(5, 0, 'RU');
data.setValue(5, 1, 700);
var container = document.getElementById('map_canvas');
var geomap = new google.visualization.GeoMap(container);
geomap.draw(data, options);
google.visualization.events.addListener(geomap, 'regionClick',
function(e) {
var countryCode = e['region'];
DrillDown(countryCode);
}
);
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在偶然编辑我的代码后,我发现了问题!
我正在使用链接
Goals
我将其更改为排除
href=""
After a chance edit in my code I found the problem!!!
I was using the link
<a href="" onclick="drawGoalsMap()">Goals</a>
I changed it to exclude the
href=""