|
5795 | 5795 | var lon = point[0], lat = point[1]; |
5796 | 5796 | return lat > 50 ? alaska : lon < -140 ? hawaii : lat < 21 ? puertoRico : lower48; |
5797 | 5797 | } |
5798 | | - var projectResample = d3_geo_resample(function(λ, φ) { |
5799 | | - return albersUsa([ λ * d3_degrees, φ * d3_degrees ]); |
5800 | | - }); |
5801 | | - albersUsa.stream = function(listener) { |
5802 | | - return d3_geo_albersUsaRadians(projectResample(listener)); |
5803 | | - }; |
5804 | 5798 | albersUsa.scale = function(x) { |
5805 | 5799 | if (!arguments.length) return lower48.scale(); |
5806 | 5800 | lower48.scale(x); |
|
5820 | 5814 | }; |
5821 | 5815 | return albersUsa.scale(lower48.scale()); |
5822 | 5816 | }; |
5823 | | - function d3_geo_albersUsaRadians(stream) { |
5824 | | - return { |
5825 | | - point: function(λ, φ) { |
5826 | | - stream.point(λ * d3_radians, φ * d3_radians); |
5827 | | - }, |
5828 | | - sphere: function() { |
5829 | | - stream.sphere(); |
5830 | | - }, |
5831 | | - lineStart: function() { |
5832 | | - stream.lineStart(); |
5833 | | - }, |
5834 | | - lineEnd: function() { |
5835 | | - stream.lineEnd(); |
5836 | | - }, |
5837 | | - polygonStart: function() { |
5838 | | - stream.polygonStart(); |
5839 | | - }, |
5840 | | - polygonEnd: function() { |
5841 | | - stream.polygonEnd(); |
5842 | | - } |
5843 | | - }; |
5844 | | - } |
5845 | 5817 | function d3_geo_albers(φ0, φ1) { |
5846 | 5818 | var sinφ0 = Math.sin(φ0), n = (sinφ0 + Math.sin(φ1)) / 2, C = 1 + sinφ0 * (2 * n - sinφ0), ρ0 = Math.sqrt(C) / n; |
5847 | 5819 | function albers(λ, φ) { |
|
6254 | 6226 | return d3_geo_projection(d3_geo_orthographic); |
6255 | 6227 | }).raw = d3_geo_orthographic; |
6256 | 6228 | d3.geo.path = function() { |
6257 | | - var pointRadius = 4.5, projection = d3.geo.albersUsa(), context, stream = new d3_geo_pathBuffer(); |
| 6229 | + var pointRadius = 4.5, projection, context, projectStream, contextStream; |
6258 | 6230 | function path(object) { |
6259 | | - if (object) d3.geo.stream(object, projection.stream(stream.pointRadius(typeof pointRadius === "function" ? +pointRadius.apply(this, arguments) : pointRadius))); |
6260 | | - return stream.result(); |
| 6231 | + if (object) d3.geo.stream(object, projectStream(contextStream.pointRadius(typeof pointRadius === "function" ? +pointRadius.apply(this, arguments) : pointRadius))); |
| 6232 | + return contextStream.result(); |
6261 | 6233 | } |
6262 | 6234 | path.area = function(object) { |
6263 | 6235 | d3_geo_pathAreaSum = 0; |
6264 | | - d3.geo.stream(object, projection.stream(d3_geo_pathArea)); |
| 6236 | + d3.geo.stream(object, projectStream(d3_geo_pathArea)); |
6265 | 6237 | return d3_geo_pathAreaSum; |
6266 | 6238 | }; |
6267 | 6239 | path.centroid = function(object) { |
6268 | 6240 | d3_geo_centroidDimension = d3_geo_centroidX = d3_geo_centroidY = d3_geo_centroidZ = 0; |
6269 | | - d3.geo.stream(object, projection.stream(d3_geo_pathCentroid)); |
| 6241 | + d3.geo.stream(object, projectStream(d3_geo_pathCentroid)); |
6270 | 6242 | return d3_geo_centroidZ ? [ d3_geo_centroidX / d3_geo_centroidZ, d3_geo_centroidY / d3_geo_centroidZ ] : undefined; |
6271 | 6243 | }; |
6272 | 6244 | path.bounds = function(object) { |
6273 | 6245 | return d3_geo_bounds(projection)(object); |
6274 | 6246 | }; |
6275 | 6247 | path.projection = function(_) { |
6276 | 6248 | if (!arguments.length) return projection; |
6277 | | - projection = _; |
| 6249 | + projectStream = (projection = _).stream ? projection.stream : d3_geo_pathProjectStream(projection); |
6278 | 6250 | return path; |
6279 | 6251 | }; |
6280 | 6252 | path.context = function(_) { |
6281 | 6253 | if (!arguments.length) return context; |
6282 | | - stream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_); |
| 6254 | + contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_); |
6283 | 6255 | return path; |
6284 | 6256 | }; |
6285 | 6257 | path.pointRadius = function(_) { |
6286 | 6258 | if (!arguments.length) return pointRadius; |
6287 | 6259 | pointRadius = typeof _ === "function" ? _ : +_; |
6288 | 6260 | return path; |
6289 | 6261 | }; |
6290 | | - return path; |
| 6262 | + return path.projection(d3.geo.albersUsa()).context(null); |
6291 | 6263 | }; |
6292 | 6264 | function d3_geo_pathCircle(radius) { |
6293 | 6265 | return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + +2 * radius + "z"; |
6294 | 6266 | } |
| 6267 | + function d3_geo_pathProjectStream(project) { |
| 6268 | + var resample = d3_geo_resample(function(λ, φ) { |
| 6269 | + return project([ λ * d3_degrees, φ * d3_degrees ]); |
| 6270 | + }); |
| 6271 | + return function(stream) { |
| 6272 | + stream = resample(stream); |
| 6273 | + return { |
| 6274 | + point: function(λ, φ) { |
| 6275 | + stream.point(λ * d3_radians, φ * d3_radians); |
| 6276 | + }, |
| 6277 | + sphere: function() { |
| 6278 | + stream.sphere(); |
| 6279 | + }, |
| 6280 | + lineStart: function() { |
| 6281 | + stream.lineStart(); |
| 6282 | + }, |
| 6283 | + lineEnd: function() { |
| 6284 | + stream.lineEnd(); |
| 6285 | + }, |
| 6286 | + polygonStart: function() { |
| 6287 | + stream.polygonStart(); |
| 6288 | + }, |
| 6289 | + polygonEnd: function() { |
| 6290 | + stream.polygonEnd(); |
| 6291 | + } |
| 6292 | + }; |
| 6293 | + }; |
| 6294 | + } |
6295 | 6295 | function d3_geo_pathBuffer() { |
6296 | 6296 | var pointCircle = d3_geo_pathCircle(4.5), buffer = []; |
6297 | 6297 | var stream = { |
|
0 commit comments