Class: MeasureLengthTool

MeasureLengthTool

new MeasureLengthTool(viewer, options)

engineExtensions/tools/MeasureLengthTool.js, line 3

距离测量工具

Name Type Description
viewer Object

viewer对象

options Object

包含以下属性的对象

Name Type Default Description
callBack function function(result, positions){} 可选

回调函数

labelCallBack function function(currentLength, totalLength, label){} 可选

测量完毕后提示框的回调函数,可以覆盖提示内容

labelStyle LabelGraphics {} 可选

labelStyle 提示框样式,参考LabelGraphics

lineStyle PolylineGraphics {} 可选

lineStyle 测量线式,参考PolylineGraphics

pointStyle PointGraphics {} 可选

lineStyle 测量点样式,参考PointGraphics

billboardStyle Billboard {} 可选

billboardStyle 测量点图标样式,参考Billboard

closePointStyle Billboard {} 可选

closePointStyle 删除测量结果图标样式,参考Billboard

showMoreInfo Boolean false 可选

是否显示详细信息。默认不显示。

exHeight Number 0 可选

附加高程偏移 (避免遮挡)

disableDepthTestDistance Number Number.POSITIVE_INFINITY 可选

只要小于这个距离深度检测就会失效,就会一直显示在最前面 不会被遮挡

isTerrain Boolean false 可选

是否针对地形,为true时对地形数据进行贴地距离测量,为false时进行直线距离测量

paneNum Number 32 可选

地形贴地距离测量中,向每段中插入采样点的数量

classificationType Number 0 可选

测量区域的绘制结果显示,区分地形、模型,为0代表在地形上绘制,为1代表在模型上绘制,为2代表同时在地形和模型上绘制

style Cesium.LabelStyle Cesium.LabelStyle.FILL 可选

label 文字的样式,支持填充、线框。填充和线框, FILL, OUTLINE, FILL_AND_OUTLINE

font String '12pt 楷体' 可选

label 的字体以及大小 @see https://html.spec.whatwg.org/multipage/canvas.html#text-styles

fillColor Cesium.Color Cesium.Color.WHITE 可选

label 的字体颜色

outlineColor Cesium.Color Cesium.Color.WHITE 可选

label 文字线框的颜色

outlineWidth Number 4.0 可选

label 的外轮廓边线

verticalOrigin Cesium.VerticalOrigin Cesium.VerticalOrigin.BOTTOM 可选

label 的摆放位置

showBackground Boolean true 可选

是否显示 label 的背景

backgroundColor Cesium.Color new Cesium.Color(0, 0, 0, 0.4) 可选

lable 背景的颜色

pixelOffset Cesium.Cartesian2 new Cesium.Cartesian2(0, -4) 可选

label 相对于设定点的偏移位置

unit String 'kilometers' 可选

显示距离的单位

fixNum Number '4 or 0' 可选

显示距离的小数点位数,unit为kilometers默认值为4,为meters时,默认值为0

pointIcon String '' 可选

测量点的图标,不传则用默认图标

pointIconWith Number 16 可选

测量点图标的宽度

pointIconHeight Number 16 可选

测量点图标的高度

pointIconScale Number 1.2 可选

测量点图标的缩放比例

pointIconOffsetX Number 0 可选

测量点图标的X轴偏移,用于微调图标位置

pointIconOffsetY Number -5 可选

测量点图标的Y轴偏移,用于微调图标位置

closeIcon String '' 可选

删除测量结果图标,不传则用默认图标

closeIconWith Number 16 可选

删除测量结果图标的宽度

closeIconHeight Number 16 可选

删除测量结果图标的高度

closeIconScale Number 1 可选

删除测量结果图标的缩放比例

closeIconOffsetX Number 3 可选

删除测量结果图标的X轴偏移,用于微调图标位置

closeIconOffsetY Number 3 可选

删除测量结果图标的Y轴偏移,用于微调图标位置

