@@ -205,6 +205,136 @@ export default class LabelLayer extends BaseLayer {
205205 return labelIcon ;
206206 }
207207
208+ /**
209+ * 添加图标注记
210+ * @function module:客户端可视化.LabelLayer.prototype.appendLabelIconEx
211+ * @param {Number } lon 经度
212+ * @param {Number } lat 纬度
213+ * @param {Number } height 高程
214+ * @param {Object } [options] 可配置参数
215+ * @param {String } [options.iconUrl] 图标路径,默认值: undefined
216+ * @param {String } [options.text] 注记文字内容,默认值: undefined
217+ * @param {Number } [options.disableDepthTestDistance] 图片和文字注记的深度测试
218+ * @param {NearFarScalar } [options.translucencyByDistance] 透明显示参数 默认值: new NearFarScalar(1.5e5, 1.0, 1.5e9, 0.0)
219+ * @param {NearFarScalar } [options.scaleByDistance] 缩放距离参数 默认值: new Cesium.NearFarScalar(1.5e2, 1.5, 1.5e7, 0.0)
220+ * @param {Number } [options.iconWidth] 图标宽度 默认值: 64
221+ * @param {Number } [options.iconHeight] 图标高度 默认值: 64
222+ * @param {Cartesian2 } [options.icoPixelOffset] 图标偏移 默认值: Cartesian2.ZERO
223+ * @param {NearFarScalar } [options.icoPixelOffsetScaleByDistance] 图标偏移值缩放距离参数 默认值: undefined
224+ * @param {Number } [options.icoVerticalOrigin] 图标相对于原点的竖直位置 默认值: VerticalOrigin.CENTER
225+ * @param {Number } [options.icoHorizontalOrigin] 图标相对于原点的水平位置 默认值: HorizontalOrigin.TOP
226+ * @param {String } [options.font] 字体 这里将字体和大小放在一起 eg:'14pt 楷体'
227+ * @param {Cartesian2 } [options.labelPixelOffset] 默认值: new Cartesian2(0.0, -iconHeight / 4)
228+ * @param {NearFarScalar } [options.labelPixelOffsetScaleByDistance] 文字注记偏移值缩放距离参数默认值: new NearFarScalar(1.5e5, 1.5, 1.5e7, 0.0)
229+ * @param {Color } [options.labelFillColor] 默认值: Color.WHITE
230+ * @param {Color } [options.labelBackgroundColor] 默认值: new Color(0.165, 0.165, 0.165, 0.8)
231+ * @param {Bool } [options.labelShow] 默认值: true
232+ * @param {BOOL } [options.labelShowBackground] 默认值: false
233+ * @param {Number } [options.labelStyle] 默认值: LabelStyle.FILL_AND_OUTLINE
234+ * @param {Color } [options.labelOutlineWidth] 默认值: 1
235+ * @param {String } [options.labelVerticalOrigin] 文字注记相对于原点的竖直位置 默认值: VerticalOrigin.BOTTOM
236+ * @param {String } [options.labelHorizontalOrigin] 文字注记相对于原点的水平位置 默认值: HorizontalOrigin.BOTTOM
237+ * @param {String } [options.attribute] 属性参数 默认值: undefined
238+ * @example
239+ * const options = { iconUrl: '/car.png', text: '注记文本', font: '14pt 楷体', labelShowBackground: true, attribute: '这是属性信息查询时可以看到' }
240+ * const labelIcon = webGlobe.appendLabelIconEx(110, 33, 0, options);
241+ * @returns {Entity } labelIcon 图标注记对象 移除通过removeEntity(entity)
242+ */
243+ appendLabelIconEx ( lon , lat , height , options ) {
244+ // eslint-disable-next-line no-param-reassign
245+ options = Cesium . defaultValue ( options , { } ) ;
246+
247+ const text = Cesium . defaultValue ( options . text , undefined ) ;
248+ const iconUrl = Cesium . defaultValue ( options . iconUrl , undefined ) ;
249+
250+ if ( ! Cesium . defined ( text ) && ! Cesium . defined ( iconUrl ) ) {
251+ // eslint-disable-next-line no-console
252+ console . log ( 'text 和 iconUrl 都未定义,无法正常添加 labelIcon' ) ;
253+ return null ;
254+ }
255+
256+ const translucencyByDistance = Cesium . defaultValue ( options . translucencyByDistance , new Cesium . NearFarScalar ( 1.5e5 , 1.0 , 1.5e9 , 0.0 ) ) ;
257+ const scaleByDistance = Cesium . defaultValue ( options . scaleByDistance , new Cesium . NearFarScalar ( 1.5e2 , 1.5 , 1.5e7 , 0.0 ) ) ;
258+ const disableDepthTestDistance = Cesium . defaultValue ( options . disableDepthTestDistance , Number . POSITIVE_INFINITY ) ;
259+
260+ const iconWidth = Cesium . defaultValue ( options . iconWidth , 64 ) ;
261+ const iconHeight = Cesium . defaultValue ( options . iconHeight , 64 ) ;
262+ const icoPixelOffset = Cesium . defaultValue ( options . icoPixelOffset , new Cesium . Cartesian2 ( 0.0 , 0.0 ) ) ;
263+ const icoPixelOffsetScaleByDistance = Cesium . defaultValue ( options . icoPixelOffsetScaleByDistance , undefined ) ;
264+ const icoVerticalOrigin = Cesium . defaultValue ( options . icoVerticalOrigin , Cesium . VerticalOrigin . CENTER ) ;
265+ const icoHorizontalOrigin = Cesium . defaultValue ( options . icoHorizontalOrigin , Cesium . HorizontalOrigin . TOP ) ;
266+
267+ const font = Cesium . defaultValue ( options . font , '14pt 楷体' ) ;
268+ const labelPixelOffset = Cesium . defaultValue ( options . labelPixelOffset , new Cesium . Cartesian2 ( 0.0 , - iconHeight / 2 ) ) ;
269+ const labelPixelOffsetScaleByDistance = Cesium . defaultValue (
270+ options . labelPixelOffsetScaleByDistance ,
271+ new Cesium . NearFarScalar ( 1.5e5 , 1.5 , 1.5e7 , 0.0 )
272+ ) ;
273+ const labelFillColor = Cesium . defaultValue ( options . labelFillColor , Cesium . Color . WHITE ) ;
274+ const labelShowBackground = Cesium . defaultValue ( options . labelShowBackground , false ) ;
275+ const labelBackgroundColor = Cesium . defaultValue ( options . labelBackgroundColor , new Cesium . Color ( 0.165 , 0.165 , 0.165 , 0.8 ) ) ;
276+ const labelShow = Cesium . defaultValue ( options . labelShow , true ) ;
277+ const labelStyle = Cesium . defaultValue ( options . labelStyle , Cesium . LabelStyle . FILL_AND_OUTLINE ) ;
278+ const labelOutlineWidth = Cesium . defaultValue ( options . labelOutlineWidth , 1 ) ;
279+ const labelVerticalOrigin = Cesium . defaultValue ( options . labelVerticalOrigin , Cesium . VerticalOrigin . BOTTOM ) ;
280+ const labelHorizontalOrigin = Cesium . defaultValue ( options . labelHorizontalOrigin , Cesium . HorizontalOrigin . BOTTOM ) ;
281+
282+ const attribute = Cesium . defaultValue ( options . attribute , undefined ) ;
283+
284+ const entity = {
285+ name : Cesium . defined ( text ) ? text : 'defaut' ,
286+ position : Cesium . Cartesian3 . fromDegrees ( lon , lat , height ) ,
287+
288+ description : attribute
289+ } ;
290+
291+ if ( Cesium . defined ( iconUrl ) ) {
292+ entity . billboard = {
293+ // 图标
294+ image : iconUrl ,
295+ width : iconWidth ,
296+ height : iconHeight ,
297+ pixelOffset : icoPixelOffset ,
298+ pixelOffsetScaleByDistance : icoPixelOffsetScaleByDistance ,
299+ // 随远近隐藏
300+ translucencyByDistance,
301+ // 随远近缩放
302+ scaleByDistance,
303+ // 定位点
304+ verticalOrigin : icoVerticalOrigin ,
305+ horizontalOrigin : icoHorizontalOrigin ,
306+ disableDepthTestDistance
307+ } ;
308+ }
309+
310+ if ( Cesium . defined ( text ) ) {
311+ entity . label = {
312+ // 文字标签
313+ text,
314+ font,
315+ show : labelShow ,
316+ style : labelStyle ,
317+ fillColor : labelFillColor ,
318+ showBackground : labelShowBackground ,
319+ backgroundColor : labelBackgroundColor ,
320+ outlineWidth : labelOutlineWidth ,
321+ verticalOrigin : labelVerticalOrigin , // 垂直方向以底部来计算标签的位置
322+ horizontalOrigin : labelHorizontalOrigin , // 原点在下方
323+ // heightReference: heightReference,
324+ pixelOffset : labelPixelOffset , // x,y方向偏移 相对于屏幕
325+ pixelOffsetScaleByDistance : labelPixelOffsetScaleByDistance ,
326+ // 随远近缩放
327+ scaleByDistance,
328+ // 随远近隐藏
329+ translucencyByDistance,
330+ disableDepthTestDistance
331+ } ;
332+ }
333+
334+ const labelIcon = this . viewer . entities . add ( entity ) ;
335+ return labelIcon ;
336+ }
337+
208338 /**
209339 * 添加图标注记
210340 * @function module:客户端可视化.LabelLayer.prototype.appendLabelIconComm
0 commit comments