UNPKG

@orca-fe/x-map

Version:
40 lines (39 loc) 1.52 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 SvgPolyline extends AbstractLayer_1.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 - defs_1.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; }); } } exports.default = SvgPolyline;