-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraticule.js
More file actions
67 lines (57 loc) · 1.75 KB
/
Copy pathgraticule.js
File metadata and controls
67 lines (57 loc) · 1.75 KB
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
d3.geo.graticule = function() {
var x1, x0,
y1, y0,
dx = 22.5, dy = dx,
x, y,
precision = 2.5;
function graticule() {
return {type: "MultiLineString", coordinates: lines()};
}
function lines() {
return d3.range(Math.ceil(x0 / dx) * dx, x1, dx).map(x)
.concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).map(y));
}
graticule.lines = function() {
return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
}
graticule.outline = function() {
return {
type: "Polygon",
coordinates: [
x(x0).concat(
y(y1).slice(1),
x(x1).reverse().slice(1),
y(y0).reverse().slice(1))
]
};
};
graticule.extent = function(_) {
if (!arguments.length) return [[x0, y0], [x1, y1]];
x0 = +_[0][0], x1 = +_[1][0];
y0 = +_[0][1], y1 = +_[1][1];
if (x0 > x1) _ = x0, x0 = x1, x1 = _;
if (y0 > y1) _ = y0, y0 = y1, y1 = _;
return graticule.precision(precision);
};
graticule.step = function(_) {
if (!arguments.length) return [dx, dy];
dx = +_[0], dy = +_[1];
return graticule;
};
graticule.precision = function(_) {
if (!arguments.length) return precision;
precision = +_;
x = d3_geo_graticuleX(y0, y1, precision);
y = d3_geo_graticuleY(x0, x1, precision);
return graticule;
};
return graticule.extent([[-180 + ε, -90 + ε], [180 - ε, 90 - ε]]);
};
function d3_geo_graticuleX(y0, y1, dy) {
var y = d3.range(y0, y1 - ε, dy).concat(y1);
return function(x) { return y.map(function(y) { return [x, y]; }); };
}
function d3_geo_graticuleY(x0, x1, dx) {
var x = d3.range(x0, x1 - ε, dx).concat(x1);
return function(y) { return x.map(function(x) { return [x, y]; }); };
}