index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { __assign, __extends, __rest } from "tslib";
  2. import { isFunction } from '@antv/util';
  3. import { GUI } from '../../core';
  4. import { ifShow, select } from '../../util';
  5. import { bowtie, circle, cross, dash, diamond, dot, hexagon, hv, hvh, hyphen, line, plus, point, smooth, square, tick, triangle, triangleDown, vh, vhv, } from './symbol';
  6. import { parseMarker } from './utils';
  7. function getType(symbol) {
  8. var markerType = parseMarker(symbol);
  9. if (['base64', 'url', 'image'].includes(markerType)) {
  10. return 'image';
  11. }
  12. if (symbol && markerType === 'symbol') {
  13. return 'path';
  14. }
  15. return null;
  16. }
  17. var Marker = /** @class */ (function (_super) {
  18. __extends(Marker, _super);
  19. function Marker() {
  20. return _super !== null && _super.apply(this, arguments) || this;
  21. }
  22. Marker.prototype.render = function (attributes, container) {
  23. var symbol = attributes.symbol, _a = attributes.size, size = _a === void 0 ? 16 : _a, style = __rest(attributes, ["symbol", "size"]);
  24. var type = getType(symbol);
  25. ifShow(!!type, select(container), function (group) {
  26. group
  27. .maybeAppendByClassName("marker", type)
  28. .attr('className', "marker ".concat(type, "-marker"))
  29. .call(function (selection) {
  30. if (type === 'image') {
  31. // todo 大小和 path symbol 保持一致
  32. var r = size * 2;
  33. selection.styles({
  34. img: symbol,
  35. width: r,
  36. height: r,
  37. x: -size,
  38. y: -size,
  39. });
  40. }
  41. else {
  42. var r = size / 2;
  43. var symbolFn = isFunction(symbol) ? symbol : Marker.getSymbol(symbol);
  44. selection.styles(__assign({ path: symbolFn === null || symbolFn === void 0 ? void 0 : symbolFn(0, 0, r) }, style));
  45. }
  46. });
  47. });
  48. };
  49. Marker.MARKER_SYMBOL_MAP = new Map();
  50. /**
  51. * 注册 icon 类型
  52. * @param type
  53. * @param path
  54. */
  55. Marker.registerSymbol = function (type, symbol) {
  56. Marker.MARKER_SYMBOL_MAP.set(type, symbol);
  57. };
  58. /**
  59. * 获取已经注册的 icon 的 path
  60. */
  61. Marker.getSymbol = function (type) {
  62. return Marker.MARKER_SYMBOL_MAP.get(type);
  63. };
  64. return Marker;
  65. }(GUI));
  66. export { Marker };
  67. /** Shapes for Point Geometry */
  68. Marker.registerSymbol('cross', cross);
  69. Marker.registerSymbol('hyphen', hyphen);
  70. Marker.registerSymbol('line', line);
  71. Marker.registerSymbol('plus', plus);
  72. Marker.registerSymbol('tick', tick);
  73. Marker.registerSymbol('circle', circle);
  74. Marker.registerSymbol('point', point);
  75. Marker.registerSymbol('bowtie', bowtie);
  76. Marker.registerSymbol('hexagon', hexagon);
  77. Marker.registerSymbol('square', square);
  78. Marker.registerSymbol('diamond', diamond);
  79. Marker.registerSymbol('triangle', triangle);
  80. Marker.registerSymbol('triangle-down', triangleDown);
  81. /** LineSymbols */
  82. Marker.registerSymbol('line', line);
  83. Marker.registerSymbol('dot', dot);
  84. Marker.registerSymbol('dash', dash);
  85. Marker.registerSymbol('smooth', smooth);
  86. Marker.registerSymbol('hv', hv);
  87. Marker.registerSymbol('vh', vh);
  88. Marker.registerSymbol('hvh', hvh);
  89. Marker.registerSymbol('vhv', vhv);
  90. //# sourceMappingURL=index.js.map