123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131 |
- import * as THREE from "../../libs/three.js/build/three.module.js";
- import {TextSprite} from "../TextSprite.js";
- import {Utils} from "../utils.js";
- import Label from "./Label.js";
- import {LineDraw} from "../utils/DrawUtil";
- import math from "./math.js";
- import {MOUSE} from "../defines.js";
- import DepthBasicMaterial from "../materials/DepthBasicMaterial.js";
- import Sprite from '../viewer/Sprite'
- import {config} from '../settings'
- import {ctrlPolygon} from './ctrlPolygon'
- let texLoader = new THREE.TextureLoader()
- let color = new THREE.Color(config.measure.lineColor)
- let textColor = new THREE.Color(config.measure.textColor)
- let highLightColor = new THREE.Color(config.measure.highLightColor)
- var markerMats;
- var lineMats;
- var planeMats
- const markerSizeInfo = {
- minSize : 25 , maxSize : 65, nearBound : 0.2, farBound : 8,
- }
- const labelSizeInfo = {width2d:200}
- const mainLabelProp = {
- backgroundColor: {r: color.r*255, g: color.g*255, b: color.b*255, a:config.measure.labelOpacity},
- textColor: {r: textColor.r*255, g: textColor.g*255, b: textColor.b*255, a: 1.0},
- fontsize:16,
- useDepth : true ,
- renderOrder : 5
- }
- const subLabelProp = {
- backgroundColor: {r: 255, g: 255, b: 255, a:1},
- textColor: {r: 0, g: 0, b:0, a: 1.0},
- fontsize:14,
- renderOrder : 4
- }
-
-
- export class Measure extends ctrlPolygon{
- constructor (prop) {
- prop.dimension = '2d'
-
- super('measure',prop);
- this.constructor.counter = (this.constructor.counter === undefined) ? 0 : this.constructor.counter + 1;
-
-
- this.name = this.measureType + this.constructor.counter //'Measure_' + this.constructor.counter;
-
- this.color = new THREE.Color(config.measure.lineColor)//new THREE.Color(0xff0000);
-
-
- this.markerLabels = [];
- this.edgeLabels = [];
- this.angleLabels = [];
- this.coordinateLabels = [];
- this.area = {value:0,string:''}
-
-
- if(this.closed/* this.showArea */){
- this.areaLabel = this.createAreaLabel();
- this.add(this.areaLabel)
- }
-
-
- //add:
- if(this.maxMarkers > 2 || this.faceDirection){
- this.guideLine = this.createGuideLine();
- this.add(this.guideLine)
- }
-
- this.selectStates = {}
-
- this.setUnitSystem(prop.unit || viewer.unitConvert.UnitService.defaultSystem)
- viewer.setObjectLayers(this, 'measure' )
-
- //addMarkers:
-
- this.initData(prop)
-
-
- this.points_datasets || (this.points_datasets = []) //存每个点是哪个数据集
-
-
- this.addEventListener('marker_dropped',(e)=>{
- this.updateDatasetBelong()
- })
- }
-
-
-
- updateDatasetBelong(){//更新所属数据集
- let old = this.datasetId
-
- let maxCount = {id:null,count:0}
- let datasets = {}
-
- this.points_datasets.forEach(e=>{
- if(datasets[e]){
- datasets[e] ++
- }else{
- datasets[e] = 1
- }
- })
- for(let i in datasets) {
- if(datasets[i]>maxCount.count){
- maxCount = {id:i, count:datasets[i]}
- }
- }
- this.datasetId = maxCount.count > 0 ? maxCount.id : null
-
- if(this.datasetId != old){
- this.dispatchEvent({type:'changeDatasetId'})
- if(this.datasetId == void 0){
- this.dataset_points = null
- }else{
- this.dataset_points = this.points.map(e=>{
- return Potree.Utils.datasetPosTransform.toDataset({datasetId:this.datasetId, position:e.clone()})
- })
- }
- }
- }
-
-
-
-
- transformByPointcloud(){//每次移动点云 or 加载测量线时要获取一下当前position
- if(this.datasetId == void 0)return
- this.points = this.dataset_points.map(e=>{
- return Potree.Utils.datasetPosTransform.fromDataset({datasetId:this.datasetId, dataset_location:e.clone()})
- })
-
- this.getPoint2dInfo(this.points)
- this.update(true)
- this.setSelected(false)//隐藏edgelabel
-
- }
-
- update(ifUpdateMarkers) {
- super.update(ifUpdateMarkers)
-
- if(this.showCoordinates && this.points.length>0){
- let position = this.points[0];
-
- this.markers[0].position.copy(position);
- { // coordinate labels
- let coordinateLabel = this.coordinateLabels[0];
-
- let lonlat = viewer.transform.lonlatToLocal.inverse(position.toArray())
- let EPSG4550 = viewer.transform.lonlatTo4550.forward(lonlat)
- let pos = [
- position.toArray(),
- lonlat,
- EPSG4550
- ]
- //let msg = position.toArray().map(p => Utils.addCommas(p.toFixed(2))).join(" / ");
- let msg = pos.map(a=>
- a.map(p => Utils.addCommas(p.toFixed(10))).join(", ")
- ).join("<br>")
- coordinateLabel.setText(msg);
- coordinateLabel.setPos(position)
- coordinateLabel.setVisible(true)//this.showCoordinates;
- }
- return
- }
-
- let lastIndex = this.points.length - 1;
-
-
- for (let index = 0; index <= lastIndex; index++) {
-
- let nextIndex = (index + 1 > lastIndex) ? 0 : index + 1;
- let previousIndex = (index === 0) ? lastIndex : index - 1;
- let point = this.points[index];
- 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)
-
- edgeLabel.shouldVisi = (index < lastIndex || this.closed && this.points.length > 2) && distance>0
-
-
- /* this.closed || */ edgeLabel.setVisible(edgeLabel.shouldVisi)
-
- }
-
- }
-
- if(this.showArea && this.point2dInfo){ // update area
- /* if(this.points.length>2){
- this.area = {value:0};
- this.areaLabel.setVisible(false)
- }else{ */
- let area = Math.abs(math.getArea(this.point2dInfo.points2d))//this.getArea();
- let msg = viewer.unitConvert.convert(area, 'area', void 0, this.unitSystem/* , 0.1 */ )
- this.area = {value:area, string:msg}
-
- this.areaLabel.setPos(this.center);
- this.areaLabel.setText(msg);
- this.areaLabel.setVisible(true)
- //}
- }
-
-
-
- };
-
-
- addMarker (o={}) {
-
- let marker = new Sprite({mat:this.getMarkerMaterial('default'), sizeInfo: markerSizeInfo, name:"measure_point"} )
- viewer.setObjectLayers(marker, 'measure' )
- marker.renderOrder = 3
- marker.markerSelectStates = {}
-
-
- let edge
- { // edges
- edge = LineDraw.createFatLine( [
- 0, 0, 0,
- 0, 0, 0,
- ],{material:this.getLineMat('edgeDefault')} )
- viewer.setObjectLayers(edge, 'measure' )
-
- //----
- let mouseover = (e) => {this.setSelected(true, 'edge')};
- let mouseleave = (e) => {this.setSelected(false, 'edge')};
-
- edge.addEventListener('mouseover', mouseover);
- edge.addEventListener('mouseleave', mouseleave);
-
-
-
- }
-
- super.addMarker({point:o.point, marker:marker, edge})
-
-
-
- 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.showCoordinates){ // coordinate labels
- let coordinateLabel = new Label({
- className:'measure_pointPos',
- camera: viewer.scene.getActiveCamera()
- })
- coordinateLabel.setVisible(false)
- this.coordinateLabels.push(coordinateLabel);
-
- }
-
-
-
-
-
- let event = {
- type: 'marker_added',
- measurement: this,
- marker: marker
- };
- this.dispatchEvent(event);
- //this.setMarker(this.points.length - 1, point);
-
- return marker;//add
- };
-
-
- editStateChange(state){ //主要针对edgeLabels显示切换,编辑时显示
- super.editStateChange(state)
- if(!state){
- this.editStateTimer = setTimeout(()=>{
- if(!this.isEditing){
- this.dispatchEvent({type:'editStateChange',state:false})
- this.closed && this.edgeLabels.forEach(e=>e.setVisible(false) )
- }
- },100)
- }else{
- if(!this.isEditing){
- this.dispatchEvent({type:'editStateChange',state:true})
- this.closed && this.edgeLabels.forEach(e=>e.setVisible(e.shouldVisi) )
- clearTimeout(this.editStateTimer)
- }
- }
- this.isEditing = state
- }
-
-
- setMarkerSelected(marker, state, hoverObject){
-
- //console.warn(marker.id , state, hoverObject)
-
-
- marker.markerSelectStates[hoverObject] = state
- let absoluteState = false
- for(var i in marker.markerSelectStates){
- if(marker.markerSelectStates[i]){
- absoluteState = true; break;
- }
- }
- if(absoluteState){
- marker.material = this.getMarkerMaterial('select')
- }else{
- marker.material = this.getMarkerMaterial('default')
- }
-
- marker.selected = absoluteState
-
- viewer.mapViewer.emit('content_changed')
- }
-
-
-
- setSelected(state, hoverObject){//add
-
- hoverObject && (this.selectStates[hoverObject] = state)
- let absoluteState = false
- for(var i in this.selectStates){
- if(this.selectStates[i]){
- absoluteState = true; break;
- }
- }
-
-
- if(absoluteState){
- this.markers.forEach(e=>this.setMarkerSelected(e,true,'selectAll' ) )
-
- this.edges.forEach(e=>e.material = this.getLineMat('edgeSelect') )
-
- 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.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.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')
- }
-
- removeMarker(index ){
- super.removeMarker(index)
-
- this.points_datasets.splice(index, 1);
- this.dataset_points.splice(index, 1)
- this.coordinateLabels.splice(index, 1);
-
- let edgeIndex = index//(index === 0) ? 0 : (index - 1);
- if(this.edgeLabels[edgeIndex]){
- this.edgeLabels[edgeIndex].dispose()
- this.edgeLabels.splice(edgeIndex, 1);
- }
-
- this.update();
- this.dispatchEvent({type: 'marker_removed', measurement: this});
- }
-
- setPosition(index, position) {
- super.setPosition(index, position)
- let event = {
- type: 'marker_moved',
- measure: this,
- index: index,
- position: position.clone()
- };
- this.dispatchEvent(event);
- }
-
- dispose(){//add
- var labels = this.edgeLabels.concat(this.coordinateLabels)
- this.areaLabel && labels.push(this.areaLabel)
- labels.forEach(e=>e.dispose())
- super.dispose()
- }
-
-
- getTotalDistance () {
- if (this.points.length === 0) {
- return 0;
- }
- let distance = 0;
- for (let i = 1; i < this.points.length; i++) {
- let prev = this.points[i - 1];
- let curr = this.points[i];
- let d = prev.distanceTo(curr);
- distance += d;
- }
- if (this.closed && this.points.length > 1) {
- let first = this.points[0];
- let last = this.points[this.points.length - 1];
- let d = last.distanceTo(first);
- distance += d;
- }
- return distance;
- }
- getAngleBetweenLines (cornerPoint, point1, point2) {
- let v1 = new THREE.Vector3().subVectors(point1, cornerPoint);
- let v2 = new THREE.Vector3().subVectors(point2, cornerPoint);
- // avoid the error printed by threejs if denominator is 0
- const denominator = Math.sqrt( v1.lengthSq() * v2.lengthSq() );
- if(denominator === 0){
- return 0;
- }else{
- return v1.angleTo(v2);
- }
- };
- getAngle (index) {
- if (this.points.length < 3 || index >= this.points.length) {
- return 0;
- }
- let previous = (index === 0) ? this.points[this.points.length - 1] : this.points[index - 1];
- let point = this.points[index];
- let next = this.points[(index + 1) % (this.points.length)];
- return this.getAngleBetweenLines(point, previous, next);
- }
-
- getCenter(/* update */){
- if(this.points.length>=3){
- return this.center.clone()
- }else if(this.points.length == 2){
- return this.points[0].clone().add((this.points[1])).multiplyScalar(0.5)
- }else return this.points[0].clone()
-
- }
-
- // updateAzimuth(){
- // // if(this.points.length !== 2){
- // // return;
- // // }
- // // const azimuth = this.azimuth;
- // // const [p0, p1] = this.points;
- // // const r = p0.distanceTo(p1);
-
- // }
-
-
-
-
- createGuideLine(){//add 辅助线
- var guideEdge = LineDraw.createFatLine([
- 0, 0, 0,
- 0, 0, 0,
- ],{material:this.getLineMat('guide')} )
- guideEdge.visible = false
-
- return guideEdge;
- }
-
-
- createAreaLabel(){
- /* const areaLabel = new Label({
- className:'measure_area',
-
- })
- areaLabel.elem.on('mouseover',()=>{
- this.setSelected(true, 'areaLabel')
- })
- areaLabel.elem.on('mouseout',()=>{
- this.setSelected(false, 'areaLabel')
- }) */
-
-
- const areaLabel = new TextSprite(
- $.extend(mainLabelProp,{sizeInfo: labelSizeInfo, name:'areaLabel_'} )
- )
-
- areaLabel.addEventListener('mouseover',()=>{
- this.setSelected(true, 'areaLabel')
- })
- areaLabel.addEventListener('mouseleave',()=>{
- this.setSelected(false, 'areaLabel')
- })
- areaLabel.addEventListener('click',()=>{
- viewer.focusOnObject(this, 'measure')
- })
- viewer.setObjectLayers(areaLabel, 'measure' )
- areaLabel.visible = false
-
- return areaLabel;
-
-
- }
-
- getMarkerMaterial(type) {
- if(!markerMats){
- markerMats = {
- default: new DepthBasicMaterial({
- transparent: !0,
- opacity: 1,
- map: texLoader.load(Potree.resourcePath+'/textures/pic_point32.png' ),
- useDepth:true
- }),
- select: new DepthBasicMaterial({
- transparent: !0,
- opacity: 1,
- map: texLoader.load(Potree.resourcePath+'/textures/pic_point_s32.png'/* , null, null, { antialias: false } */),
-
- }),
- }
- Measure.markerMats = markerMats
- }
- return markerMats[type]
-
- }
-
-
-
-
- getLineMat(type) {
- if(!Measure.lineMats){
- Measure.lineMats = {
- edgeDefault: LineDraw.createFatLineMat({
- color: color,
- dashSize: 0.5,
- gapSize: 0.2,
- linewidth: config.measure.lineWidth,
- useDepth :true
- }),
- edgeSelect: LineDraw.createFatLineMat({
- color: highLightColor,//'#f0ff00',
- dashSize: 0.5,
- gapSize: 0.2,
- linewidth: config.measure.lineWidth
- }),
- guide: LineDraw.createFatLineMat({
- color:config.measure.guideLineColor,
- dashSize: 0.1,
- gapSize: 0.02,
- dashed: true,
- linewidth: config.measure.lineWidth
- })
-
- }
- }
- return Measure.lineMats[type]
-
- }
-
-
- createAreaPlane(){
- planeMats || (planeMats = {
- default: new DepthBasicMaterial({
- color:color,
- side:THREE.DoubleSide,
- opacity:0.2,
- transparent:true,
- useDepth:true
- }),
- selected: new DepthBasicMaterial({
- color:color,
- side:THREE.DoubleSide,
- opacity:0.3,
- transparent:true
- })
- },Measure.planeMats = planeMats)
- return super.createAreaPlane(planeMats.default)
- }
-
-
- raycast (raycaster, intersects) {
- for (let i = 0; i < this.points.length; i++) {
- let marker = this.markers[i];
- marker.raycast(raycaster, intersects);
- }
- // recalculate distances because they are not necessarely correct
- // for scaled objects.
- // see https://github.com/mrdoob/three.js/issues/5827
- // TODO: remove this once the bug has been fixed
- for (let i = 0; i < intersects.length; i++) {
- let I = intersects[i];
- I.distance = raycaster.ray.origin.distanceTo(I.point);
- }
- intersects.sort(function (a, b) { return a.distance - b.distance; });
- };
-
-
- transformData(prop){
- if(prop.measureType == 'Point'){
- prop.showCoordinates = true,
- prop.closed = true,
- prop.maxMarkers = 1,
- prop.minMarkers = 1
- }else if(prop.measureType == 'Distance'){
- prop.showDistances = true,
- prop.closed = false,
- prop.showEdges = true,
- prop.maxMarkers = 2,
- prop.minMarkers = 2
- }else if(prop.measureType == 'Ver Distance'){
- prop.showDistances = true,
- prop.closed = false,
- prop.showEdges = true,
- prop.maxMarkers = 2,
- prop.minMarkers = 2,
- prop.faceDirection = "vertical"
- }else if(prop.measureType == 'Hor Distance'){
- prop.showDistances = true,
- prop.closed = false,
- prop.showEdges = true,
- prop.maxMarkers = 2,
- prop.minMarkers = 2,
- prop.faceDirection = "horizontal"
- }else if(prop.measureType == 'Area'){
- prop.showDistances = true,
- prop.showArea = true,
- prop.showEdges = true,
- prop.closed = true,
- prop.minMarkers = 3
- }else if(prop.measureType == 'Hor Area'){
- prop.showDistances = true,
- prop.showArea = true,
- prop.showEdges = true,
- 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"
- }else if(prop.measureType == 'Rect Area'){
- prop.showDistances = true,
- prop.showArea = true,
- prop.showEdges = true,
- prop.closed = true,
- prop.minMarkers = 4
- prop.maxMarkers = 4
- }else if(prop.measureType == 'Hor Rect Area'){
- prop.showDistances = true,
- prop.showArea = true,
- prop.showEdges = true,
- prop.closed = true,
- prop.minMarkers = 4
- prop.maxMarkers = 4
- prop.isRect = true
- prop.faceDirection = "horizontal"
- }else if(prop.measureType == 'Ver Rect Area'){
- prop.showDistances = true,
- prop.showArea = true,
- prop.showEdges = true,
- prop.closed = true,
- prop.minMarkers = 4
- prop.maxMarkers = 4
- prop.isRect = true
- prop.faceDirection = "vertical"
- }
- }
- setUnitSystem(unitSystem){
- //console.log(this.name +':' +this.unitSystem)
- if(unitSystem != this.unitSystem){
- if(unitSystem == "metric"){
-
- }else if(unitSystem == 'imperial'){
-
- }
- this.unitSystem = unitSystem
- this.update()
- }
- }
- /* get showCoordinates () {
- return this._showCoordinates;
- }
- set showCoordinates (value) {
- this._showCoordinates = value;
- this.update();
- }
- get showAngles () {
- return this._showAngles;
- }
- set showAngles (value) {
- this._showAngles = value;
- this.update();
- }
- get showCircle () {
- return this._showCircle;
- }
- set showCircle (value) {
- this._showCircle = value;
- this.update();
- }
- get showAzimuth(){
- return this._showAzimuth;
- }
- set showAzimuth(value){
- this._showAzimuth = value;
- this.update();
- }
- get showEdges () {
- return this._showEdges;
- }
- set showEdges (value) {
- this._showEdges = value;
- this.update();
- }
- get showHeight () {
- return this._showHeight;
- }
- set showHeight (value) {
- this._showHeight = value;
- this.update();
- }
- get showArea () {
- return this._showArea;
- }
- set showArea (value) {
- this._showArea = value;
- this.update();
- }
- get closed () {
- return this._closed;
- }
- set closed (value) {
- this._closed = value;
- this.update();
- }
- get showDistances () {
- return this._showDistances;
- }
- set showDistances (value) {
- this._showDistances = value;
- this.update();
- } */
- }
- function setLabelHightState(label, state){
- if(state){
- //label.backgroundColor = {r: highLightColor.r*255, g: highLightColor.g*255, b: highLightColor.b*255, a:1},
- label.backgroundColor.a = 1
- label.sprite.material.useDepth = false;
-
- }else{
- //label.backgroundColor = mainLabelProp.backgroundColor
- label.backgroundColor.a = config.measure.labelOpacity
- label.sprite.material.useDepth = true
-
- }
- label.updateTexture()
- //label.sprite.material.needsUpdate = true
- }
- function createCircleRadiusLabel(){
- const circleRadiusLabel = new TextSprite("");
- circleRadiusLabel.setTextColor({r: 140, g: 250, b: 140, a: 1.0});
- circleRadiusLabel.setBorderColor({r: 0, g: 0, b: 0, a: 1.0});
- circleRadiusLabel.setBackgroundColor({r: 0, g: 0, b: 0, a: 1.0});
- circleRadiusLabel.fontsize = 16;
- circleRadiusLabel.material.depthTest = false;
- circleRadiusLabel.material.opacity = 1;
- circleRadiusLabel.visible = false;
-
- return circleRadiusLabel;
- }
- function createCircleRadiusLine(){
- /* const lineGeometry = new LineGeometry();
- lineGeometry.setPositions([
- 0, 0, 0,
- 0, 0, 0,
- ]);
- const lineMaterial = new LineMaterial({
- color: 0xff0000,
- linewidth: 2,
- resolution: new THREE.Vector2(1000, 1000),
- gapSize: 1,
- dashed: true,
- });
- lineMaterial.depthTest = false;
- const circleRadiusLine = new Line2(lineGeometry, lineMaterial);*/
-
- var circleRadiusLine = LineDraw.createFatLine([
- 0, 0, 0,
- 0, 0, 0,
- ],{
- color:0xff0000,
- dashSize: 0.5,
- gapSize: 0.2,
- linewidth: config.measure.lineWidth
- })
- circleRadiusLine.visible = false;
- return circleRadiusLine;
- }
- function createCircleLine(){
- const coordinates = [];
- let n = 128;
- for(let i = 0; i <= n; i++){
- let u0 = 2 * Math.PI * (i / n);
- let u1 = 2 * Math.PI * (i + 1) / n;
- let p0 = new THREE.Vector3(
- Math.cos(u0),
- Math.sin(u0),
- 0
- );
- let p1 = new THREE.Vector3(
- Math.cos(u1),
- Math.sin(u1),
- 0
- );
- coordinates.push(
- ...p0.toArray(),
- ...p1.toArray(),
- );
- }
- /* const geometry = new LineGeometry();
- geometry.setPositions(coordinates);
- const material = new LineMaterial({
- color: 0xff0000,
- dashSize: 5,
- gapSize: 2,
- linewidth: 2,
- resolution: new THREE.Vector2(1000, 1000),
- });
- material.depthTest = false;
- const circleLine = new Line2(geometry, material);
- circleLine.visible = false;
- circleLine.computeLineDistances();*/
- var circleLine = LineDraw.createFatLine(coordinates,{
- color: 0xff0000,
- dashSize: 0.5,
- gapSize: 0.2,
- linewidth: config.measure.lineWidth
- })
- return circleLine;
- }
- function createCircleCenter(){
- const sg = new THREE.markerGeometry(1, 32, 32);
- const sm = new THREE.MeshNormalMaterial();
-
- const circleCenter = new THREE.Mesh(sg, sm);
- circleCenter.visible = false;
- return circleCenter;
- }
- function createLine(){
-
- const line = LineDraw.createFatLine([
- 0, 0, 0,
- 0, 0, 0,
- ],{
- color: 0xff0000,
- dashSize: 0.5,
- gapSize: 0.2,
- linewidth: config.measure.lineWidth
- })
-
-
-
- return line;
- }
- function createCircle(){
- const coordinates = [];
- let n = 128;
- for(let i = 0; i <= n; i++){
- let u0 = 2 * Math.PI * (i / n);
- let u1 = 2 * Math.PI * (i + 1) / n;
- let p0 = new THREE.Vector3(
- Math.cos(u0),
- Math.sin(u0),
- 0
- );
- let p1 = new THREE.Vector3(
- Math.cos(u1),
- Math.sin(u1),
- 0
- );
- coordinates.push(
- ...p0.toArray(),
- ...p1.toArray(),
- );
- }
-
- var line = LineDraw.createFatLine(coordinates,{
- color: 0xff0000,
- dashSize: 0.5,
- gapSize: 0.2,
- linewidth: config.measure.lineWidth
- })
- return line;
- }
- function createAzimuth(){
- const azimuth = {
- label: null,
- center: null,
- target: null,
- north: null,
- centerToNorth: null,
- centerToTarget: null,
- centerToTargetground: null,
- targetgroundToTarget: null,
- circle: null,
- node: null,
- };
- const sg = new THREE.markerGeometry(1, 32, 32);
- const sm = new THREE.MeshNormalMaterial();
- {
- const label = new TextSprite("");
- label.setTextColor({r: 140, g: 250, b: 140, a: 1.0});
- label.setBorderColor({r: 0, g: 0, b: 0, a: 1.0});
- label.setBackgroundColor({r: 0, g: 0, b: 0, a: 1.0});
- label.fontsize = 16;
- label.material.depthTest = false;
- label.material.opacity = 1;
- azimuth.label = label;
- }
- azimuth.center = new THREE.Mesh(sg, sm);
- azimuth.target = new THREE.Mesh(sg, sm);
- azimuth.north = new THREE.Mesh(sg, sm);
- azimuth.centerToNorth = createLine();
- azimuth.centerToTarget = createLine();
- azimuth.centerToTargetground = createLine();
- azimuth.targetgroundToTarget = createLine();
- azimuth.circle = createCircle();
- azimuth.node = new THREE.Object3D();
- azimuth.node.add(
- azimuth.centerToNorth,
- azimuth.centerToTarget,
- azimuth.centerToTargetground,
- azimuth.targetgroundToTarget,
- azimuth.circle,
- azimuth.label,
- azimuth.center,
- azimuth.target,
- azimuth.north,
- );
- return azimuth;
- }
- /*
-
- */
|