UNPKG

@orca-fe/x-map

Version:
31 lines (30 loc) 968 B
import { SVG_OFFSET_TOP } from '../defs'; import AbstractLayer from './AbstractLayer'; const svgNS = 'http://www.w3.org/2000/svg'; export default class SvgLayer extends AbstractLayer { constructor(options = {}) { super(); const dom = document.createElementNS(svgNS, 'svg'); dom.style.position = 'absolute'; dom.style.top = `${SVG_OFFSET_TOP}px`; dom.style.left = '0'; dom.style.overflow = 'visible'; this.dom = dom; } add(marker) { this.markers.add(marker); this.dom.appendChild(marker.dom); marker.setLayer(this); } remove(marker) { this.markers.delete(marker); if (this.dom.contains(marker.dom)) { this.dom.removeChild(marker.dom); } marker.setLayer(undefined); } getSize() { const { clientWidth, clientHeight } = this.dom; return [clientWidth, clientHeight]; } }