| 1 | function streamGeometry(geometry, stream) {
|
|---|
| 2 | if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
|
|---|
| 3 | streamGeometryType[geometry.type](geometry, stream);
|
|---|
| 4 | }
|
|---|
| 5 | }
|
|---|
| 6 |
|
|---|
| 7 | var streamObjectType = {
|
|---|
| 8 | Feature: function(object, stream) {
|
|---|
| 9 | streamGeometry(object.geometry, stream);
|
|---|
| 10 | },
|
|---|
| 11 | FeatureCollection: function(object, stream) {
|
|---|
| 12 | var features = object.features, i = -1, n = features.length;
|
|---|
| 13 | while (++i < n) streamGeometry(features[i].geometry, stream);
|
|---|
| 14 | }
|
|---|
| 15 | };
|
|---|
| 16 |
|
|---|
| 17 | var streamGeometryType = {
|
|---|
| 18 | Sphere: function(object, stream) {
|
|---|
| 19 | stream.sphere();
|
|---|
| 20 | },
|
|---|
| 21 | Point: function(object, stream) {
|
|---|
| 22 | object = object.coordinates;
|
|---|
| 23 | stream.point(object[0], object[1], object[2]);
|
|---|
| 24 | },
|
|---|
| 25 | MultiPoint: function(object, stream) {
|
|---|
| 26 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
|---|
| 27 | while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
|
|---|
| 28 | },
|
|---|
| 29 | LineString: function(object, stream) {
|
|---|
| 30 | streamLine(object.coordinates, stream, 0);
|
|---|
| 31 | },
|
|---|
| 32 | MultiLineString: function(object, stream) {
|
|---|
| 33 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
|---|
| 34 | while (++i < n) streamLine(coordinates[i], stream, 0);
|
|---|
| 35 | },
|
|---|
| 36 | Polygon: function(object, stream) {
|
|---|
| 37 | streamPolygon(object.coordinates, stream);
|
|---|
| 38 | },
|
|---|
| 39 | MultiPolygon: function(object, stream) {
|
|---|
| 40 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
|---|
| 41 | while (++i < n) streamPolygon(coordinates[i], stream);
|
|---|
| 42 | },
|
|---|
| 43 | GeometryCollection: function(object, stream) {
|
|---|
| 44 | var geometries = object.geometries, i = -1, n = geometries.length;
|
|---|
| 45 | while (++i < n) streamGeometry(geometries[i], stream);
|
|---|
| 46 | }
|
|---|
| 47 | };
|
|---|
| 48 |
|
|---|
| 49 | function streamLine(coordinates, stream, closed) {
|
|---|
| 50 | var i = -1, n = coordinates.length - closed, coordinate;
|
|---|
| 51 | stream.lineStart();
|
|---|
| 52 | while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
|
|---|
| 53 | stream.lineEnd();
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | function streamPolygon(coordinates, stream) {
|
|---|
| 57 | var i = -1, n = coordinates.length;
|
|---|
| 58 | stream.polygonStart();
|
|---|
| 59 | while (++i < n) streamLine(coordinates[i], stream, 1);
|
|---|
| 60 | stream.polygonEnd();
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | export default function(object, stream) {
|
|---|
| 64 | if (object && streamObjectType.hasOwnProperty(object.type)) {
|
|---|
| 65 | streamObjectType[object.type](object, stream);
|
|---|
| 66 | } else {
|
|---|
| 67 | streamGeometry(object, stream);
|
|---|
| 68 | }
|
|---|
| 69 | }
|
|---|