修改代码

This commit is contained in:
ival 2021-04-07 15:39:32 +08:00
parent e1a75e68a1
commit fc2e4137f5
9 changed files with 278 additions and 28 deletions

View File

@ -14,7 +14,7 @@ class MouseEvent {
this.clientX = e.event.clientX; this.clientX = e.event.clientX;
this.clientY = e.event.clientY; this.clientY = e.event.clientY;
if (shape && !['__selecting__', '__drag__'].includes(shape.subType)) { if (shape && !['@selecting', '@border', '@drag'].includes(shape.subType)) {
if (shape.code) { if (shape.code) {
let composeCode = shape.composeCode; let composeCode = shape.composeCode;
let compose = null; let compose = null;
@ -142,7 +142,7 @@ export default class Controller extends Eventful {
} }
isSpecialSubType(e) { isSpecialSubType(e) {
return ['__drag__', '__selecting__'].includes(e.subType); return ['@drag', '@selecting'].includes(e.subType);
} }
isSelected(code) { isSelected(code) {

View File

@ -8,7 +8,7 @@ import shapeRender from '../constant/shapeRender';
function shapeStyleBuilder({shape}) { function shapeStyleBuilder({shape}) {
return { return {
...shapeRender, ...shapeRender,
subType: '__drag__', subType: '@drag',
z: 9998, z: 9998,
draggable: false, draggable: false,
cursor: 'crosshair', cursor: 'crosshair',
@ -81,7 +81,7 @@ export default class ImageDraggable extends Group {
} }
mousedown(e) { mousedown(e) {
if (e.target && ['__selecting__', '__drag__'].includes(e.target.subType)) { if (e.target && ['@selecting', '@border', '@drag'].includes(e.target.subType)) {
if (!eventTool.isMiddleOrRightButtonOnMouseUpDown(e)) { if (!eventTool.isMiddleOrRightButtonOnMouseUpDown(e)) {
this.target = e.target; this.target = e.target;
this.offset = {x: e.offsetX, y: e.offsetY}; this.offset = {x: e.offsetX, y: e.offsetY};

View File

@ -6,7 +6,7 @@ import shapeRender from '../constant/shapeRender';
function lineStyleBuilder() { function lineStyleBuilder() {
return { return {
...shapeRender, ...shapeRender,
subType: '__drag__', subType: '@drag',
z: 9998, z: 9998,
shape: {x1: 0, y1: 0, x2: 0, y2: 0 }, shape: {x1: 0, y1: 0, x2: 0, y2: 0 },
style: { style: {
@ -19,7 +19,7 @@ function lineStyleBuilder() {
function circleStyleBuilder({shape}) { function circleStyleBuilder({shape}) {
return { return {
...shapeRender, ...shapeRender,
subType: '__drag__', subType: '@drag',
z: 9999, z: 9999,
draggable: false, draggable: false,
cursor: 'crosshair', cursor: 'crosshair',
@ -79,7 +79,7 @@ export default class LineDraggable extends graphic.Group {
mousedown(e) { mousedown(e) {
this.offset = {x: e.offsetX, y: e.offsetY}; this.offset = {x: e.offsetX, y: e.offsetY};
if (e.target && ['__drag__'].includes(e.target.subType)) { if (e.target && ['@drag'].includes(e.target.subType)) {
this.target = e.target; this.target = e.target;
if (!eventTool.isMiddleOrRightButtonOnMouseUpDown(e)) { if (!eventTool.isMiddleOrRightButtonOnMouseUpDown(e)) {
this.setDraggable(true); this.setDraggable(true);

View File

@ -69,7 +69,7 @@ class ShapeFactory extends Eventful {
this.$painter = map.getPainter(); this.$painter = map.getPainter();
this.$controller = map.getController(); this.$controller = map.getController();
this.border = new graphic.Rect(shapeStyleBuilder()); this.border = new graphic.Rect(shapeStyleBuilder({subType: '@border'}));
this.tipsHandle = new TipsHandle(map); this.tipsHandle = new TipsHandle(map);

View File

@ -9,6 +9,7 @@ import Controller from './controller';
import StateHandle from './stateHandle'; import StateHandle from './stateHandle';
import ShapeFactory from './factory'; import ShapeFactory from './factory';
import orders from './utils/orders'; import orders from './utils/orders';
import ModelBuilder from './modelBuilder';
const renderer = 'canvas'; const renderer = 'canvas';
const devicePixelRatio = 1; const devicePixelRatio = 1;
@ -69,6 +70,9 @@ class JMap {
// 状态处理器 // 状态处理器
this.$stateHandle = new StateHandle(this); this.$stateHandle = new StateHandle(this);
// 绘制模块
this.modelBuilder = new ModelBuilder(this.getZr());
this.disable = function() { this.disable = function() {
this.off(this.events.Pan, optionHandler); this.off(this.events.Pan, optionHandler);
this.off(this.events.Zoom, optionHandler); this.off(this.events.Zoom, optionHandler);

View File

@ -0,0 +1,44 @@
class Handle {
constructor() {
}
onmousedown(e) {
// console.log('mousedown', e)
}
onmousemove(e) {
// console.log('mousemove', e)
}
onmouseup(e) {
// console.log('mouseup', e)
}
}
class ModelBuilder {
constructor(zr) {
this.zr = zr;
this.handle = new Handle();
}
addEventListener() {
if (this.zr) {
this.zr.on('mousedown', this.handle.onmousedown, this.handle);
this.zr.on('mousemove', this.handle.onmousemove, this.handle);
this.zr.on('mouseup', this.handle.onmouseup, this.handle);
}
}
removeEventListener() {
if (this.zr) {
this.zr.off('mousedown', this.handle.onmousedown);
this.zr.off('mousemove', this.handle.onmousemove);
this.zr.off('mouseup', this.handle.onmouseup);
}
}
buildModel(shapeType) {
}
}
export default ModelBuilder;

View File

@ -1,10 +1,10 @@
class Option { class Option {
constructor(opts, notice) { constructor(opts, notice) {
this.ratio = 10; this.ratio = 100;
this.step = 1/this.ratio; this.step = 0.1;
this.scaleMin = 0.2; this.scaleMin = 0.3;
this.scaleMax = 10; this.scaleMax = 10;
@ -51,9 +51,9 @@ class Option {
getScaleRate(scale) { getScaleRate(scale) {
if (Number.isFinite(scale)) { if (Number.isFinite(scale)) {
const sumScaleNum = (this.scaleRate - this.scaleMin + scale * this.step) * this.ratio; const sumScaleNum = parseInt((this.scaleRate - this.scaleMin + scale * this.step) * this.ratio);
const maxScaleNum = (this.scaleMax * this.ratio); const maxScaleNum = this.scaleMax * this.ratio;
return (sumScaleNum%maxScaleNum) / this.ratio + this.scaleMin; return sumScaleNum > 0? ((sumScaleNum%maxScaleNum) / this.ratio + this.scaleMin).toFixed(1): this.scaleRate;
} }
return this.scaleRate; return this.scaleRate;
} }

View File

@ -3,22 +3,222 @@ import shapeRender from './constant/shapeRender';
import shapeLayer from './constant/shapeLayer'; import shapeLayer from './constant/shapeLayer';
import defaultStyle from './config/defaultStyle'; import defaultStyle from './config/defaultStyle';
function shapeStyleBuilder() { const vernierStyle = {
return { area: {
subType: '__selecting__', areaStyle: {
...shapeRender,
z: 9999,
shape: {
x: 0,
y: 0,
width: 0,
height: 0
},
style: {
fill: `rgba(200,200,200,0.3)` fill: `rgba(200,200,200,0.3)`
} }
},
axisLine: {
lineStyle: {
lineWidth: 30,
stroke: 'rgba(255,255,255,0.6)',
shadowBlur: 17,
shadowColor: 'rgba(0,255,0,0.2)',
strokeNoScale: true
}
},
axisTick: {
length: 5,
lineStyle: {
lineWidth: 2,
stroke: '#000000'
}
},
axisLabel: {
distance: 3,
textStyle: {
textStroke: '#000',
textAlign: 'center',
textVerticalAlign: 'center'
}
} }
} }
class Vernier extends graphic.Group {
constructor(args) {
super(args);
this._scaleRate = 1;
this.area = null;
this.axisLineX = null;
this.axisLineY = null;
}
_area(rect) {
this.area = new graphic.Rect({
...shapeRender,
z: 9999,
silent: true,
shape: { ...rect },
style: {
...vernierStyle.area.areaStyle
}
})
this.add(this.area);
}
_lineAxisX(rect) {
const minX = Math.min(rect.x, rect.x + rect.width);
const minY = Math.min(rect.y, rect.y + rect.height)
const maxX = Math.max(rect.x, rect.x + rect.width);
const axisLineWidthHalf = vernierStyle.axisLine.lineStyle.lineWidth/this._scaleRate/2;
this.axisLineX = new graphic.Line({
...shapeRender,
z: 9999,
silent: true,
position: [0, -axisLineWidthHalf],
shape: {
x1: minX,
y1: minY,
x2: maxX,
y2: minY
},
style: {
...vernierStyle.axisLine.lineStyle,
shadowOffsetX: -5
}
})
const step = 4/this._scaleRate;
const count = parseInt(Math.abs(rect.width/step));
for(var i = 0; i in new Array(count).fill(0); i++) {
const offset = step * i;
const tick = i % vernierStyle.axisTick.length == 0
const len = tick? axisLineWidthHalf*0.8: axisLineWidthHalf*0.5;
if (tick) {
this.add(new graphic.Text({
...shapeRender,
z: 10000,
silent: true,
position: [minX + offset, minY - axisLineWidthHalf - vernierStyle.axisLabel.distance],
style: {
...vernierStyle.axisLabel.textStyle,
text: i / vernierStyle.axisTick.length
}
}))
}
this.add(new graphic.Line({
...shapeRender,
z: 10000,
silent: true,
shape: {
x1: minX + offset,
y1: minY,
x2: minX + offset,
y2: minY - len
},
style: {
...vernierStyle.axisTick.lineStyle,
strokeNoScale: true,
}
}))
}
this.add(this.axisLineX);
}
_lineAxisY(rect) {
const minX = Math.min(rect.x, rect.x + rect.width);
const minY = Math.min(rect.y, rect.y + rect.height)
const maxX = Math.max(rect.x, rect.x + rect.width);
const maxY = Math.max(rect.y, rect.y + rect.height)
const axisLineWidthHalf = vernierStyle.axisLine.lineStyle.lineWidth/this._scaleRate/2;
this.axisLineY = new graphic.Line({
...shapeRender,
z: 9999,
silent: true,
position: [-axisLineWidthHalf, 0],
shape: {
x1: minX,
y1: minY,
x2: minX,
y2: maxY
},
style: {
...vernierStyle.axisLine.lineStyle,
shadowOffsetY: -5
}
})
this.add(this.axisLineY);
const step = 4/this._scaleRate;
const count = parseInt(Math.abs(rect.height/step));
for(var i = 0; i in new Array(count).fill(0); i++) {
const offset = step * i;
const tick = i % vernierStyle.axisTick.length == 0;
const len = tick? axisLineWidthHalf*0.7: axisLineWidthHalf*0.5;
if (tick) {
this.add(new graphic.Text({
...shapeRender,
z: 10000,
silent: true,
position: [minX - axisLineWidthHalf - vernierStyle.axisLabel.distance, minY + offset],
style: {
...vernierStyle.axisLabel.textStyle,
text: i / vernierStyle.axisTick.length
}
}))
}
this.add(new graphic.Line({
...shapeRender,
z: 10000,
silent: true,
shape: {
x1: minX,
y1: minY + offset,
x2: minX - len,
y2: minY + offset
},
style: {
...vernierStyle.axisTick.lineStyle,
strokeNoScale: true,
}
}))
}
}
render(rect) {
this.removeAll();
this._scaleRate = this.parent? this.parent.transform[0]: 1;
this._area(rect);
this._lineAxisX(rect);
this._lineAxisY(rect);
}
setShape(rect) {
this.render(rect);
}
getBoundingRect() {
if (this.area) {
return this.area.getBoundingRect();
}
return super.getBoundingRect();
}
}
// function shapeStyleBuilder() {
// return {
// subType: '@selecting',
// ...shapeRender,
// z: 9999,
// shape: {
// x: 0,
// y: 0,
// width: 0,
// height: 0
// },
// style: {
// fill: `rgba(200,200,200,0.3)`
// }
// }
// }
export default class SelectingHandle { export default class SelectingHandle {
constructor(map, controller) { constructor(map, controller) {
@ -29,7 +229,8 @@ export default class SelectingHandle {
this.begPoint = null; this.begPoint = null;
this.endPoint = null; this.endPoint = null;
this.selecting = new graphic.Rect(shapeStyleBuilder()); // this.selecting = new graphic.Rect(shapeStyleBuilder());
this.selecting = new Vernier({subType: '@selecting'});
} }
isSelecting() { isSelecting() {

View File

@ -67,8 +67,10 @@ export default {
}, },
mounted() { mounted() {
this.init(); this.init();
this.$iscs.modelBuilder.addEventListener();
}, },
beforeDestroy() { beforeDestroy() {
this.$iscs.modelBuilder.removeEventListener();
this.destroy(); this.destroy();
}, },
methods: { methods: {
@ -318,7 +320,6 @@ export default {
reflect: true reflect: true
}); });
window.document.oncontextmenu = function () { window.document.oncontextmenu = function () {
return false; return false;
}; };