|
@@ -40,6 +40,11 @@ const subLabelProp = {
|
|
|
}
|
|
|
|
|
|
|
|
|
+const angle = THREE.Math.degToRad(5);//显示水平垂直辅助线的最小角度
|
|
|
+const guideShowMinAngle = {min: angle, max: Math.PI/2 - angle}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -71,10 +76,13 @@ export class Measure extends ctrlPolygon{
|
|
|
|
|
|
//add:
|
|
|
if(this.maxMarkers > 2 || this.faceDirection){
|
|
|
- this.guideLine = this.createGuideLine();
|
|
|
- this.add(this.guideLine)
|
|
|
+ this.createGuideLine();
|
|
|
+ }
|
|
|
+ if(this.measureType == 'Distance'){
|
|
|
+ this.createHorVerGuideLine()
|
|
|
}
|
|
|
|
|
|
+
|
|
|
this.selectStates = {}
|
|
|
|
|
|
this.setUnitSystem(prop.unit || viewer.unitConvert.UnitService.defaultSystem)
|
|
@@ -104,6 +112,7 @@ export class Measure extends ctrlPolygon{
|
|
|
let datasets = {}
|
|
|
|
|
|
this.points_datasets.forEach(e=>{
|
|
|
+ if(e == void 0)return
|
|
|
if(datasets[e]){
|
|
|
datasets[e] ++
|
|
|
}else{
|
|
@@ -120,7 +129,7 @@ export class Measure extends ctrlPolygon{
|
|
|
if(this.datasetId != old){
|
|
|
this.dispatchEvent({type:'changeDatasetId'})
|
|
|
if(this.datasetId == void 0){
|
|
|
- this.dataset_points = null
|
|
|
+ this.dataset_points = null //可能为空或[null,null...]
|
|
|
}else{
|
|
|
this.dataset_points = this.points.map(e=>{
|
|
|
return Potree.Utils.datasetPosTransform.toDataset({datasetId:this.datasetId, position:e.clone()})
|
|
@@ -147,7 +156,7 @@ export class Measure extends ctrlPolygon{
|
|
|
|
|
|
update(ifUpdateMarkers) {
|
|
|
super.update(ifUpdateMarkers)
|
|
|
-
|
|
|
+
|
|
|
if(this.showCoordinates && this.points.length>0){
|
|
|
let position = this.points[0];
|
|
|
|
|
@@ -174,9 +183,19 @@ export class Measure extends ctrlPolygon{
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- let lastIndex = this.points.length - 1;
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ let setEdgeLabel = (label,p1,p2,distance)=>{//设置label位置和字
|
|
|
+ let center = new THREE.Vector3().addVectors(p1,p2).multiplyScalar(0.5);
|
|
|
+ label.setPos(center)
|
|
|
+ distance = distance == void 0 ? p1.distanceTo(p2) : distance;
|
|
|
+ var text = viewer.unitConvert.convert(distance, 'distance', void 0, this.unitSystem, 0.1 , true)//distance要传0.1 这个factor
|
|
|
+ label.setText(text)
|
|
|
+ return distance
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ let lastIndex = this.points.length - 1;
|
|
|
for (let index = 0; index <= lastIndex; index++) {
|
|
|
|
|
|
let nextIndex = (index + 1 > lastIndex) ? 0 : index + 1;
|
|
@@ -186,31 +205,46 @@ export class Measure extends ctrlPolygon{
|
|
|
let nextPoint = this.points[nextIndex];
|
|
|
let previousPoint = this.points[previousIndex];
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
if(this.showDistances){ // edge labels
|
|
|
let edgeLabel = this.edgeLabels[index];
|
|
|
-
|
|
|
- let center = new THREE.Vector3().add(point);
|
|
|
- center.add(nextPoint);
|
|
|
- center = center.multiplyScalar(0.5);
|
|
|
- edgeLabel.setPos(center)
|
|
|
- let distance = point.distanceTo(nextPoint);
|
|
|
-
|
|
|
- var text = viewer.unitConvert.convert(distance, 'distance', void 0, this.unitSystem, 0.1 , true)//distance要传0.1 这个factor
|
|
|
-
|
|
|
- edgeLabel.setText(text)
|
|
|
-
|
|
|
+ let distance = point.distanceTo(nextPoint)
|
|
|
edgeLabel.shouldVisi = (index < lastIndex || this.closed && this.points.length > 2) && distance>0
|
|
|
-
|
|
|
-
|
|
|
- /* this.closed || */ edgeLabel.setVisible(edgeLabel.shouldVisi)
|
|
|
-
|
|
|
+ /* this.closed || */edgeLabel.setVisible(edgeLabel.shouldVisi)
|
|
|
+ if(edgeLabel.visible){
|
|
|
+ setEdgeLabel(edgeLabel,point,nextPoint,distance)
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
+ if(this.measureType == 'Distance' && this.points.length>1){//设置水平垂直辅助线
|
|
|
+ var pTop, pBtm
|
|
|
+ if(this.points[0].z > this.points[1].z ){
|
|
|
+ pTop = this.points[0];
|
|
|
+ pBtm = this.points[1];
|
|
|
+ }else{
|
|
|
+ pTop = this.points[1];
|
|
|
+ pBtm = this.points[0];
|
|
|
+ }
|
|
|
+ let projectPos = new THREE.Vector3(pTop.x, pTop.y, pBtm.z);//两条guideline的交点
|
|
|
+
|
|
|
+ {//倾斜角度太小的时候不显示
|
|
|
+ let tan = pTop.distanceTo(projectPos) / pBtm.distanceTo(projectPos)
|
|
|
+ let angle = Math.atan(tan);
|
|
|
+
|
|
|
+ this.shouldShowHorVerGuide = angle > guideShowMinAngle.min && angle < guideShowMinAngle.max
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ LineDraw.updateLine(this.verGuideEdge, [pTop, projectPos])
|
|
|
+ LineDraw.updateLine(this.horGuideEdge, [pBtm, projectPos])
|
|
|
+ setEdgeLabel(this.verEdgeLabel,pTop,projectPos)
|
|
|
+ setEdgeLabel(this.horEdgeLabel,pBtm,projectPos)
|
|
|
+
|
|
|
+ this.verGuideEdge.visible = this.horGuideEdge.visible = this.shouldShowHorVerGuide
|
|
|
+ this.verEdgeLabel.visible = this.horEdgeLabel.visible = this.shouldShowHorVerGuide
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
if(this.showArea && this.point2dInfo){ // update area
|
|
|
/* if(this.points.length>2){
|
|
@@ -267,42 +301,10 @@ export class Measure extends ctrlPolygon{
|
|
|
|
|
|
|
|
|
|
|
|
- if(this.showEdges){ // edge labels
|
|
|
- var className = 'measure_length';
|
|
|
- if(this.closed){
|
|
|
- className += ' sub'
|
|
|
- }
|
|
|
- /* let edgeLabel = new Label({
|
|
|
- className ,
|
|
|
- })
|
|
|
- edgeLabel.setVisible(false)
|
|
|
- if(!this.closed){
|
|
|
- edgeLabel.elem.on('mouseover',()=>{
|
|
|
- this.setSelected(true, 'edgeLabel')
|
|
|
- })
|
|
|
- edgeLabel.elem.on('mouseout',()=>{
|
|
|
- this.setSelected(false, 'edgeLabel')
|
|
|
- })
|
|
|
- } */
|
|
|
-
|
|
|
- const edgeLabel = new TextSprite(
|
|
|
- $.extend(this.closed ? subLabelProp : mainLabelProp,{sizeInfo: labelSizeInfo, name:'edgeLabel'})
|
|
|
- )
|
|
|
- if(!this.closed){
|
|
|
- edgeLabel.addEventListener('mouseover',()=>{
|
|
|
- this.setSelected(true, 'edgeLabel')
|
|
|
- })
|
|
|
- edgeLabel.addEventListener('mouseleave',()=>{
|
|
|
- this.setSelected(false, 'edgeLabel')
|
|
|
- })
|
|
|
- edgeLabel.addEventListener('click',()=>{
|
|
|
- viewer.focusOnObject(this, 'measure')
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- viewer.setObjectLayers(edgeLabel, 'measure' )
|
|
|
- this.edgeLabels.push(edgeLabel);
|
|
|
- this.add(edgeLabel);
|
|
|
+ if(this.showEdges){ // edge labels
|
|
|
+ const edgeLabel = this.createEdgeLabel('edgeLabel', !this.closed)
|
|
|
+ this.edgeLabels.push(edgeLabel);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
@@ -349,13 +351,13 @@ export class Measure extends ctrlPolygon{
|
|
|
this.editStateTimer = setTimeout(()=>{
|
|
|
if(!this.isEditing){
|
|
|
this.dispatchEvent({type:'editStateChange',state:false})
|
|
|
- this.closed && this.edgeLabels.forEach(e=>e.setVisible(false) )
|
|
|
+ this.setEdgesDisplay(false)
|
|
|
}
|
|
|
},100)
|
|
|
}else{
|
|
|
if(!this.isEditing){
|
|
|
this.dispatchEvent({type:'editStateChange',state:true})
|
|
|
- this.closed && this.edgeLabels.forEach(e=>e.setVisible(e.shouldVisi) )
|
|
|
+ this.setEdgesDisplay(true)
|
|
|
clearTimeout(this.editStateTimer)
|
|
|
}
|
|
|
}
|
|
@@ -393,6 +395,15 @@ export class Measure extends ctrlPolygon{
|
|
|
|
|
|
|
|
|
|
|
|
+ setEdgesDisplay(state){
|
|
|
+ this.closed && this.edgeLabels.forEach(e=>e.setVisible(!!(state && e.shouldVisi)) )
|
|
|
+
|
|
|
+ if(this.measureType == 'Distance'){
|
|
|
+ this.horEdgeLabel.visible = this.verEdgeLabel.visible = this.horGuideEdge.visible = this.verGuideEdge.visible = !!(state && this.shouldShowHorVerGuide)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
setSelected(state, hoverObject){//add
|
|
|
|
|
|
hoverObject && (this.selectStates[hoverObject] = state)
|
|
@@ -411,38 +422,38 @@ export class Measure extends ctrlPolygon{
|
|
|
|
|
|
this.areaPlane && (this.areaPlane.material = planeMats.selected)
|
|
|
|
|
|
- this.closed && this.edgeLabels.forEach(e=>e.setVisible(e.shouldVisi) )
|
|
|
+
|
|
|
//this.areaLabel && this.areaLabel.elem.addClass('highLight')
|
|
|
//this.closed || this.edgeLabels.forEach(e=>e.elem.addClass('highLight') )
|
|
|
-
|
|
|
+ this.setEdgesDisplay(true)
|
|
|
|
|
|
this.areaLabel && setLabelHightState(this.areaLabel, true)
|
|
|
this.closed || this.edgeLabels.forEach(e=>setLabelHightState(e, true) )
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
}else{
|
|
|
this.markers.forEach(e=>this.setMarkerSelected(e,false,'selectAll' ))
|
|
|
this.edges.forEach(e=>e.material = this.getLineMat('edgeDefault') )
|
|
|
this.areaPlane && (this.areaPlane.material = planeMats.default)
|
|
|
- this.closed && this.edgeLabels.forEach(e=>e.setVisible( false))
|
|
|
+ this.setEdgesDisplay(false)
|
|
|
//this.areaLabel && this.areaLabel.elem.removeClass('highLight')
|
|
|
//this.closed || this.edgeLabels.forEach(e=>e.elem.removeClass('highLight') )
|
|
|
this.areaLabel && setLabelHightState(this.areaLabel, false)
|
|
|
this.closed || this.edgeLabels.forEach(e=>setLabelHightState(e, false) )
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
this.selected = absoluteState
|
|
|
viewer.mapViewer.emit('content_changed')
|
|
|
+ if(hoverObject != 'byList'){
|
|
|
+ this.bus && this.bus.emit('highlight', this.selected)//列表高亮
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
removeMarker(index ){
|
|
|
super.removeMarker(index)
|
|
|
|
|
|
this.points_datasets.splice(index, 1);
|
|
|
- this.dataset_points.splice(index, 1)
|
|
|
+ this.dataset_points && this.dataset_points.splice(index, 1)
|
|
|
this.coordinateLabels.splice(index, 1);
|
|
|
|
|
|
let edgeIndex = index//(index === 0) ? 0 : (index - 1);
|
|
@@ -551,15 +562,60 @@ export class Measure extends ctrlPolygon{
|
|
|
|
|
|
|
|
|
createGuideLine(){//add 辅助线
|
|
|
- var guideEdge = LineDraw.createFatLine([
|
|
|
+ var guideLine = LineDraw.createFatLine([
|
|
|
+ 0, 0, 0,
|
|
|
+ 0, 0, 0,
|
|
|
+ ],{material:this.getLineMat('guide')} )
|
|
|
+ guideLine.visible = false
|
|
|
+ this.guideLine = guideLine
|
|
|
+ this.add(guideLine);
|
|
|
+ }
|
|
|
+ createHorVerGuideLine(){//创建水平与垂直辅助线,仅距离测量有。
|
|
|
+ var verGuideEdge = LineDraw.createFatLine([
|
|
|
+ 0, 0, 0,
|
|
|
+ 0, 0, 0,
|
|
|
+ ],{material:this.getLineMat('guide')} )
|
|
|
+ verGuideEdge.visible = false
|
|
|
+ this.verGuideEdge = verGuideEdge
|
|
|
+
|
|
|
+ var horGuideEdge = LineDraw.createFatLine([
|
|
|
0, 0, 0,
|
|
|
0, 0, 0,
|
|
|
],{material:this.getLineMat('guide')} )
|
|
|
- guideEdge.visible = false
|
|
|
+ horGuideEdge.visible = false
|
|
|
+ this.horGuideEdge = horGuideEdge
|
|
|
+
|
|
|
+ this.add(this.verGuideEdge);
|
|
|
+ this.add(this.horGuideEdge);
|
|
|
+
|
|
|
+
|
|
|
+ //label:
|
|
|
+ this.verEdgeLabel = this.createEdgeLabel('verGuideEdge')
|
|
|
+ this.horEdgeLabel = this.createEdgeLabel('horGuideEdge')
|
|
|
+
|
|
|
|
|
|
- return guideEdge;
|
|
|
}
|
|
|
|
|
|
+ createEdgeLabel(name, hasHoverEvent){
|
|
|
+ const edgeLabel = new TextSprite(
|
|
|
+ $.extend(hasHoverEvent ? mainLabelProp : subLabelProp,{sizeInfo: labelSizeInfo, name:name||'edgeLabel'})
|
|
|
+ )
|
|
|
+ if(hasHoverEvent){
|
|
|
+ edgeLabel.addEventListener('mouseover',()=>{
|
|
|
+ this.setSelected(true, 'edgeLabel')
|
|
|
+ })
|
|
|
+ edgeLabel.addEventListener('mouseleave',()=>{
|
|
|
+ this.setSelected(false, 'edgeLabel')
|
|
|
+ })
|
|
|
+ edgeLabel.addEventListener('click',()=>{
|
|
|
+ viewer.focusOnObject(this, 'measure')
|
|
|
+ })
|
|
|
+ }
|
|
|
+ edgeLabel.visible = false
|
|
|
+ viewer.setObjectLayers(edgeLabel, 'measure' )
|
|
|
+ this.add(edgeLabel)
|
|
|
+ return edgeLabel
|
|
|
+ }
|
|
|
|
|
|
createAreaLabel(){
|
|
|
/* const areaLabel = new Label({
|
|
@@ -629,7 +685,11 @@ export class Measure extends ctrlPolygon{
|
|
|
dashSize: 0.5,
|
|
|
gapSize: 0.2,
|
|
|
linewidth: config.measure.lineWidth,
|
|
|
- useDepth :true
|
|
|
+ useDepth :true,
|
|
|
+ dashWithDepth :true, // 只在被遮住的部分显示虚线,因为实线容易挡住label
|
|
|
+ dashed :true,
|
|
|
+ dashSize : 0.04,
|
|
|
+ gapSize: 0.04,
|
|
|
}),
|
|
|
edgeSelect: LineDraw.createFatLineMat({
|
|
|
color: highLightColor,//'#f0ff00',
|
|
@@ -711,13 +771,15 @@ export class Measure extends ctrlPolygon{
|
|
|
prop.maxMarkers = 2,
|
|
|
prop.minMarkers = 2,
|
|
|
prop.faceDirection = "vertical"
|
|
|
+ prop.unableDragAtMap = true
|
|
|
}else if(prop.measureType == 'Hor Distance'){
|
|
|
prop.showDistances = true,
|
|
|
prop.closed = false,
|
|
|
prop.showEdges = true,
|
|
|
prop.maxMarkers = 2,
|
|
|
prop.minMarkers = 2,
|
|
|
- prop.faceDirection = "horizontal"
|
|
|
+ prop.faceDirection = "horizontal"
|
|
|
+
|
|
|
}else if(prop.measureType == 'Area'){
|
|
|
prop.showDistances = true,
|
|
|
prop.showArea = true,
|
|
@@ -731,13 +793,15 @@ export class Measure extends ctrlPolygon{
|
|
|
prop.closed = true,
|
|
|
prop.minMarkers = 3
|
|
|
prop.faceDirection = "horizontal"
|
|
|
+
|
|
|
}else if(prop.measureType == 'Ver Area'){
|
|
|
prop.showDistances = true,
|
|
|
prop.showArea = true,
|
|
|
prop.showEdges = true,
|
|
|
prop.closed = true,
|
|
|
prop.minMarkers = 3
|
|
|
- prop.faceDirection = "vertical"
|
|
|
+ prop.faceDirection = "vertical"
|
|
|
+ prop.unableDragAtMap = true
|
|
|
}else if(prop.measureType == 'Rect Area'){
|
|
|
prop.showDistances = true,
|
|
|
prop.showArea = true,
|
|
@@ -753,7 +817,7 @@ export class Measure extends ctrlPolygon{
|
|
|
prop.minMarkers = 4
|
|
|
prop.maxMarkers = 4
|
|
|
prop.isRect = true
|
|
|
- prop.faceDirection = "horizontal"
|
|
|
+ prop.faceDirection = "horizontal"
|
|
|
}else if(prop.measureType == 'Ver Rect Area'){
|
|
|
prop.showDistances = true,
|
|
|
prop.showArea = true,
|
|
@@ -763,6 +827,7 @@ export class Measure extends ctrlPolygon{
|
|
|
prop.maxMarkers = 4
|
|
|
prop.isRect = true
|
|
|
prop.faceDirection = "vertical"
|
|
|
+ prop.unableDragAtMap = true
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -782,7 +847,18 @@ export class Measure extends ctrlPolygon{
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+ reDraw(restMarkerCount=0){//重新开始画
|
|
|
+ super.reDraw(restMarkerCount)
|
|
|
+ if(this.measureType == 'Distance'){
|
|
|
+ this.shouldShowHorVerGuide = false
|
|
|
+ this.setEdgesDisplay(false)
|
|
|
+ }
|
|
|
+ if(this.showArea){
|
|
|
+ this.area = {value:0};
|
|
|
+ this.areaLabel && this.areaLabel.setVisible(false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
/* get showCoordinates () {
|