mirror of https://gitee.com/antv-l7/antv-l7
refactor(core): layer register
This commit is contained in:
parent
abe1258adf
commit
712e983b3e
|
@ -1,5 +1,5 @@
|
|||
import Engine from './engine';
|
||||
import * as layers from '../layer';
|
||||
import { LAYER_MAP } from '../layer';
|
||||
import Base from './base';
|
||||
import LoadImage from './image';
|
||||
import WorkerPool from './worker';
|
||||
|
@ -48,14 +48,14 @@ export default class Scene extends Base {
|
|||
|
||||
}
|
||||
initLayer() {
|
||||
for (const methodName in layers) {
|
||||
this[methodName] = cfg => {
|
||||
cfg ? cfg.mapType = this.mapType : cfg = { mapType: this.mapType };
|
||||
const layer = new layers[methodName](this, cfg);
|
||||
for (const key in LAYER_MAP) {
|
||||
Scene.prototype[key] = cfg => {
|
||||
const layer = new LAYER_MAP[key](this, cfg);
|
||||
this._layers.push(layer);
|
||||
return layer;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
on(type, hander) {
|
||||
if (this.map) { this.map.on(type, hander); }
|
||||
|
@ -83,14 +83,6 @@ export default class Scene extends Base {
|
|||
getLayers() {
|
||||
return this._layers;
|
||||
}
|
||||
_addLight() {
|
||||
// const scene = this._engine._scene;
|
||||
// //const ambientLight = new THREE.AmbientLight(0xaaaaaa);
|
||||
// scene.add(ambientLight);
|
||||
|
||||
// const directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);
|
||||
// scene.add(directionalLight);
|
||||
}
|
||||
_addLayer() {
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
export const LAYER_MAP = {};
|
||||
export const getLayer = type => {
|
||||
return LAYER_MAP[type.toLowerCase()];
|
||||
};
|
||||
export const registerLayer = (type, layer) => {
|
||||
if (getLayer(type)) {
|
||||
throw new Error(`Layer type '${type}' existed.`);
|
||||
}
|
||||
// 存储到 map 中
|
||||
LAYER_MAP[type] = layer;
|
||||
};
|
|
@ -1,3 +1,17 @@
|
|||
import { registerLayer } from './factory';
|
||||
import PolygonLayer from './polygonLayer';
|
||||
import PointLayer from './pointLayer';
|
||||
import LineLayer from './lineLayer';
|
||||
import ImageLayer from './imageLayer';
|
||||
import RasterLayer from './rasterLayer';
|
||||
|
||||
registerLayer('PolygonLayer', PolygonLayer);
|
||||
registerLayer('PointLayer', PointLayer);
|
||||
registerLayer('LineLayer', LineLayer);
|
||||
registerLayer('ImageLayer', ImageLayer);
|
||||
registerLayer('RasterLayer', RasterLayer);
|
||||
|
||||
export { LAYER_MAP } from './factory';
|
||||
export { default as PolygonLayer } from './polygonLayer';
|
||||
export { default as PointLayer } from './pointLayer';
|
||||
export { default as LineLayer } from './lineLayer';
|
||||
|
|
Loading…
Reference in New Issue