这是一个在线打开dxf图纸的插件,欢迎使用,如有不足,欢迎指正。 持续更新中...
安装方式:npm install view-dxf --save
引用方式:import Viewer from 'view-dxf'
ThreeJS的支持:npm install three --save
DxfParser的支持: npm install dxf-parser --save
let parser = new DxfParser()
let dxfData = parser.parseSync('拿到的dxf文件数据')
// helvetiker_regular.typeface.json 代表的是json格式的字体库数据
// cad-view代表的是你插入dxf的节点id,width代表显示时的宽,height代表显示时的高
let loader = new THREE.FontLoader()
loader.load('/static/lib/fonts/helvetiker_regular.typeface.json', (response) => {
let cadCanvas = new Viewer(dxfData, document.getElementById('cad-view'), width, height, response, (dxfCallback) => {
console.log(dxfCallback, '用户操作之后的回调函数')
})
})
cadCanvas.sceneAddDataCtrl(dxfData)
cadCanvas.render()
绘制矩形框:drawRectId
绘制云线框:drawCloudId
绘制平面框:drawPlaneId
绘制箭头:drawArrowId
绘制椭圆:drawEllipseId
<i id="drawRectId" class="iconfont off dxf-el-button icon-xiankuang1"></i>
let data = [{annotationId: 320, // 批注的唯一标识
content: "批注内容详情", // ---如果只是使用批注模块,这个参数不要传
coordinate: {
drawRectScreenCoord: {
startX: 38,
startY: 210,
endX: 238,
endY: 402
},
drawRectWorldCoord: {
startX: -24.88748981868235,
startY: 26.64271682686174,
endX: 25.490601775931857,
endY: 48.2797488960321
},
type: "drawCloudType"
}, // 批注操作完成之后callback出来的数据,不用处理同步保存就好
type: 1, // 问题类型(1:一般问题,2:严重问题)---如果只是使用批注模块,这个参数不要传
markNumber: 1, // 右下角的标号,如果不传,则会使用数组的"index+1"的值
roleColor: '#000000' // 传入绘制的颜色值
}]
cadCanvas.dxfAnnotationListDrawCtrl(data)
let data = [{annotationId: 320}, {annotationId: 321}]
cadCanvas.deleteAllDxfAnnotationCtrl(data)
cadCanvas.deleteDxfAnnotationCtrl(annotationId)
cadCanvas.sceneRemoveViewerCtrl()
let data = [{annotationId: 320}, {annotationId: 321}]
or data = [320, 321]
let show = true // true为显示,false为隐藏
cadCanvas.showAllDxfAnnotationCtrl(data, show)
let data = {
annotationId: 320, // 批注的唯一标识
coordinate: {
drawRectScreenCoord: {
startX: 38,
startY: 210,
endX: 238,
endY: 402
},
drawRectWorldCoord: {
startX: -24.88748981868235,
startY: 26.64271682686174,
endX: 25.490601775931857,
endY: 48.2797488960321
},
type: "drawCloudType"
}
}
或
let data = annotationId || elementId || modelId
let config = {
showCenter: false, // 是否定位到屏幕中央, 默认: false
showColor: '#00ff00' // 闪烁的颜色值, 默认: #00ff00
}
cadCanvas.selectedDxfAnnotationCtrl(data, config)
cadCanvas.moveToScreenPositionCtrl(x, y)
let data = {
data: 100.00,
type: "sceneAddFinishDxf"
}
绘制矩形框:drawRectType
绘制云线框:drawCloudType
绘制平面框:drawPlaneType
绘制箭头:drawArrowType
绘制椭圆:drawEllipseType
let data = {
data: {}, // 和查询批注列表里面的coordinate字段的数据要保持同步
type: "selectedComponentDxf"
}
let data = {
data: {
moveAndZoom: {
offsetX: 0, // X轴偏移量
offsetY: 0, // Y轴偏移量
zoom: 1 // 画布缩放大小,1为不放大也没缩小
}
},
type: "updateScreenPositionDxf"
}
let data = [{
coordinate: {
drawRectScreenCoord: {
startX: 38,
startY: 210,
endX: 238,
endY: 402
},
drawRectWorldCoord: {
startX: -24.88748981868235,
startY: 26.64271682686174,
endX: 25.490601775931857,
endY: 48.2797488960321
},
type: "drawCloudType"
}, // 还是之前第一次保存之后的callback数据
}]
cadCanvas.pointToScreenPositionCtrl(data, (callback) => {
console.log(callback)
})
新绘制的批注框的callback数据格式
let data = {
type: "selectedComponentDxf",
data: {
drawRectScreenCoord: {
startX: 38,
startY: 210,
endX: 238,
endY: 402
},
drawRectWorldCoord: {
startX: -24.88748981868235,
startY: 26.64271682686174,
endX: 25.490601775931857,
endY: 48.2797488960321
},
type: "drawCloudType" // 根据这个type判断是新增批注框,以及批注框的形状
}
}
点击之前绘制的批注框的callback数据格式
let data = {
type: "selectedComponentDxf"
data: {
name: 341, // 返回点选的批注框的唯一标识
type: "Line",
userData: {
drawRectScreenCoord: {
startX: 38,
startY: 210,
endX: 238,
endY: 402
},
drawRectWorldCoord: {
startX: -24.88748981868235,
startY: 26.64271682686174,
endX: 25.490601775931857,
endY: 48.2797488960321
},
type: "drawCloudType" // 根据这个type判断是点选的批注框,以及选中的批注框的形状
}
}
}
eg: data.data.type === 'drawCloudType' // 如果取到对应值,则代表新增
eg: data.data.userData.type === 'drawCloudType' // 如果取到对应值,则代表点选
let data = {
type: "touchendDxf",
data: {}
}
cadCanvas.changeRoleColorCtrl('#00ff00')
cadCanvas.resetCameraCtrl()
cadCanvas.resetCameraCtrl(width, height)
cadCanvas.zoomCameraCtrl(1)
cadCanvas.deleteCurrentNodeCtrl()
cadCanvas.closeDrawCtrl()
// cad-view代表的是你插入dxf的节点id,width代表显示时的宽,height代表显示时的高
let cadCanvas = new Viewer({}, document.getElementById('cad-view'), width, height, {}, (dxfCallback) => {
console.log(dxfCallback, '用户操作之后的回调函数')
})
// 如若切换的下面为图片,则需要这样调用,并且下方图片一定要根据canvas的宽高比动态居中全部显示出来
cadCanvas.sceneAddDataCtrl({}, {
width: canvas宽度,
height: canvas高度,
imageWidth: 下方需要批注的图片的宽度,
imageHeight: 下方需要批注的图片的高度
})
// 如若之后再修改屏幕的宽高
cadCanvas.resetCameraCtrl(width, height, imageWidth, imageHeight)
1,单指表示平移(如果打开批注,则为绘制) 2,双指表示缩放(如果打开批注,则不允许缩放) 3,三指表示平移
<script src="https://cdn.jsdelivr.net/npm/view-dxf@1.2.0/dist/index.js" type="text/javascript" charset="utf-8"></script>
<script src="https://cdn.jsdelivr.net/npm/view-dxf@latest/dist/index.js" type="text/javascript" charset="utf-8"></script>
import Viewer from 'view-dxf'