UNPKG

@orca-fe/x-map

Version:
42 lines (41 loc) 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const defs_1 = require("../../defs"); const AbstractLayer_1 = require("../AbstractLayer"); const svgNS = 'http://www.w3.org/2000/svg'; class SvgLine extends AbstractLayer_1.AbstractMarker { constructor(options) { super(); this.setLine = (from, to) => { this.from = from; this.to = to; this.updatePosition(); }; this.setStyle = (style) => { Object.entries(style).forEach(([key, value]) => { this.dom.style[key] = value; }); this.updatePosition(); }; this.updatePosition = () => { var _a; if ((_a = this.layer) === null || _a === void 0 ? void 0 : _a.map) { const { map } = this.layer; const pixels = [this.from, this.to].map(position => map.lnglatToPixel(position)); const path = pixels.map(([x, y], index) => `${index === 0 ? 'M' : 'L'}${x} ${y - defs_1.SVG_OFFSET_TOP} `).join(''); this.dom.setAttribute('d', path); } }; const { from, to, style = {} } = options; const dom = document.createElementNS(svgNS, 'path'); this.dom = dom; this.from = from; this.to = to; dom.style.fill = 'none'; dom.style.stroke = 'black'; Object.entries(style).forEach(([key, value]) => { this.dom.style[key] = value; }); } } exports.default = SvgLine;