@xtctwins/tctwins-core 1.1.9 → 1.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3046,7 +3046,7 @@ case WAITING_FOR_TARGET_LONG_TOUCH_END$1:if(_this17.pointerLens){_this17.pointer
3046
3046
  * @type {AnnotationsPlugin}
3047
3047
  */_this20.plugin=cfg.plugin;_this20._container=cfg.container;if(!_this20._container){throw"config missing: container";}if(!cfg.markerElement&&!cfg.markerHTML){throw"config missing: need either markerElement or markerHTML";}if(!cfg.labelElement&&!cfg.labelHTML){throw"config missing: need either labelElement or labelHTML";}_this20._htmlDirty=false;if(cfg.markerElement){_this20._marker=cfg.markerElement;_this20._marker.addEventListener("click",_this20._onMouseClickedExternalMarker=function(){_this20.plugin.fire("markerClicked",_this20);});_this20._marker.addEventListener("dblclick",_this20._onMouseDblClickedExternalMarker=function(){_this20.plugin.fire("markerDoubleClicked",_this20);});_this20._marker.addEventListener("mouseenter",_this20._onMouseEnterExternalMarker=function(){_this20.plugin.fire("markerMouseEnter",_this20);});_this20._marker.addEventListener("mouseleave",_this20._onMouseLeaveExternalMarker=function(){_this20.plugin.fire("markerMouseLeave",_this20);});_this20._markerExternal=true;// Don't destroy marker when destroying Annotation
3048
3048
  }else{_this20._markerHTML=cfg.markerHTML;_this20._htmlDirty=true;_this20._markerExternal=false;}if(cfg.labelElement){_this20._label=cfg.labelElement;_this20._label.addEventListener("click",function(){_this20.plugin.fire("labelClicked",_this20);});_this20._labelExternal=true;// Don't destroy marker when destroying Annotation
3049
- }else{_this20._labelHTML=cfg.labelHTML;_this20._htmlDirty=true;_this20._labelExternal=false;}_this20._markerShown=!!cfg.markerShown;_this20._labelShown=!!cfg.labelShown;_this20._values=cfg.values||{};_this20._layoutDirty=true;_this20._visibilityDirty=true;_this20._buildHTML();_this20._onTick=_this20.scene.on("tick",function(){if(_this20._htmlDirty){_this20._buildHTML();_this20._htmlDirty=false;_this20._layoutDirty=true;_this20._visibilityDirty=true;}if(_this20._layoutDirty||_this20._visibilityDirty){if(_this20._markerShown||_this20._labelShown){_this20._updatePosition();_this20._layoutDirty=false;}}if(_this20._visibilityDirty){_this20._marker.style.visibility=_this20.visible&&_this20._markerShown?"visible":"hidden";_this20._label.style.visibility=_this20.visible&&_this20._markerShown&&_this20._labelShown?"visible":"hidden";_this20._visibilityDirty=false;}});_this20.on("canvasPos",function(){_this20._layoutDirty=true;});_this20.on("visible",function(){_this20._visibilityDirty=true;});_this20.setMarkerShown(cfg.markerShown!==false);_this20.setLabelShown(cfg.labelShown);/**
3049
+ }else{_this20._labelHTML=cfg.labelHTML;_this20._htmlDirty=true;_this20._labelExternal=false;}_this20._markerShown=!!cfg.markerShown;_this20._labelShown=!!cfg.labelShown;_this20._labelPlacement=cfg.labelPlacement||"right";_this20._labelOffset=cfg.labelOffset||null;_this20._values=cfg.values||{};_this20._layoutDirty=true;_this20._visibilityDirty=true;_this20._buildHTML();_this20._onTick=_this20.scene.on("tick",function(){if(_this20._htmlDirty){_this20._buildHTML();_this20._htmlDirty=false;_this20._layoutDirty=true;_this20._visibilityDirty=true;}if(_this20._layoutDirty||_this20._visibilityDirty){if(_this20._markerShown||_this20._labelShown){_this20._updatePosition();_this20._layoutDirty=false;}}if(_this20._visibilityDirty){_this20._marker.style.visibility=_this20.visible&&_this20._markerShown?"visible":"hidden";_this20._label.style.visibility=_this20.visible&&_this20._markerShown&&_this20._labelShown?"visible":"hidden";_this20._visibilityDirty=false;}});_this20.on("canvasPos",function(){_this20._layoutDirty=true;});_this20.on("visible",function(){_this20._visibilityDirty=true;});_this20.setMarkerShown(cfg.markerShown!==false);_this20.setLabelShown(cfg.labelShown);/**
3050
3050
  * Optional World-space position for {@link Camera#eye}, used when this Annotation is associated with a {@link Camera} position.
3051
3051
  *
3052
3052
  * Undefined by default.
@@ -3076,7 +3076,9 @@ case WAITING_FOR_TARGET_LONG_TOUCH_END$1:if(_this17.pointerLens){_this17.pointer
3076
3076
  if(utils.isArray(markerHTML)){markerHTML=markerHTML.join("");}markerHTML=this._renderTemplate(markerHTML.trim());var markerFragment=document.createRange().createContextualFragment(markerHTML);this._marker=markerFragment.firstChild;this._container.appendChild(this._marker);this._marker.style.visibility=this._markerShown?"visible":"hidden";this._marker.addEventListener("click",function(){_this21.plugin.fire("markerClicked",_this21);});this._marker.addEventListener("dblclick",function(){_this21.plugin.fire("markerDoubleClicked",_this21);});this._marker.addEventListener("mouseenter",function(){_this21.plugin.fire("markerMouseEnter",_this21);});this._marker.addEventListener("mouseleave",function(){_this21.plugin.fire("markerMouseLeave",_this21);});this._marker.addEventListener("wheel",function(event){_this21.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",event));});}if(!this._labelExternal){if(this._label){this._container.removeChild(this._label);this._label=null;}var labelHTML=this._labelHTML||"<p></p>";// Make label
3077
3077
  if(utils.isArray(labelHTML)){labelHTML=labelHTML.join("");}labelHTML=this._renderTemplate(labelHTML.trim());var labelFragment=document.createRange().createContextualFragment(labelHTML);this._label=labelFragment.firstChild;this._container.appendChild(this._label);this._label.style.visibility=this._markerShown&&this._labelShown?"visible":"hidden";this._label.addEventListener("click",function(){_this21.plugin.fire("labelClicked",_this21);});this._label.addEventListener("wheel",function(event){_this21.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",event));});}}/**
3078
3078
  * @private
3079
- */},{key:"_updatePosition",value:function _updatePosition(){var boundary=this.scene.canvas.boundary;var left=boundary[0];var top=boundary[1];var canvasPos=this.canvasPos;this._marker.style.left=Math.floor(left+canvasPos[0])-12+"px";this._marker.style.top=Math.floor(top+canvasPos[1])-12+"px";this._marker.style["z-index"]=90005+Math.floor(this._viewPos[2])+1;var offsetX=20;var offsetY=-17;this._label.style.left=20+Math.floor(left+canvasPos[0]+offsetX)+"px";this._label.style.top=Math.floor(top+canvasPos[1]+offsetY)+"px";this._label.style["z-index"]=90005+Math.floor(this._viewPos[2])+1;}/**
3079
+ */},{key:"_updatePosition",value:function _updatePosition(){var boundary=this.scene.canvas.boundary;var left=boundary[0];var top=boundary[1];var canvasPos=this.canvasPos;var offset=this._labelOffset||{};var ox=offset.x||0;var oy=offset.y||0;this._marker.style.left=Math.floor(left+canvasPos[0])-12+"px";this._marker.style.top=Math.floor(top+canvasPos[1])-12+"px";this._marker.style["z-index"]=90005+Math.floor(this._viewPos[2])+1;if(this._labelPlacement==="above"){// 将标签居中显示在 marker 正上方,并叠加自定义偏移
3080
+ var labelWidth=this._label.offsetWidth||0;var labelHeight=this._label.offsetHeight||0;this._label.style.left=Math.floor(left+canvasPos[0]-labelWidth/2+ox)+"px";this._label.style.top=Math.floor(top+canvasPos[1]-12-labelHeight-4+oy)+"px";}else{// 默认显示在 marker 右侧,并叠加自定义偏移
3081
+ var offsetX=20+ox;var offsetY=-17+oy;this._label.style.left=20+Math.floor(left+canvasPos[0]+offsetX)+"px";this._label.style.top=Math.floor(top+canvasPos[1]+offsetY)+"px";}this._label.style["z-index"]=90005+Math.floor(this._viewPos[2])+1;}/**
3080
3082
  * @private
3081
3083
  */},{key:"_renderTemplate",value:function _renderTemplate(template){for(var key in this._values){if(this._values.hasOwnProperty(key)){var value=this._values[key];template=template.replace(new RegExp("{{"+key+"}}","g"),value);}}return template;}/**
3082
3084
  * Sets whether or not to show this Annotation's marker.
@@ -3115,13 +3117,21 @@ if(utils.isArray(labelHTML)){labelHTML=labelHTML.join("");}labelHTML=this._rende
3115
3117
  *
3116
3118
  * @returns {Boolean} Whether to show the label.
3117
3119
  */},{key:"getLabelShown",value:function getLabelShown(){return this._labelShown;}/**
3120
+ * Sets the pixel offset applied to the label relative to its default placement.
3121
+ *
3122
+ * @param {{x:Number, y:Number}} value The offset, e.g. `{ x: 0, y: -8 }`.
3123
+ */},{key:"labelOffset",get:/**
3124
+ * Gets the pixel offset applied to the label.
3125
+ *
3126
+ * @returns {{x:Number, y:Number}} The offset.
3127
+ */function get(){return this._labelOffset;}/**
3118
3128
  * Sets the value of a field within the HTML templates for either the Annotation's marker or label.
3119
3129
  *
3120
3130
  * See {@link AnnotationsPlugin} for more info.
3121
3131
  *
3122
3132
  * @param {String} key Identifies the field.
3123
3133
  * @param {String} value The field's value.
3124
- */},{key:"setField",value:function setField(key,value){this._values[key]=value||"";this._htmlDirty=true;}/**
3134
+ */,set:function set(value){this._labelOffset=value||null;this._layoutDirty=true;}},{key:"setField",value:function setField(key,value){this._values[key]=value||"";this._htmlDirty=true;}/**
3125
3135
  * Gets the value of a field within the HTML templates for either the Annotation's marker or label.
3126
3136
  *
3127
3137
  * See {@link AnnotationsPlugin} for more info.
@@ -3520,7 +3530,7 @@ if(utils.isArray(labelHTML)){labelHTML=labelHTML.join("");}labelHTML=this._rende
3520
3530
  */function AnnotationsPlugin(viewer,cfg){var _this22;_classCallCheck(this,AnnotationsPlugin);_this22=_callSuper(this,AnnotationsPlugin,["Annotations",viewer]);_this22._labelHTML=cfg.labelHTML||"<div></div>";_this22._markerHTML=cfg.markerHTML||"<div></div>";_this22._container=cfg.container||document.body;_this22._values=cfg.values||{};/**
3521
3531
  * The {@link Annotation}s created by {@link AnnotationsPlugin#createAnnotation}, each mapped to its {@link Annotation#id}.
3522
3532
  * @type {{String:Annotation}}
3523
- */_this22.annotations={};_this22.surfaceOffset=cfg.surfaceOffset;return _this22;}/**
3533
+ */_this22.annotations={};_this22.surfaceOffset=cfg.surfaceOffset;_this22._labelPlacement=cfg.labelPlacement;_this22._labelOffset=cfg.labelOffset;return _this22;}/**
3524
3534
  * Gets the plugin's HTML container element, if any.
3525
3535
  * @returns {*|HTMLElement|HTMLElement}
3526
3536
  */_inherits(AnnotationsPlugin,_Plugin2);return _createClass(AnnotationsPlugin,[{key:"getContainerElement",value:function getContainerElement(){return this._container;}/**
@@ -3566,7 +3576,7 @@ if(utils.isArray(labelHTML)){labelHTML=labelHTML.join("");}labelHTML=this._rende
3566
3576
  * @param {Number[]} [params.up] Optional World-space position for {@link Camera#up}, used when this Annotation is associated with a {@link Camera} position.
3567
3577
  * @param {String} [params.projection] Optional projection type for {@link Camera#projection}, used when this Annotation is associated with a {@link Camera} position.
3568
3578
  * @returns {Annotation} The new {@link Annotation}.
3569
- */,set:function set(surfaceOffset){if(surfaceOffset===undefined||surfaceOffset===null){surfaceOffset=0.3;}this._surfaceOffset=surfaceOffset;}},{key:"createAnnotation",value:function createAnnotation(params){var _this23=this;if(this.viewer.scene.components[params.id]){this.error("Viewer component with this ID already exists: "+params.id);delete params.id;}var worldPos;var entity;params.pickResult=params.pickResult||params.pickRecord;if(params.pickResult){var pickResult=params.pickResult;if(!pickResult.worldPos||!pickResult.worldNormal){this.error("Param 'pickResult' does not have both worldPos and worldNormal");}else{var normalizedWorldNormal=math.normalizeVec3(pickResult.worldNormal,tempVec3a$I);var offsetVec=math.mulVec3Scalar(normalizedWorldNormal,this._surfaceOffset,tempVec3b$z);var offsetWorldPos=math.addVec3(pickResult.worldPos,offsetVec,tempVec3c$u);worldPos=offsetWorldPos;entity=pickResult.entity;}}else{worldPos=params.worldPos;entity=params.entity;}var markerElement=null;if(params.markerElementId){markerElement=document.getElementById(params.markerElementId);if(!markerElement){this.error("Can't find DOM element for 'markerElementId' value '"+params.markerElementId+"' - defaulting to internally-generated empty DIV");}}var labelElement=null;if(params.labelElementId){labelElement=document.getElementById(params.labelElementId);if(!labelElement){this.error("Can't find DOM element for 'labelElementId' value '"+params.labelElementId+"' - defaulting to internally-generated empty DIV");}}var annotation=new Annotation(this.viewer.scene,{id:params.id,plugin:this,entity:entity,worldPos:worldPos,container:this._container,markerElement:markerElement,labelElement:labelElement,markerHTML:params.markerHTML||this._markerHTML,labelHTML:params.labelHTML||this._labelHTML,occludable:params.occludable,values:utils.apply(params.values,utils.apply(this._values,{})),markerShown:params.markerShown,labelShown:params.labelShown,eye:params.eye,look:params.look,up:params.up,projection:params.projection,visible:params.visible!==false});this.annotations[annotation.id]=annotation;annotation.on("destroyed",function(){delete _this23.annotations[annotation.id];_this23.fire("annotationDestroyed",annotation.id);});this.fire("annotationCreated",annotation.id);return annotation;}/**
3579
+ */,set:function set(surfaceOffset){if(surfaceOffset===undefined||surfaceOffset===null){surfaceOffset=0.3;}this._surfaceOffset=surfaceOffset;}},{key:"createAnnotation",value:function createAnnotation(params){var _this23=this;if(this.viewer.scene.components[params.id]){this.error("Viewer component with this ID already exists: "+params.id);delete params.id;}var worldPos;var entity;params.pickResult=params.pickResult||params.pickRecord;if(params.pickResult){var pickResult=params.pickResult;if(!pickResult.worldPos||!pickResult.worldNormal){this.error("Param 'pickResult' does not have both worldPos and worldNormal");}else{var normalizedWorldNormal=math.normalizeVec3(pickResult.worldNormal,tempVec3a$I);var offsetVec=math.mulVec3Scalar(normalizedWorldNormal,this._surfaceOffset,tempVec3b$z);var offsetWorldPos=math.addVec3(pickResult.worldPos,offsetVec,tempVec3c$u);worldPos=offsetWorldPos;entity=pickResult.entity;}}else{worldPos=params.worldPos;entity=params.entity;}var markerElement=null;if(params.markerElementId){markerElement=document.getElementById(params.markerElementId);if(!markerElement){this.error("Can't find DOM element for 'markerElementId' value '"+params.markerElementId+"' - defaulting to internally-generated empty DIV");}}var labelElement=null;if(params.labelElementId){labelElement=document.getElementById(params.labelElementId);if(!labelElement){this.error("Can't find DOM element for 'labelElementId' value '"+params.labelElementId+"' - defaulting to internally-generated empty DIV");}}var annotation=new Annotation(this.viewer.scene,{id:params.id,plugin:this,entity:entity,worldPos:worldPos,container:this._container,markerElement:markerElement,labelElement:labelElement,markerHTML:params.markerHTML||this._markerHTML,labelHTML:params.labelHTML||this._labelHTML,labelPlacement:params.labelPlacement||this._labelPlacement,labelOffset:params.labelOffset||this._labelOffset,occludable:params.occludable,values:utils.apply(params.values,utils.apply(this._values,{})),markerShown:params.markerShown,labelShown:params.labelShown,eye:params.eye,look:params.look,up:params.up,projection:params.projection,visible:params.visible!==false});this.annotations[annotation.id]=annotation;annotation.on("destroyed",function(){delete _this23.annotations[annotation.id];_this23.fire("annotationDestroyed",annotation.id);});this.fire("annotationCreated",annotation.id);return annotation;}/**
3570
3580
  * Destroys an {@link Annotation}.
3571
3581
  *
3572
3582
  * @param {String} id ID of Annotation to destroy.