D3.js 制作中国地图

from:  http://d3.decembercafe.org/pages/map/index.html

GeoJSON is a format for encoding a variety of geographic data structures.

http://geojson.org/

https://msdn.microsoft.com/en-us/library/mt712806.aspx

GeoJSON 是用于描述地理空间信息的数据格式。GeoJSON 不是一种新的格式,其语法规范是符合 JSON 格式的,只不过对其名称进行了规范,专门用于表示地理信息。

GeoJSON 的最外层是一个单独的对象(object)。这个对象可表示:

几何体(Geometry)。

特征(Feature)。

特征集合(FeatureCollection)。

最外层的 GeoJSON 里可能包含有很多子对象,每一个 GeoJSON 对象都有一个 type 属性,表示对象的类型,type 的值必须是下面之一。

Point:点。

MultiPoint:多点。

LineString:线。

MultiLineString:多线。

Polygon:面。

MultiPolygon:多面。

GeometryCollection:几何体集合。

Feature:特征。

FeatureCollection:特征集合。

在线工具

在线生成 GeoJSON:http://geojson.io/

简化、转换 GeoJSON 和 TopoJSON:http://mapshaper.org/

 https://pypi.org/project/geojson/

https://github.com/d3/d3/wiki

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html lang="en">
  <head
        <meta charset="utf-8"> 
        <title>中国地图</title
  </head>
<style>
 
</style>
<body>
<script src="d3.v3.min.js"></script>
<script>
    var width  = 1000;
    var height = 1000;
     
    var svg = d3.select("body").append("svg")
        .attr("width", width)
        .attr("height", height)
        .append("g")
        .attr("transform", "translate(0,0)");
     
    var projection = d3.geo.mercator()
                        .center([107, 31])
                        .scale(850)
                        .translate([width/2, height/2]);
     
    var path = d3.geo.path()
                    .projection(projection);
     
     
    var color = d3.scale.category20();
     
     
    d3.json("china.geojson", function(error, root) {
         
        if (error)
            return console.error(error);
        console.log(root.features);
         
        svg.selectAll("path")
            .data( root.features )
            .enter()
            .append("path")
            .attr("stroke","#000")
            .attr("stroke-width",1)
            .attr("fill", function(d,i){
                return color(i);
            })
            .attr("d", path )
            .on("mouseover",function(d,i){
                d3.select(this)
                    .attr("fill","yellow");
            })
            .on("mouseout",function(d,i){
                d3.select(this)
                    .attr("fill",color(i));
            });
         
    });
 
</script>
     
</body
</html

  https://www.webdesignerdepot.com/2009/06/50-great-examples-of-data-visualization/

 

posted @   ®Geovin Du Dream Park™  阅读(1400)  评论(1编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
历史上的今天:
2013-06-21 Csharp and Vbscript: Encryption/Decryption Functional
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示