-
Notifications
You must be signed in to change notification settings - Fork 12
/
map5.html
117 lines (98 loc) · 3.73 KB
/
map5.html
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<title>D3</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans|Roboto+Slab" rel="stylesheet">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/main.css" rel="stylesheet">
<link href="css/fonts.css" rel="stylesheet">
<style>
.municipio {
stroke: #fff;
stroke-width: 0.8px;
}
</style>
</head>
<body>
<div class="container">
<a href="index.html" class="sidebar-btn"><span class="icon-return"></span> Voltar</a>
<div class="header">
<div class="row">
<div class="col-xs-10">
<h2>Choropleth</h2>
</div>
<div class="col-xs-2 text-right">
<a href="https://github.com/jeffersonrpn/d3/blob/master/map.html" target="_blank" class="btn btn-link"><span class="icon-code"></span></a>
<a href="https://bl.ocks.org/mbostock/4060606" target="_blank" class="btn btn-link"><span class="icon-link-external"></span></a>
</div>
</div>
</div>
<ol class="breadcrumb">
<li class="active">Início</li>
<li><a href="map1.html">1</a></li>
<li><a href="map2.html">2</a></li>
<li><a href="map3.html">3</a></li>
<li><a href="map4.html">4</a></li>
<li><a href="map5.html">5</a></li>
</ol>
<header>
<h1>Estilizar</h1>
</header>
<div id="chart"></div>
<div class="section">
<h3>Referências</h3>
<ul class="list-unstyled">
<li><a href="https://bl.ocks.org/mbostock/4060606" target="_blank">Exemplo base <span class="icon-link-external"></span></a></li>
<li><a href="https://bl.ocks.org/mbostock/3306362" target="_blank">Outro exemplo (limite) <span class="icon-link-external"></span></a></li>
<li><a href="https://github.com/d3/d3-geo/blob/master/README.md#azimuthal-projections" target="_blank">Projeções azimutais <span class="icon-link-external"></span></a></li>
</ul>
</div>
</div>
<footer></footer>
<!-- scripts -->
<script src="js/d3.v4.min.js"></script>
<script src="//d3js.org/d3-color.v1.min.js"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script>
var
width = 1000,
height = 500;
var svg = d3.select("#chart")
.append("svg")
.attr('version', '1.1')
.attr('viewBox', '0 0 '+width+' '+height)
.attr('width', '100%')
.attr('class', 'map-chart');
var projection = d3.geoAlbers()
.center([-36.820037, -7.195265])
.rotate([0, 0])
.parallels([0, 0])
.scale(12000);
var path = d3.geoPath().projection(projection);
var color = d3.scaleThreshold();
d3.json("data/topo_pb.json", function(error, pb) {
if (error) throw error;
var municipios = topojson.feature(pb, pb.objects.geo_pb);
color
.domain([5000, 10000, 30000, 50000, 100000])
// Purple
.range([d3.rgb(84, 39, 143, 0.2), d3.rgb(84, 39, 143, 0.4), d3.rgb(84, 39, 143, 0.6), d3.rgb(84, 39, 143, 0.8), d3.rgb(84, 39, 143, 1)]);
// Orange
// .range([d3.rgb(248, 80, 44, 0.2), d3.rgb(248, 80, 44, 0.4), d3.rgb(248, 80, 44, 0.6), d3.rgb(248, 80, 44, 0.8), d3.rgb(248, 80, 44, 1)]);
// Blue
// .range([d3.rgb(8, 48, 107, 0.2), d3.rgb(8, 48, 107, 0.4), d3.rgb(8, 48, 107, 0.6), d3.rgb(8, 48, 107, 0.8), d3.rgb(8, 48, 107, 1)]);
svg.selectAll(".municipio")
.data(municipios.features)
.enter().append("path")
.attr("class", function(d) { return "municipio " + d.id; })
.attr("d", path)
.attr("fill", function(d){ return color(+d.properties.populacao)});
});
</script>
</body>
</html>