@@ -205,6 +205,131 @@ 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+ options = defaultValue ( options , { } ) ;
245+
246+ let text = defaultValue ( options . text , undefined ) ;
247+ let iconUrl = defaultValue ( options . iconUrl , undefined ) ;
248+
249+ if ( ! defined ( text ) && ! defined ( iconUrl ) ) {
250+ console . log ( 'text 和 iconUrl 都未定义,无法正常添加 labelIcon' ) ;
251+ return null ;
252+ }
253+
254+ let translucencyByDistance = defaultValue ( options . translucencyByDistance , new NearFarScalar ( 1.5e5 , 1.0 , 1.5e9 , 0.0 ) ) ;
255+ let scaleByDistance = defaultValue ( options . scaleByDistance , new NearFarScalar ( 1.5e2 , 1.5 , 1.5e7 , 0.0 ) ) ;
256+ let disableDepthTestDistance = defaultValue ( options . disableDepthTestDistance , Number . POSITIVE_INFINITY ) ;
257+
258+ let iconWidth = defaultValue ( options . iconWidth , 64 ) ;
259+ let iconHeight = defaultValue ( options . iconHeight , 64 ) ;
260+ let icoPixelOffset = defaultValue ( options . icoPixelOffset , new Cartesian2 ( 0.0 , 0.0 ) ) ;
261+ let icoPixelOffsetScaleByDistance = defaultValue ( options . icoPixelOffsetScaleByDistance , undefined ) ;
262+ let icoVerticalOrigin = defaultValue ( options . icoVerticalOrigin , VerticalOrigin . CENTER ) ;
263+ let icoHorizontalOrigin = defaultValue ( options . icoHorizontalOrigin , HorizontalOrigin . TOP ) ;
264+
265+ let font = defaultValue ( options . font , '14pt 楷体' ) ;
266+ let labelPixelOffset = defaultValue ( options . labelPixelOffset , new Cartesian2 ( 0.0 , - iconHeight / 2 ) ) ;
267+ let labelPixelOffsetScaleByDistance = defaultValue ( options . labelPixelOffsetScaleByDistance , new NearFarScalar ( 1.5e5 , 1.5 , 1.5e7 , 0.0 ) ) ;
268+ let labelFillColor = defaultValue ( options . labelFillColor , Color . WHITE ) ;
269+ let labelShowBackground = defaultValue ( options . labelShowBackground , false ) ;
270+ let labelBackgroundColor = defaultValue ( options . labelBackgroundColor , new Color ( 0.165 , 0.165 , 0.165 , 0.8 ) ) ;
271+ let labelShow = defaultValue ( options . labelShow , true ) ;
272+ let labelStyle = defaultValue ( options . labelStyle , LabelStyle . FILL_AND_OUTLINE ) ;
273+ let labelOutlineWidth = defaultValue ( options . labelOutlineWidth , 1 ) ;
274+ let labelVerticalOrigin = defaultValue ( options . labelVerticalOrigin , VerticalOrigin . BOTTOM ) ;
275+ let labelHorizontalOrigin = defaultValue ( options . labelHorizontalOrigin , HorizontalOrigin . BOTTOM ) ;
276+
277+ let attribute = defaultValue ( options . attribute , undefined ) ;
278+
279+ let entity = {
280+ name : defined ( text ) ? text : 'defaut' ,
281+ position : Cartesian3 . fromDegrees ( lon , lat , height ) ,
282+
283+ description : attribute
284+ } ;
285+
286+ if ( defined ( iconUrl ) ) {
287+ entity . billboard = {
288+ //图标
289+ image : iconUrl ,
290+ width : iconWidth ,
291+ height : iconHeight ,
292+ pixelOffset : icoPixelOffset ,
293+ pixelOffsetScaleByDistance : icoPixelOffsetScaleByDistance ,
294+ //随远近隐藏
295+ translucencyByDistance : translucencyByDistance ,
296+ //随远近缩放
297+ scaleByDistance : scaleByDistance ,
298+ //定位点
299+ verticalOrigin : icoVerticalOrigin ,
300+ horizontalOrigin : icoHorizontalOrigin ,
301+ disableDepthTestDistance : disableDepthTestDistance
302+ } ;
303+ }
304+
305+ if ( defined ( text ) ) {
306+ entity . label = {
307+ //文字标签
308+ text : text ,
309+ font : font ,
310+ show : labelShow ,
311+ style : labelStyle ,
312+ fillColor : labelFillColor ,
313+ showBackground : labelShowBackground ,
314+ backgroundColor : labelBackgroundColor ,
315+ outlineWidth : labelOutlineWidth ,
316+ verticalOrigin : labelVerticalOrigin , //垂直方向以底部来计算标签的位置
317+ horizontalOrigin : labelHorizontalOrigin , //原点在下方
318+ // heightReference: heightReference,
319+ pixelOffset : labelPixelOffset , //x,y方向偏移 相对于屏幕
320+ pixelOffsetScaleByDistance : labelPixelOffsetScaleByDistance ,
321+ //随远近缩放
322+ scaleByDistance : scaleByDistance ,
323+ //随远近隐藏
324+ translucencyByDistance : translucencyByDistance ,
325+ disableDepthTestDistance : disableDepthTestDistance
326+ } ;
327+ }
328+
329+ let labelIcon = this . viewer . entities . add ( entity ) ;
330+ return labelIcon ;
331+ }
332+
208333 /**
209334 * 添加图标注记
210335 * @function module:客户端可视化.LabelLayer.prototype.appendLabelIconComm
0 commit comments