-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.html
68 lines (59 loc) · 1.63 KB
/
map.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
<!DOCTYPE html>
<html>
<head>
<title>Maps</title>
<style type="text/css">
path {
fill: transparent;
stroke: rgba(0,0,0,1);
}
svg {
background: #ddd;
}
</style>
</head>
<body>
<script type="text/javascript" src="static/vendor/d3/d3.min.js"></script>
<script type="text/javascript" src="static/dist/js/d3-tip.js"></script>
<script type="text/javascript">
//Width and height
var w = 600;
var h = 500;
var tip = d3.tip()
.offset([-10, 0])
.attr('class', 'd3-tip')
.html(d => { return d.properties.AC_NAME })
var projection = d3.geoMercator()
.scale(1)
.translate([ 0, 0])
//Define path generator
var path = d3.geoPath()
.projection(projection)
//Create SVG
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
svg.call(tip)
//Load in GeoJSON data
d3.json("data/uttarakhand.geojson", function(json) {
// Calc bounding box transforms for entire collection
var b = path.bounds( json ),
s = .95 / Math.max((b[1][0] - b[0][0]) / w, (b[1][1] - b[0][1]) / h),
t = [(w - s * (b[1][0] + b[0][0])) / 2, (h - s * (b[1][1] + b[0][1])) / 2];
// Update the projection
projection
.scale(s)
.translate(t);
//Bind data and create one path per GeoJSON feature
svg.selectAll("path")
.data(json.features)
.enter()
.append("path")
.attr("d", path)
.on('mouseover', tip.show)
.on('mouseout', tip.hide)
});
</script>
</body>
</html>