Javascript 数据映射中的自定义映射
您好,我正在使用D3JS和数据地图,我想展示世界上少数几个国家。我已经查看了在线论坛的帮助,但没有得到明确的想法或回应 源代码:Javascript 数据映射中的自定义映射,javascript,dictionary,d3.js,topojson,datamaps,Javascript,Dictionary,D3.js,Topojson,Datamaps,您好,我正在使用D3JS和数据地图,我想展示世界上少数几个国家。我已经查看了在线论坛的帮助,但没有得到明确的想法或回应 源代码: <div id="container" style="position: relative; width: 900px; height: 500px;"></div> <script src="http://cdnjs.cloudflare.com/ajax/libs/d3/3.5.3/d3.min.js"></script
<div id="container" style="position: relative; width: 900px; height: 500px;"></div>
<script src="http://cdnjs.cloudflare.com/ajax/libs/d3/3.5.3/d3.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.9/topojson.min.js"></script>
<script src="http://datamaps.github.io/scripts/0.4.4/datamaps.world.min.js"></script>
<script>
var map = new Datamap({
element: document.getElementById('container'),
fills: {
HIGH: '#afafaf',
LOW: '#123456',
MEDIUM: 'blue',
UNKNOWN: 'rgb(0,0,0)',
defaultFill: 'green'
},
dataType: 'json', //for use with dataUrl, currently 'json' or 'csv'. CSV should have an `id` column
dataUrl: null,
geographyConfig: {
dataUrl: null, //if not null, datamaps will fetch the map JSON (currently only supports topojson)
hideAntarctica: true,
borderWidth: 1,
borderOpacity: 1,
borderColor: '#FDFDFD',
popupTemplate: function(geography, data) { //this function should just return a string
return '<div class="hoverinfo"><strong>' + geography.properties.name + '</strong></div>';
},
popupOnHover: true, //disable the popup while hovering
highlightOnHover: true,
highlightFillColor: '#FC8D59',
highlightBorderColor: 'rgba(250, 15, 160, 0.2)',
highlightBorderWidth: 2,
highlightBorderOpacity: 1
},
done: function(datamap) {
datamap.svg.selectAll('.datamaps-subunit').on('click', function(geography) {
console.log(geography);
var url = window.location.href;
var arr = url.split("/");
var result = arr[0] + "//" + arr[2]
window.open(result+'/countries/view/'+geography.properties.name);
});
}
});
</script>
var-map=新数据映射({
元素:document.getElementById('container'),
填充:{
高:“#afafaf”,
低:“#123456”,
中等:“蓝色”,
未知:“rgb(0,0,0)”,
默认填充:“绿色”
},
数据类型:“json”,//用于dataUrl,当前为“json”或“csv”。csv应具有“id”列
dataUrl:null,
地理图形配置:{
dataUrl:null,//如果不为null,datamaps将获取映射JSON(当前仅支持topojson)
希迪安塔尔西卡:没错,
边框宽度:1,
边界不透明度:1,
边框颜色:“#FDFDFD”,
popupTemplate:function(geography,data){//此函数应该只返回一个字符串
返回“”+geography.properties.name+”;
},
popupOnHover:true,//在悬停时禁用弹出窗口
highlightOnHover:对,
highlightFillColor:“#FC8D59”,
highlightBorderColor:“rgba(250,15,160,0.2)”,
highlightBorderWidth:2,
highlightBorderOpacity:1
},
完成:函数(数据映射){
datamap.svg.selectAll('.datamaps子单元')。打开('click',函数(地理){
控制台日志(地理);
var url=window.location.href;
var arr=url.split(“/”);
var结果=arr[0]+“/”+arr[2]
打开(结果+'/countries/view/'+geography.properties.name);
});
}
});
它将显示所有的国家。但我不想让任何国家知道。
我怎样才能通过那边的国家名单?
我认为在custom.json或topojson的帮助下。我不知道。如果您有任何解决方案或指导,请告诉我 你为什么不这样使用你自己的topojson呢customized@VinodLouis我怎么能创建我自己没有的topojsonknow@Pratik你可以按照我使用过的相同教程进行操作。如何获得特定国家/地区的文件列表?在该论坛中,它使用的是“仅适用于美国”。一旦你有了geojson文件,就转到并编辑它,为什么不这样使用你自己的topojson呢customized@VinodLouis我怎么能创建我自己没有的topojsonknow@Pratik你可以按照我使用过的相同教程进行操作。如何获得特定国家/地区的文件列表?在该论坛中,它使用的是“仅限美国”。一旦你有了geojson文件,就转到并编辑它