提交代码
This commit is contained in:
parent
0a0ff63fec
commit
2dbd0d7764
@ -32,7 +32,7 @@ class AbstractShape {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 拖动
|
// 拖动
|
||||||
draft({dx, dy}) {
|
drift({dx, dy}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置高亮
|
// 设置高亮
|
||||||
|
@ -30,7 +30,7 @@ export default class DragHandle {
|
|||||||
this.$controller.storage.values().forEach(target => {
|
this.$controller.storage.values().forEach(target => {
|
||||||
if (target) {
|
if (target) {
|
||||||
target.shapeFactory.hideHightLight(target);;
|
target.shapeFactory.hideHightLight(target);;
|
||||||
target.draft(e);
|
target.drift(e);
|
||||||
target.shapeFactory.showHightLight(target);
|
target.shapeFactory.showHightLight(target);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import * as graphic from '../core/graphic';
|
import * as graphic from '../core/graphic';
|
||||||
import * as eventTool from 'zrender/src/core/event';
|
import * as eventTool from 'zrender/src/core/event';
|
||||||
|
import Group from 'zrender/src/container/Group';
|
||||||
import shapeRender from '../constant/shapeRender';
|
import shapeRender from '../constant/shapeRender';
|
||||||
|
|
||||||
function shapeStyleBuilder({shape}) {
|
function shapeStyleBuilder({shape}) {
|
||||||
@ -18,7 +19,7 @@ function shapeStyleBuilder({shape}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export default class ImageDraggable extends graphic.Group {
|
export default class ImageDraggable extends Group {
|
||||||
constructor(handle, draggle=false) {
|
constructor(handle, draggle=false) {
|
||||||
super();
|
super();
|
||||||
this.draggle = draggle;
|
this.draggle = draggle;
|
||||||
|
@ -1,23 +1,43 @@
|
|||||||
import AbstractShape from '../core/abstractShape';
|
|
||||||
import shapeEvent from '../constant/shapeEvent';
|
|
||||||
import * as utils from '../utils/utils';
|
import * as utils from '../utils/utils';
|
||||||
|
import * as graphic from '../core/graphic';
|
||||||
|
import Group from 'zrender/src/container/Group';
|
||||||
|
import AbstractShape from '../core/abstractShape';
|
||||||
|
import shapeRender from '../constant/shapeRender';
|
||||||
|
import shapeEvent from '../constant/shapeEvent';
|
||||||
|
|
||||||
class Compose extends AbstractShape {
|
class Compose extends AbstractShape {
|
||||||
constructor(args) {
|
constructor(args) {
|
||||||
super(args);
|
super(args);
|
||||||
|
this.create();
|
||||||
this.hightLightInstance.setShape(this.getBoundingRect());
|
this.hightLightInstance.setShape(this.getBoundingRect());
|
||||||
}
|
}
|
||||||
|
|
||||||
create() {
|
create() {
|
||||||
// this.instance = new Group({});
|
this.instance = new Group({
|
||||||
|
...shapeRender,
|
||||||
|
...this.option,
|
||||||
|
...this.model,
|
||||||
|
shapeInstance: this,
|
||||||
|
});
|
||||||
|
|
||||||
|
// this.instance.transform = utils.createTransform({scale: this.model.scale, position: this.model.position, rotation: this.model.rotation});
|
||||||
|
this.model.elementCodes.forEach(code => {
|
||||||
|
const el = this.shapeFactory.getShapeByCode(code);
|
||||||
|
if (el.instance) {
|
||||||
|
this.shapeFactory.removeFromLevel(el.model.type, el.instance);
|
||||||
|
this.instance.add(el.instance);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
this.instance.dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拖动
|
// 拖动
|
||||||
draft({dx, dy}) {
|
drift({dx, dy}) {
|
||||||
this.model.elementCodes.forEach(code => {
|
this.model.elementCodes.forEach(code => {
|
||||||
const el = this.shapeFactory.getShapeByCode(code);
|
const el = this.shapeFactory.getShapeByCode(code);
|
||||||
if (el) {
|
if (el) {
|
||||||
el.draft({dx, dy});
|
el.drift({dx, dy});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -50,11 +70,11 @@ class Compose extends AbstractShape {
|
|||||||
if (el &&
|
if (el &&
|
||||||
el.model) {
|
el.model) {
|
||||||
el.model.composeCode = this.model.code;
|
el.model.composeCode = this.model.code;
|
||||||
el.attr(el.model)
|
this.shapeFactory.removeFromLevel(el.model.type, el.instance);
|
||||||
|
this.instance.add(el.instance);
|
||||||
|
el.attr(el.model);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解除绑定
|
// 解除绑定
|
||||||
@ -67,6 +87,8 @@ class Compose extends AbstractShape {
|
|||||||
el.model &&
|
el.model &&
|
||||||
el.model.composeCode) {
|
el.model.composeCode) {
|
||||||
el.model.composeCode = '';
|
el.model.composeCode = '';
|
||||||
|
this.remove(el.instance);
|
||||||
|
this.shapeFactory.addToLevel(el.model.type, el.instance);
|
||||||
el.attr(el.model);
|
el.attr(el.model);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -2,6 +2,7 @@ import AbstractShape from '../core/abstractShape';
|
|||||||
import shapeEvent from '../constant/shapeEvent';
|
import shapeEvent from '../constant/shapeEvent';
|
||||||
import * as graphic from '../core/graphic';
|
import * as graphic from '../core/graphic';
|
||||||
import * as utils from '../utils/utils';
|
import * as utils from '../utils/utils';
|
||||||
|
import shapeRender from '../constant/shapeRender';
|
||||||
import shapeLayer from '../constant/shapeLayer';
|
import shapeLayer from '../constant/shapeLayer';
|
||||||
|
|
||||||
class Element extends AbstractShape {
|
class Element extends AbstractShape {
|
||||||
@ -29,6 +30,7 @@ class Element extends AbstractShape {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.instance = new elementBuilder({
|
this.instance = new elementBuilder({
|
||||||
|
...shapeRender,
|
||||||
...this.option,
|
...this.option,
|
||||||
...this.model,
|
...this.model,
|
||||||
shapeInstance: this,
|
shapeInstance: this,
|
||||||
@ -40,7 +42,7 @@ class Element extends AbstractShape {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 拖动
|
// 拖动
|
||||||
draft({dx, dy}) {
|
drift({dx, dy}) {
|
||||||
// const scale = this.instance._scale||[1,1];
|
// const scale = this.instance._scale||[1,1];
|
||||||
// const position = this.instance._position||[0,0];
|
// const position = this.instance._position||[0,0];
|
||||||
|
|
||||||
|
@ -66,6 +66,7 @@ class ShapeFactory extends Eventful {
|
|||||||
this.$map = map;
|
this.$map = map;
|
||||||
this.$painter = map.getPainter();
|
this.$painter = map.getPainter();
|
||||||
this.$controller = map.getController();
|
this.$controller = map.getController();
|
||||||
|
this.$zr = map.getZr();
|
||||||
|
|
||||||
this.border = new graphic.Rect(shapeStyleBuilder());
|
this.border = new graphic.Rect(shapeStyleBuilder());
|
||||||
|
|
||||||
@ -107,11 +108,11 @@ class ShapeFactory extends Eventful {
|
|||||||
try {
|
try {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
zrUtil.each(source.elementList ||[], model => {
|
zrUtil.each(source.elementList ||[], model => {
|
||||||
walk(this.storageShape(this.createShape(model, {...shapeRender, shapeType: shapeType.Element})));
|
walk(this.storageShape(this.createShape(model, {shapeType: shapeType.Element})));
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
zrUtil.each(source.composeList ||[], model => {
|
zrUtil.each(source.composeList ||[], model => {
|
||||||
this.storageShape(this.createShape(model, {...shapeRender, shapeType: shapeType.Compose}));
|
walk(this.storageShape(this.createShape(model, {shapeType: shapeType.Compose})));
|
||||||
}, this);
|
}, this);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[ERROR] ', error);
|
console.error('[ERROR] ', error);
|
||||||
@ -152,46 +153,54 @@ class ShapeFactory extends Eventful {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
showHightLight(instance) {
|
showHightLight(shape) {
|
||||||
const target = this.$controller.getTarget();
|
const target = this.$controller.getTarget();
|
||||||
if (instance.hightLightInstance) {
|
if (shape.hightLightInstance) {
|
||||||
instance.hightLightInstance.setShape(instance.getBoundingRect());
|
shape.hightLightInstance.setShape(shape.getBoundingRect());
|
||||||
this.$painter.addToLevel(shapeLayer.HightLight)(instance.hightLightInstance);
|
this.$painter.addToLevel(shapeLayer.HightLight)(shape.hightLightInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target == instance) {
|
if (target == shape) {
|
||||||
this.showBorder(instance);
|
this.showBorder(shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
instance.attr({ z: shapeRender.z + 9 })
|
shape.attr({ z: shapeRender.z + 9 })
|
||||||
|
|
||||||
instance.active();
|
shape.active();
|
||||||
}
|
}
|
||||||
|
|
||||||
hideHightLight(instance) {
|
hideHightLight(shape) {
|
||||||
const target = this.$controller.getTarget();
|
const target = this.$controller.getTarget();
|
||||||
if (instance.hightLightInstance) {
|
if (shape.hightLightInstance) {
|
||||||
this.$painter.removeFromLevel(shapeLayer.HightLight)(instance.hightLightInstance);
|
this.$painter.removeFromLevel(shapeLayer.HightLight)(shape.hightLightInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target != instance) {
|
if (target != shape) {
|
||||||
this.hideBorder(instance);
|
this.hideBorder(shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
instance.attr({ z: shapeRender.z })
|
shape.attr({ z: shapeRender.z })
|
||||||
|
|
||||||
instance.inactive();
|
shape.inactive();
|
||||||
}
|
}
|
||||||
|
|
||||||
showBorder(instance) {
|
showBorder(shape) {
|
||||||
this.border.setShape(instance.getBoundingRect());
|
this.border.setShape(shape.getBoundingRect());
|
||||||
this.$painter.addToLevel(shapeLayer.HightLight)(this.border);
|
this.$painter.addToLevel(shapeLayer.HightLight)(this.border);
|
||||||
}
|
}
|
||||||
|
|
||||||
hideBorder(instance) {
|
hideBorder(shape) {
|
||||||
this.$painter.removeFromLevel(shapeLayer.HightLight)(this.border);
|
this.$painter.removeFromLevel(shapeLayer.HightLight)(this.border);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addToLevel(level, view) {
|
||||||
|
return this.$painter.addToLevel(level)(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
removeFromLevel(level, view) {
|
||||||
|
return this.$painter.removeFromLevel(level)(view);
|
||||||
|
}
|
||||||
|
|
||||||
isDrawing() {
|
isDrawing() {
|
||||||
this.$map.isDrawing();
|
this.$map.isDrawing();
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ class JMap {
|
|||||||
switch(action.order) {
|
switch(action.order) {
|
||||||
case orders.BINDING:
|
case orders.BINDING:
|
||||||
case orders.ADD:
|
case orders.ADD:
|
||||||
newShape = this.$shapeFactory.createShape(updateModel, {...shapeRender, ...action});
|
newShape = this.$shapeFactory.createShape(updateModel, action);
|
||||||
this.$shapeFactory.storageShape(newShape)
|
this.$shapeFactory.storageShape(newShape)
|
||||||
this.$painter.add(newShape);
|
this.$painter.add(newShape);
|
||||||
break;
|
break;
|
||||||
@ -170,7 +170,7 @@ class JMap {
|
|||||||
break;
|
break;
|
||||||
case orders.UPDATE:
|
case orders.UPDATE:
|
||||||
oldShape = this.$shapeFactory.removeShape(shape);
|
oldShape = this.$shapeFactory.removeShape(shape);
|
||||||
newShape = this.$shapeFactory.createShape(updateModel, {...shapeRender, ...action});
|
newShape = this.$shapeFactory.createShape(updateModel, action);
|
||||||
this.$painter.remove(oldShape);
|
this.$painter.remove(oldShape);
|
||||||
this.$shapeFactory.storageShape(newShape)
|
this.$shapeFactory.storageShape(newShape)
|
||||||
this.$painter.add(newShape);
|
this.$painter.add(newShape);
|
||||||
|
@ -71,6 +71,7 @@ class Painter extends Group {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addToLevel(name) {
|
addToLevel(name) {
|
||||||
|
name = Object.keys(graphic).includes(name)? name: `Group`;
|
||||||
return (view) => {
|
return (view) => {
|
||||||
this.mapShapeLevel[name].add(view);
|
this.mapShapeLevel[name].add(view);
|
||||||
this.$transformHandle.transformView(view);
|
this.$transformHandle.transformView(view);
|
||||||
@ -79,6 +80,7 @@ class Painter extends Group {
|
|||||||
}
|
}
|
||||||
|
|
||||||
removeFromLevel(name) {
|
removeFromLevel(name) {
|
||||||
|
name = Object.keys(graphic).includes(name)? name: `Group`;
|
||||||
return (view) => {
|
return (view) => {
|
||||||
this.mapShapeLevel[name].remove(view);
|
this.mapShapeLevel[name].remove(view);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import * as utils from './utils/utils';
|
import * as utils from './utils/utils';
|
||||||
import * as matrix from 'zrender/src/core/matrix';
|
|
||||||
export default class TransformHandle {
|
export default class TransformHandle {
|
||||||
constructor(painter) {
|
constructor(painter) {
|
||||||
this.$painter = painter;
|
this.$painter = painter;
|
||||||
@ -33,11 +33,7 @@ export default class TransformHandle {
|
|||||||
// 视图进行缩放/平移
|
// 视图进行缩放/平移
|
||||||
transformView(view) {
|
transformView(view) {
|
||||||
if (view) {
|
if (view) {
|
||||||
view.transform = matrix.mul(
|
view.transform = this.transform;
|
||||||
matrix.create(),
|
|
||||||
matrix.copy(matrix.create(), this.transform),
|
|
||||||
utils.createTransform({scale: view.scale, position: view.position, rotation: view.rotation}),
|
|
||||||
);
|
|
||||||
view.decomposeTransform();
|
view.decomposeTransform();
|
||||||
this.visibleView(view);
|
this.visibleView(view);
|
||||||
}
|
}
|
||||||
|
@ -131,8 +131,6 @@ export default {
|
|||||||
code: '1',
|
code: '1',
|
||||||
name: 'a',
|
name: 'a',
|
||||||
type: 'Rect',
|
type: 'Rect',
|
||||||
// scale: [0.5, 0.5],
|
|
||||||
// _position: [100, 0],
|
|
||||||
shape: {
|
shape: {
|
||||||
x: 100,
|
x: 100,
|
||||||
y: 100,
|
y: 100,
|
||||||
@ -149,8 +147,6 @@ export default {
|
|||||||
code: '2',
|
code: '2',
|
||||||
name: 'b',
|
name: 'b',
|
||||||
type: 'Circle',
|
type: 'Circle',
|
||||||
// scale: [0.5, 0.5],
|
|
||||||
// position: [100, 0],
|
|
||||||
shape: {
|
shape: {
|
||||||
cx: 100,
|
cx: 100,
|
||||||
cy: 100,
|
cy: 100,
|
||||||
@ -197,7 +193,6 @@ export default {
|
|||||||
code: '5',
|
code: '5',
|
||||||
name: 'c',
|
name: 'c',
|
||||||
type: 'Droplet',
|
type: 'Droplet',
|
||||||
// scale: [0.5, 0.5],
|
|
||||||
shape: {
|
shape: {
|
||||||
cx: 300,
|
cx: 300,
|
||||||
cy: 200,
|
cy: 200,
|
||||||
@ -232,20 +227,21 @@ export default {
|
|||||||
code: '100',
|
code: '100',
|
||||||
type: 'Device',
|
type: 'Device',
|
||||||
elementCodes: ['1', '2'],
|
elementCodes: ['1', '2'],
|
||||||
composeCode: '1000',
|
// scale: [0.5, 0.5]
|
||||||
|
// composeCode: '1000',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: '101',
|
code: '101',
|
||||||
type: 'Device',
|
type: 'Device',
|
||||||
elementCodes: ['3', '4'],
|
elementCodes: ['3', '4'],
|
||||||
composeCode: '1000'
|
// composeCode: '1000'
|
||||||
},
|
},
|
||||||
{
|
// {
|
||||||
code: '1000',
|
// code: '1000',
|
||||||
type: 'Combine',
|
// type: 'Combine',
|
||||||
elementCodes: ['100', '101'],
|
// elementCodes: ['100', '101'],
|
||||||
composeCode: ''
|
// composeCode: ''
|
||||||
}
|
// }
|
||||||
]
|
]
|
||||||
}, {
|
}, {
|
||||||
panEnable: true,
|
panEnable: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user