enableScaleByDistance Number true 可选

是否启用标签随视角高度缩放功能

scaleByDistance Number 可选

标签大小随视角高度缩放函数,用户可自定义,不传则使用默认函数,会传入一个当前的相机视角高度,返回一个NearFarScale函数对象,详见下方示例

isContinueDraw Number true 可选

是否连续绘制,true:是,false:否

isMultiple Number true 可选

是否显示多个测量结果,true:是,false:否

showRuntimeResult Number false 可选

是否显示实时的量算结果,true:是,false:否

Author:
  • 韩彦生 modify 修改人:周凌风 2020年9月25日 添加针对地形数据进行贴地距离测量的功能
Example
// ES5引入方式
const { MeasureLengthTool } = zondy.cesium
// ES6引入方式
import { MeasureLengthTool } from "@mapgis/webclient-cesium-plugin"

function callBackFunction(arg){}
const measureLengthTool = new MeasureLengthTool(viewer,
{
    callBack:callBackFunction
    showMoreInfo:false,
    isTerrain:true,
    paneNum:32,
    scaleByDistance: function(height) {
        if (height < 30) {
            return new NearFarScalar(30, 3, 180, 0);
        } else if (height < 60) {
            return new NearFarScalar(60, 3, 360, 0);
        } else if (height < 120) {
            return new NearFarScalar(120, 3, 720, 0);
        } else if (height < 240) {
            return new NearFarScalar(240, 2, 1200, 0);
        } else if (height < 480) {
            return new NearFarScalar(480, 2, 2400, 0);
        } else if (height < 960) {
            return new NearFarScalar(960, 2, 4800, 0);
        } else if (height < 1920) {
            return new NearFarScalar(1920, 2, 9600, 0);
        } else if (height < 3840) {
            return new NearFarScalar(3840, 2, 19200, 0);
        } else if (height < 7680) {
            return new NearFarScalar(7680, 2, 38400, 0);
        } else if (height < 15360) {
            return new NearFarScalar(15360, 2, 76800, 0);
        } else if (height < 30720) {
            return new NearFarScalar(30720, 2, 153600, 0);
        } else if (height < 61440) {
            return new NearFarScalar(61440, 2, 307200, 0);
        } else if (height < 122880) {
            return new NearFarScalar(122880, 2, 614400, 0);
        } else if (height < 245760) {
            return new NearFarScalar(245760, 2, 1228800, 0);
        } else if (height < 491520) {
            return new NearFarScalar(491520, 2, 2457600, 0);
        } else if (height < 983040) {
            return new NearFarScalar(983040, 2, 4915200, 0);
        } else if (height < 1966080) {
            return new NearFarScalar(1966080, 2, 9830400, 0);
        } else if (height < 3932160) {
            return new NearFarScalar(3932160, 1, 19660800, 0);
        } else if (height < 7864320) {
            return new NearFarScalar(7864320, 1, 39321600, 0);
        } else if (height < 15728640) {
            return new NearFarScalar(15728640, 1, 78643200, 0);
        }
        return new NearFarScalar(15728640, 1, 78643200, 0);
    }
});
measureLengthTool.startTool();  //开始测量
//measureLengthTool.stopTool(); //结束测量

Members

distanceResultNumber

返回测量结果

isTerrainBoolean

是否贴地测量

showMoreInfoBoolean

显示详细信息

Methods

clear()

engineExtensions/tools/MeasureLengthTool.js, line 249

清除所有测量结果,仍可绘制(绘制事件仍然是激活状态)

startTool()

engineExtensions/tools/MeasureLengthTool.js, line 142

开始测量

stopTool(isKeepResult)

engineExtensions/tools/MeasureLengthTool.js, line 230

结束测量,测量工具处于不能绘制(不激活状态)

Name Type Default Description
isKeepResult Boolean false 可选

是否保留测量结果。默认为false不保留测量结果