|
1912 | 1912 | }; |
1913 | 1913 | return albers; |
1914 | 1914 | } |
| 1915 | + function d3_geo_antemeridianLine(rotate, p) { |
| 1916 | + return function(lineString, context) { |
| 1917 | + d3_geo_antemeridianClipLine(rotate, lineString, d3_geo_antemeridianContext(p, context)); |
| 1918 | + }; |
| 1919 | + } |
| 1920 | + function d3_geo_antemeridianRing(rotate, p) { |
| 1921 | + return function(ring, context) { |
| 1922 | + d3_geo_antemeridianClipLine(rotate, ring, d3_geo_antemeridianContext(p, context)); |
| 1923 | + context.closePath(); |
| 1924 | + }; |
| 1925 | + } |
| 1926 | + function d3_geo_antemeridianClipLine(rotate, lineString, context) { |
| 1927 | + if (!(n = lineString.length)) return; |
| 1928 | + var point = rotate(lineString[0]); |
| 1929 | + context.moveTo(λ0 = point[0], φ0 = point[1]); |
| 1930 | + for (var λ0, φ0, i = 0, j = 0, n; j < n; j++) { |
| 1931 | + point = rotate(lineString[j]); |
| 1932 | + var λ1 = point[0], φ1 = point[1], δλ = (Math.abs(λ1 - λ0) + 2 * π) % (2 * π), sλ0 = λ0 > 0; |
| 1933 | + if (j > i && sλ0 ^ λ1 > 0 && (δλ >= π || δλ < ε && Math.abs(Math.abs(λ0) - π) < ε)) { |
| 1934 | + φ0 = d3_geo_antemeridianIntersect(λ0, φ0, λ1, φ1); |
| 1935 | + context.lineTo(sλ0 ? π : -π, φ0); |
| 1936 | + context.moveTo(sλ0 ? -π : π, φ0); |
| 1937 | + } |
| 1938 | + context.lineTo(λ0 = λ1, φ0 = φ1); |
| 1939 | + } |
| 1940 | + } |
| 1941 | + function d3_geo_antemeridianIntersect(λ0, φ0, λ1, φ1) { |
| 1942 | + var cosφ0, cosφ1, sinλ0_λ1 = Math.sin(λ0 - λ1); |
| 1943 | + return Math.abs(sinλ0_λ1) > ε ? Math.atan((Math.sin(φ0) * (cosφ1 = Math.cos(φ1)) * Math.sin(λ1) - Math.sin(φ1) * (cosφ0 = Math.cos(φ0)) * Math.sin(λ0)) / (cosφ0 * cosφ1 * sinλ0_λ1)) : (φ0 + φ1) / 2; |
| 1944 | + } |
| 1945 | + function d3_geo_antemeridianContext(p, context) { |
| 1946 | + return { |
| 1947 | + moveTo: function(x, y) { |
| 1948 | + var point = p(x, y); |
| 1949 | + context.moveTo(point[0], point[1]); |
| 1950 | + }, |
| 1951 | + lineTo: function(x, y) { |
| 1952 | + var point = p(x, y); |
| 1953 | + context.lineTo(point[0], point[1]); |
| 1954 | + }, |
| 1955 | + closePath: function() { |
| 1956 | + context.closePath(); |
| 1957 | + } |
| 1958 | + }; |
| 1959 | + } |
1915 | 1960 | function d3_geo_bounds(o, f) { |
1916 | 1961 | if (d3_geo_boundsTypes.hasOwnProperty(o.type)) d3_geo_boundsTypes[o.type](o, f); |
1917 | 1962 | } |
|
2031 | 2076 | return [ coordinates[0] * d3_degrees, coordinates[1] * d3_degrees ]; |
2032 | 2077 | } |
2033 | 2078 | function reset() { |
2034 | | - projectRotate = d3_geo_compose(d3_geo_rotation(δλ, δφ, δγ), project); |
| 2079 | + projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project); |
2035 | 2080 | var center = project(λ, φ); |
2036 | 2081 | δx = x - center[0] * k; |
2037 | 2082 | δy = y + center[1] * k; |
2038 | 2083 | return p; |
2039 | 2084 | } |
2040 | | - var project, projectRotate, k = 150, x = 480, y = 250, λ = 0, φ = 0, δλ = 0, δφ = 0, δγ = 0, δx = x, δy = y; |
| 2085 | + function rotateLocation(coordinates) { |
| 2086 | + return rotate(coordinates[0] * π / 180, coordinates[1] * π / 180); |
| 2087 | + } |
| 2088 | + function transformPoint(λ, φ) { |
| 2089 | + var point = project(λ, φ); |
| 2090 | + return [ point[0] * k + δx, δy - point[1] * k ]; |
| 2091 | + } |
| 2092 | + var project, rotate, projectRotate, k = 150, x = 480, y = 250, λ = 0, φ = 0, δλ = 0, δφ = 0, δγ = 0, δx = x, δy = y; |
2041 | 2093 | p.point = function(coordinates, context) { |
2042 | 2094 | var point = p(coordinates); |
2043 | 2095 | context.point(point[0], point[1]); |
2044 | 2096 | }; |
2045 | | - p.line = function(coordinates, context) { |
2046 | | - var point = p(coordinates[0]), i = 0, n = coordinates.length; |
2047 | | - context.moveTo(point[0], point[1]); |
2048 | | - while (++i < n) context.lineTo((point = p(coordinates[i]))[0], point[1]); |
2049 | | - }; |
2050 | | - p.ring = function(coordinates, context) { |
2051 | | - p.line(coordinates, context); |
2052 | | - context.closePath(); |
2053 | | - }; |
| 2097 | + p.line = d3_geo_antemeridianLine(rotateLocation, transformPoint); |
| 2098 | + p.ring = d3_geo_antemeridianRing(rotateLocation, transformPoint); |
2054 | 2099 | p.scale = function(_) { |
2055 | 2100 | if (!arguments.length) return k; |
2056 | 2101 | k = +_; |
|
2707 | 2752 | d3 = { |
2708 | 2753 | version: "2.10.2" |
2709 | 2754 | }; |
2710 | | - var π = Math.PI, d3_radians = π / 180, d3_degrees = 180 / π; |
| 2755 | + var π = Math.PI, ε = 1e-6, d3_radians = π / 180, d3_degrees = 180 / π; |
2711 | 2756 | var d3_array = d3_arraySlice; |
2712 | 2757 | try { |
2713 | 2758 | d3_array(document.documentElement.childNodes)[0].nodeType; |
|
6218 | 6263 | } |
6219 | 6264 | var x1 = 180, x0 = -x1, y1 = 90, y0 = -y1, dx = 22.5, dy = dx; |
6220 | 6265 | graticule.lines = function() { |
6221 | | - var xLines = d3.range(Math.ceil(x0 / dx) * dx, y0, dx).map(function(x) { |
6222 | | - return [ y0, y1 ].map(function(y) { |
| 6266 | + var xSteps = d3.range(Math.ceil(x0 / dx) * dx, x1, dx).concat(x1), ySteps = d3.range(Math.ceil(y0 / dy) * dy, y1, dy).concat(y1), xLines = xSteps.map(function(x) { |
| 6267 | + return ySteps.map(function(y) { |
6223 | 6268 | return [ x, y ]; |
6224 | 6269 | }); |
6225 | | - }), yLines = d3.range(Math.ceil(x1 / dy) * dy, y1, dy).map(function(y) { |
6226 | | - return [ x0, x1 ].map(function(x) { |
| 6270 | + }), yLines = ySteps.map(function(y) { |
| 6271 | + return xSteps.map(function(x) { |
6227 | 6272 | return [ x, y ]; |
6228 | 6273 | }); |
6229 | 6274 | }); |
|
0 commit comments