No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

65 líneas
2.0 KiB

  1. import {geoEquirectangular, geoOrthographic} from "d3-geo";
  2. import {asin, atan, degrees, radians, sin, tan} from "./math.js";
  3. function gilbertForward(point) {
  4. return [point[0] / 2, asin(tan(point[1] / 2 * radians)) * degrees];
  5. }
  6. function gilbertInvert(point) {
  7. return [point[0] * 2, 2 * atan(sin(point[1] * radians)) * degrees];
  8. }
  9. export default function(projectionType) {
  10. if (projectionType == null) projectionType = geoOrthographic;
  11. var projection = projectionType(),
  12. equirectangular = geoEquirectangular().scale(degrees).precision(0).clipAngle(null).translate([0, 0]); // antimeridian cutting
  13. function gilbert(point) {
  14. return projection(gilbertForward(point));
  15. }
  16. if (projection.invert) gilbert.invert = function(point) {
  17. return gilbertInvert(projection.invert(point));
  18. };
  19. gilbert.stream = function(stream) {
  20. var s1 = projection.stream(stream), s0 = equirectangular.stream({
  21. point: function(lambda, phi) { s1.point(lambda / 2, asin(tan(-phi / 2 * radians)) * degrees); },
  22. lineStart: function() { s1.lineStart(); },
  23. lineEnd: function() { s1.lineEnd(); },
  24. polygonStart: function() { s1.polygonStart(); },
  25. polygonEnd: function() { s1.polygonEnd(); }
  26. });
  27. s0.sphere = s1.sphere;
  28. return s0;
  29. };
  30. function property(name) {
  31. gilbert[name] = function() {
  32. return arguments.length ? (projection[name].apply(projection, arguments), gilbert) : projection[name]();
  33. };
  34. }
  35. gilbert.rotate = function(_) {
  36. return arguments.length ? (equirectangular.rotate(_), gilbert) : equirectangular.rotate();
  37. };
  38. gilbert.center = function(_) {
  39. return arguments.length ? (projection.center(gilbertForward(_)), gilbert) : gilbertInvert(projection.center());
  40. };
  41. property("angle");
  42. property("clipAngle");
  43. property("clipExtent");
  44. property("fitExtent");
  45. property("fitHeight");
  46. property("fitSize");
  47. property("fitWidth");
  48. property("scale");
  49. property("translate");
  50. property("precision");
  51. return gilbert
  52. .scale(249.5);
  53. }