forked from d3/d3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson-source.js
More file actions
72 lines (66 loc) · 2.47 KB
/
Copy pathjson-source.js
File metadata and controls
72 lines (66 loc) · 2.47 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
68
69
70
71
72
import "../math/trigonometry";
import "geo";
d3.geo.jsonSource = function(sink) {
return function(object) {
(object && d3_geo_jsonSourceObjectType.hasOwnProperty(object.type)
? d3_geo_jsonSourceObjectType[object.type]
: d3_geo_jsonSourceGeometry)(object, sink);
};
};
function d3_geo_jsonSourceGeometry(geometry, sink) {
if (geometry && d3_geo_jsonSourceGeometryType.hasOwnProperty(geometry.type)) {
d3_geo_jsonSourceGeometryType[geometry.type](geometry, sink);
}
}
var d3_geo_jsonSourceObjectType = {
Feature: function(feature, sink) {
d3_geo_jsonSourceGeometry(feature.geometry, sink);
},
FeatureCollection: function(object, sink) {
var features = object.features, i = -1, n = features.length;
while (++i < n) d3_geo_jsonSourceGeometry(features[i].geometry, sink);
}
};
var d3_geo_jsonSourceGeometryType = {
Sphere: function(object, sink) {
sink.sphere();
},
Point: function(object, sink) {
object = object.coordinates;
sink.point(object[0] * d3_radians, object[1] * d3_radians);
},
MultiPoint: function(object, sink) {
var coordinates = object.coordinates, i = -1, n = coordinates.length;
while (++i < n) object = coordinates[i], sink.point(object[0] * d3_radians, object[1] * d3_radians);
},
LineString: function(object, sink) {
d3_geo_jsonSourceLine(object.coordinates, sink, 0);
},
MultiLineString: function(object, sink) {
var coordinates = object.coordinates, i = -1, n = coordinates.length;
while (++i < n) d3_geo_jsonSourceLine(coordinates[i], sink, 0);
},
Polygon: function(object, sink) {
d3_geo_jsonSourcePolygon(object.coordinates, sink);
},
MultiPolygon: function(object, sink) {
var coordinates = object.coordinates, i = -1, n = coordinates.length;
while (++i < n) d3_geo_jsonSourcePolygon(coordinates[i], sink);
},
GeometryCollection: function(object, sink) {
var geometries = object.geometries, i = -1, n = geometries.length;
while (++i < n) d3_geo_jsonSourceGeometry(geometries[i], sink);
}
};
function d3_geo_jsonSourceLine(coordinates, sink, closed) {
var i = -1, n = coordinates.length - closed, coordinate;
sink.lineStart();
while (++i < n) coordinate = coordinates[i], sink.point(coordinate[0] * d3_radians, coordinate[1] * d3_radians);
sink.lineEnd();
}
function d3_geo_jsonSourcePolygon(coordinates, sink) {
var i = -1, n = coordinates.length;
sink.polygonStart();
while (++i < n) d3_geo_jsonSourceLine(coordinates[i], sink, 1);
sink.polygonEnd();
}