@orca-fe/x-map
Version:
25 lines (24 loc) • 1.11 kB
JavaScript
import { SVG_OFFSET_TOP } from '../../defs';
import SvgLine from './SvgLine';
import { getCPoints } from '../../utils/math';
export default class SvgArcLine extends SvgLine {
constructor(options) {
super(options);
this.setAlpha = (alpha) => {
this.alpha = alpha;
this.updatePosition();
};
this.updatePosition = () => {
var _a;
if ((_a = this.layer) === null || _a === void 0 ? void 0 : _a.map) {
const { map } = this.layer;
const [fromPixel, toPixel] = [this.from, this.to].map(position => map.lnglatToPixel(position));
const bAlpha = toPixel[0] < fromPixel[0] ? 1 : -1;
const { cp } = getCPoints(fromPixel, toPixel, this.alpha * bAlpha);
this.dom.setAttribute('d', `M${fromPixel[0]} ${fromPixel[1] - SVG_OFFSET_TOP}Q${Math.round(cp[0])} ${Math.round(cp[1] - SVG_OFFSET_TOP)} ${toPixel[0]} ${toPixel[1] - SVG_OFFSET_TOP}`);
}
};
const { alpha = 3 } = options;
this.alpha = alpha;
}
}