修改函数名称

This commit is contained in:
ival 2021-04-01 22:11:01 +08:00
parent 2dbd0d7764
commit 6ebbdec414
6 changed files with 37 additions and 37 deletions

View File

@ -24,7 +24,7 @@ class Compose extends AbstractShape {
this.model.elementCodes.forEach(code => {
const el = this.shapeFactory.getShapeByCode(code);
if (el.instance) {
this.shapeFactory.removeFromLevel(el.model.type, el.instance);
this.shapeFactory.removeFromLayer(el.model.type, el.instance);
this.instance.add(el.instance);
}
})
@ -70,7 +70,7 @@ class Compose extends AbstractShape {
if (el &&
el.model) {
el.model.composeCode = this.model.code;
this.shapeFactory.removeFromLevel(el.model.type, el.instance);
this.shapeFactory.removeFromLayer(el.model.type, el.instance);
this.instance.add(el.instance);
el.attr(el.model);
}
@ -88,7 +88,7 @@ class Compose extends AbstractShape {
el.model.composeCode) {
el.model.composeCode = '';
this.remove(el.instance);
this.shapeFactory.addToLevel(el.model.type, el.instance);
this.shapeFactory.addToLayer(el.model.type, el.instance);
el.attr(el.model);
}
})

View File

@ -104,15 +104,15 @@ class ShapeFactory extends Eventful {
})
}
parse(source={}, walk=None) {
parse(source={}, take=None) {
try {
this.source = source;
zrUtil.each(source.elementList ||[], model => {
walk(this.storageShape(this.createShape(model, {shapeType: shapeType.Element})));
take(this.storageShape(this.createShape(model, {shapeType: shapeType.Element})));
}, this);
zrUtil.each(source.composeList ||[], model => {
walk(this.storageShape(this.createShape(model, {shapeType: shapeType.Compose})));
take(this.storageShape(this.createShape(model, {shapeType: shapeType.Compose})));
}, this);
} catch (error) {
console.error('[ERROR] ', error);
@ -157,7 +157,7 @@ class ShapeFactory extends Eventful {
const target = this.$controller.getTarget();
if (shape.hightLightInstance) {
shape.hightLightInstance.setShape(shape.getBoundingRect());
this.$painter.addToLevel(shapeLayer.HightLight)(shape.hightLightInstance);
this.$painter.addToLayer(shapeLayer.HightLight)(shape.hightLightInstance);
}
if (target == shape) {
@ -172,7 +172,7 @@ class ShapeFactory extends Eventful {
hideHightLight(shape) {
const target = this.$controller.getTarget();
if (shape.hightLightInstance) {
this.$painter.removeFromLevel(shapeLayer.HightLight)(shape.hightLightInstance);
this.$painter.removeFromLayer(shapeLayer.HightLight)(shape.hightLightInstance);
}
if (target != shape) {
@ -186,19 +186,19 @@ class ShapeFactory extends Eventful {
showBorder(shape) {
this.border.setShape(shape.getBoundingRect());
this.$painter.addToLevel(shapeLayer.HightLight)(this.border);
this.$painter.addToLayer(shapeLayer.HightLight)(this.border);
}
hideBorder(shape) {
this.$painter.removeFromLevel(shapeLayer.HightLight)(this.border);
this.$painter.removeFromLayer(shapeLayer.HightLight)(this.border);
}
addToLevel(level, view) {
return this.$painter.addToLevel(level)(view);
addToLayer(level, view) {
return this.$painter.addToLayer(level)(view);
}
removeFromLevel(level, view) {
return this.$painter.removeFromLevel(level)(view);
removeFromLayer(level, view) {
return this.$painter.removeFromLayer(level)(view);
}
isDrawing() {

View File

@ -41,13 +41,13 @@ export default class TipsHandle {
const painter = this.$map.getPainter();
this.message.setStyle({ x, y, text });
painter.addToLevel(shapeLayer.Tips)(this.message);
painter.addToLayer(shapeLayer.Tips)(this.message);
}
onHide(e) {
const painter = this.$map.getPainter();
painter.removeFromLevel(shapeLayer.Tips)(this.message);
painter.removeFromLayer(shapeLayer.Tips)(this.message);
this.message.setStyle('text', '');
}
}

View File

@ -16,7 +16,7 @@ class Painter extends Group {
initLevels(map) {
// 初始化图层对象
this.mapShapeLevel = {};
this.mapShapeLayer = {};
// 获取顶层图层
this.$zr = map.getZr();
@ -25,34 +25,34 @@ class Painter extends Group {
this.$zr.add(this);
// 创建select图层
this.mapShapeLevel[shapeLayer.SelectIng] = new Group({ name: shapeLayer.SelectIng });
this.mapShapeLayer[shapeLayer.SelectIng] = new Group({ name: shapeLayer.SelectIng });
// 创建hover图层
this.mapShapeLevel[shapeLayer.HightLight] = new Group({ name: shapeLayer.HightLight });
this.mapShapeLayer[shapeLayer.HightLight] = new Group({ name: shapeLayer.HightLight });
// 创建tips图层
this.mapShapeLevel[shapeLayer.Tips] = new Group({name: shapeLayer.Tips });
this.mapShapeLayer[shapeLayer.Tips] = new Group({name: shapeLayer.Tips });
// 创建元素图层
Object.keys(graphic).forEach(key => {
this.mapShapeLevel[key] = new Group({name: `__${key}__`});
this.mapShapeLayer[key] = new Group({name: `__${key}__`});
})
// 添加图层
Object.values(this.mapShapeLevel).forEach(el => {
Object.values(this.mapShapeLayer).forEach(el => {
super.add(el);
})
}
add(shape) {
if (shape && shape.instance) {
this.addToLevel(shape.model.type)(shape.instance);
this.addToLayer(shape.model.type)(shape.instance);
}
}
remove(shape) {
if (shape && shape.instance) {
this.removeFromLevel(shape.model.type)(shape.instance);
this.removeFromLayer(shape.model.type)(shape.instance);
}
}
@ -70,35 +70,35 @@ class Painter extends Group {
this.$transformHandle.updateZrSize(opt);
}
addToLevel(name) {
addToLayer(name) {
name = Object.keys(graphic).includes(name)? name: `Group`;
return (view) => {
this.mapShapeLevel[name].add(view);
this.mapShapeLayer[name].add(view);
this.$transformHandle.transformView(view);
this.dirty();
}
}
removeFromLevel(name) {
removeFromLayer(name) {
name = Object.keys(graphic).includes(name)? name: `Group`;
return (view) => {
this.mapShapeLevel[name].remove(view);
this.mapShapeLayer[name].remove(view);
}
}
getLevelByName(name) {
return this.mapShapeLevel[name];
return this.mapShapeLayer[name];
}
clear() {
Object.values(this.mapShapeLevel).forEach(el => {
Object.values(this.mapShapeLayer).forEach(el => {
el.removeAll();
})
}
destroy() {
this.clear();
this.mapShapeLevel = {};
this.mapShapeLayer = {};
}
}

View File

@ -39,7 +39,7 @@ export default class SelectingHandle {
onSelectStart(e) {
this.selecting.setShape({ x: e.x, y: e.y, width: 0, height: 0 });
this.$painter.addToLevel(shapeLayer.SelectIng)(this.selecting);
this.$painter.addToLayer(shapeLayer.SelectIng)(this.selecting);
this.begPoint = { x: e.x, y: e.y };
this.endPoint = null;
}
@ -47,13 +47,13 @@ export default class SelectingHandle {
onSelecting(e) {
this.endPoint = { x: e.x, y: e.y };
this.selecting.setShape(this.normalizedArea(this.begPoint, this.endPoint));
this.$painter.addToLevel(shapeLayer.SelectIng)(this.selecting);
this.$painter.addToLayer(shapeLayer.SelectIng)(this.selecting);
}
onSelectEnd(e) {
this.endPoint = { x: e.x, y: e.y };
this.selecting.setShape(this.normalizedArea(this.begPoint, this.endPoint));
this.$painter.addToLevel(shapeLayer.SelectIng)(this.selecting);
this.$painter.addToLayer(shapeLayer.SelectIng)(this.selecting);
const selectingRect = this.selecting.getBoundingRect();
Object.values(this.$map.getMapShape()).forEach(el => {
@ -72,7 +72,7 @@ export default class SelectingHandle {
}
clear() {
this.$painter.removeFromLevel(shapeLayer.SelectIng)(this.selecting);
this.$painter.removeFromLayer(shapeLayer.SelectIng)(this.selecting);
}
checkSelectingRectContainShape(rect, shape) {

View File

@ -63,8 +63,8 @@ export default class TransformHandle {
// 遍历group执行回调
traverse(cb, context) {
this.$painter.eachChild(level => {
level.eachChild((view) => {
this.$painter.eachChild(layer => {
layer.eachChild((view) => {
cb.call(context, view);
}, context);
}, context);