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
73 lines (66 loc) · 2.43 KB
/
Copy pathjson-source.js
File metadata and controls
73 lines (66 loc) · 2.43 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
73
import "geom";
// TODO nearly identical to d3.geo.jsonSource
d3.geom.jsonSource = function(sink) {
return function(object) {
(object && d3_geom_jsonSourceObjectType.hasOwnProperty(object.type)
? d3_geom_jsonSourceObjectType[object.type]
: d3_geom_jsonSourceGeometry)(object, sink);
};
};
function d3_geom_jsonSourceGeometry(geometry, sink) {
if (geometry && d3_geom_jsonSourceGeometryType.hasOwnProperty(geometry.type)) {
d3_geom_jsonSourceGeometryType[geometry.type](geometry, sink);
}
}
var d3_geom_jsonSourceObjectType = {
Feature: function(feature, sink) {
d3_geom_jsonSourceGeometry(feature.geometry, sink);
},
FeatureCollection: function(object, sink) {
var features = object.features, i = -1, n = features.length;
while (++i < n) d3_geom_jsonSourceGeometry(features[i].geometry, sink);
}
};
var d3_geom_jsonSourceGeometryType = {
Sphere: function(object, sink) {
sink.sphere();
},
Point: function(object, sink) {
object = object.coordinates;
sink.point(object[0], object[1]);
},
MultiPoint: function(object, sink) {
var coordinates = object.coordinates, i = -1, n = coordinates.length;
while (++i < n) object = coordinates[i], sink.point(object[0], object[1]);
},
LineString: function(object, sink) {
d3_geom_jsonSourceLine(object.coordinates, sink, 0);
},
MultiLineString: function(object, sink) {
var coordinates = object.coordinates, i = -1, n = coordinates.length;
while (++i < n) d3_geom_jsonSourceLine(coordinates[i], sink, 0);
},
Polygon: function(object, sink) {
d3_geom_jsonSourcePolygon(object.coordinates, sink);
},
MultiPolygon: function(object, sink) {
var coordinates = object.coordinates, i = -1, n = coordinates.length;
while (++i < n) d3_geom_jsonSourcePolygon(coordinates[i], sink);
},
GeometryCollection: function(object, sink) {
var geometries = object.geometries, i = -1, n = geometries.length;
while (++i < n) d3_geom_jsonSourceGeometry(geometries[i], sink);
}
};
function d3_geom_jsonSourceLine(coordinates, sink, closed) {
var i = -1, n = coordinates.length - closed, coordinate;
sink.lineStart();
while (++i < n) coordinate = coordinates[i], sink.point(coordinate[0], coordinate[1]);
sink.lineEnd();
}
function d3_geom_jsonSourcePolygon(coordinates, sink) {
var i = -1, n = coordinates.length;
sink.polygonStart();
while (++i < n) d3_geom_jsonSourceLine(coordinates[i], sink, 1);
sink.polygonEnd();
}