UNPKG

@orca-fe/x-map

Version:
37 lines (36 loc) 1.41 kB
import { SVG_OFFSET_TOP } from '../../defs'; import { AbstractMarker } from '../AbstractLayer'; const svgNS = 'http://www.w3.org/2000/svg'; export default class SvgPolyline extends AbstractMarker { constructor(options) { super(); this.setPath = (path) => { this.path = path; 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.path.map(position => map.lnglatToPixel(position)); const path = pixels.map(([x, y], index) => `${index === 0 ? 'M' : 'L'}${x} ${y - SVG_OFFSET_TOP} `).join(''); this.dom.setAttribute('d', path); } }; const { path, style = {} } = options; const dom = document.createElementNS(svgNS, 'path'); this.dom = dom; this.path = path; dom.style.fill = 'none'; dom.style.stroke = 'black'; Object.entries(style).forEach(([key, value]) => { this.dom.style[key] = value; }); } }