@orca-fe/x-map
Version:
37 lines (36 loc) • 1.17 kB
JavaScript
import AbstractLayer from './AbstractLayer';
export default class BaseLayer extends AbstractLayer {
constructor(options = {}) {
super();
this.add = (marker) => {
this.markers.add(marker);
this.dom.appendChild(marker.dom);
marker.setLayer(this);
};
this.remove = (marker) => {
this.markers.delete(marker);
if (this.dom.contains(marker.dom)) {
this.dom.removeChild(marker.dom);
}
marker.setLayer(undefined);
};
const { style } = options;
const dom = document.createElement('div');
dom.style.position = 'absolute';
dom.style.top = '0';
dom.style.left = '0';
dom.style.width = '0';
dom.style.height = '0';
dom.style.zIndex = '0';
if (style) {
Object.entries(style).forEach(([key, value]) => {
dom.style[key] = value;
});
}
this.dom = dom;
}
getSize() {
const { clientWidth, clientHeight } = this.dom;
return [clientWidth, clientHeight];
}
}