|
5333 | 5333 | d3.csv = d3_dsv(",", "text/csv"); |
5334 | 5334 | d3.tsv = d3_dsv(" ", "text/tab-separated-values"); |
5335 | 5335 | d3.geo = {}; |
| 5336 | + d3.geo.stream = function(object, listener) { |
| 5337 | + if (d3_geo_streamObjectType.hasOwnProperty(object.type)) { |
| 5338 | + d3_geo_streamObjectType[object.type](object, listener); |
| 5339 | + } else { |
| 5340 | + d3_geo_streamGeometry(object, listener); |
| 5341 | + } |
| 5342 | + }; |
| 5343 | + function d3_geo_streamGeometry(geometry, listener) { |
| 5344 | + if (d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) { |
| 5345 | + d3_geo_streamGeometryType[geometry.type](geometry, listener); |
| 5346 | + } |
| 5347 | + } |
| 5348 | + var d3_geo_streamObjectType = { |
| 5349 | + Feature: function(feature, listener) { |
| 5350 | + d3_geo_streamGeometry(feature.geometry, listener); |
| 5351 | + }, |
| 5352 | + FeatureCollection: function(object, listener) { |
| 5353 | + var features = object.features, i = -1, n = features.length; |
| 5354 | + while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener); |
| 5355 | + }, |
| 5356 | + GeometryCollection: function(object, listener) { |
| 5357 | + var geometries = object.geometries, i = -1, n = geometries.length; |
| 5358 | + while (++i < n) d3_geo_streamGeometry(geometries[i], listener); |
| 5359 | + } |
| 5360 | + }; |
| 5361 | + var d3_geo_streamGeometryType = { |
| 5362 | + Sphere: function(object, listener) { |
| 5363 | + listener.sphere(); |
| 5364 | + }, |
| 5365 | + Point: function(object, listener) { |
| 5366 | + var coordinate = object.coordinates; |
| 5367 | + listener.point(coordinate[0], coordinate[1]); |
| 5368 | + }, |
| 5369 | + MultiPoint: function(object, listener) { |
| 5370 | + var coordinates = object.coordinates, i = -1, n = coordinates.length, coordinate; |
| 5371 | + while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1]); |
| 5372 | + }, |
| 5373 | + LineString: function(object, listener) { |
| 5374 | + d3_geo_streamLine(object.coordinates, listener); |
| 5375 | + }, |
| 5376 | + MultiLineString: function(object, listener) { |
| 5377 | + var coordinates = object.coordinates, i = -1, n = coordinates.length; |
| 5378 | + while (++i < n) d3_geo_streamLine(coordinates[i], listener); |
| 5379 | + }, |
| 5380 | + Polygon: function(object, listener) { |
| 5381 | + d3_geo_streamPolygon(object.coordinates, listener); |
| 5382 | + }, |
| 5383 | + MultiPolygon: function(object, listener) { |
| 5384 | + var coordinates = object.coordinates, i = -1, n = coordinates.length; |
| 5385 | + while (++i < n) d3_geo_streamPolygon(coordinates[i], listener); |
| 5386 | + } |
| 5387 | + }; |
| 5388 | + function d3_geo_streamLine(coordinates, listener) { |
| 5389 | + var i = -1, n = coordinates.length, coordinate; |
| 5390 | + listener.lineStart(); |
| 5391 | + while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1]); |
| 5392 | + listener.lineEnd(); |
| 5393 | + } |
| 5394 | + function d3_geo_streamPolygon(coordinates, listener) { |
| 5395 | + var i = -1, n = coordinates.length; |
| 5396 | + listener.polygonStart(); |
| 5397 | + while (++i < n) d3_geo_streamLine(coordinates[i], listener); |
| 5398 | + listener.polygonEnd(); |
| 5399 | + } |
| 5400 | + var d3_geo_streamListener = d3.geo.streamListener = function() {}; |
| 5401 | + d3_geo_streamListener.prototype = { |
| 5402 | + sphere: d3_noop, |
| 5403 | + point: d3_noop, |
| 5404 | + lineStart: d3_noop, |
| 5405 | + lineEnd: d3_noop, |
| 5406 | + polygonStart: d3_noop, |
| 5407 | + polygonEnd: d3_noop |
| 5408 | + }; |
5336 | 5409 | function d3_geo_spherical(cartesian) { |
5337 | 5410 | return [ Math.atan2(cartesian[1], cartesian[0]), Math.asin(Math.max(-1, Math.min(1, cartesian[2]))) ]; |
5338 | 5411 | } |
|
0 commit comments