Draw

Draw

new Draw()

绘制类 eg:new zz3d.Draw(viewer, {})

Extends

  • Evented

Methods

addBillboard(point, styleopt) → {Entity}

添加billboard点数据

Parameters:
Name Type Attributes Default Description
point Cartesian3

点位置

style Object <optional>
{}

样式信息

Returns:
Type
Entity

addPoint(point, styleopt) → {Entity}

添加billboard点数据

Parameters:
Name Type Attributes Default Description
point Cartesian3

点位置

style Object <optional>
{}

样式信息

Returns:
Type
Entity

addPolygon(coordinates, styleopt) → {Entity}

添加面数据

Parameters:
Name Type Attributes Default Description
coordinates Array

点组 点类型[经,纬,高]

style Object <optional>
{}

样式信息

Properties
Name Type Description
color String

颜色信息 eg:"#ffff00"

opacity Number

透明度

stRotation Number

视频纹理旋转角度 范围0~360

clampToGround Boolean

是否贴地

video String

用视频作为纹理贴图时的视频地址

Returns:
Type
Entity

addPolyline(coordinates, styleopt) → {Entity}

添加线数据

Parameters:
Name Type Attributes Default Description
coordinates Array

点组 点类型[经,纬,高]

style Object <optional>
{}

样式信息

Returns:
Type
Entity

bindDeleteContextmenu(entity)

给entity绑定右键删除菜单

Parameters:
Name Type Description
entity Entity

目标实体

bindExtraEntity(entity, attributeopt)

绑定外部非Draw产生的entity到标绘

Parameters:
Name Type Attributes Default Description
entity Entity

外部实体

attribute Object <optional>
{}

属性信息

bindSelectEvent()

绑定鼠标选中事件

clearDraw(bContinueDraw) → {Object}

删除所有绘制实体

Parameters:
Name Type Description
bContinueDraw Boolean

是否继续现有绘制

Returns:

返回绘制对象本身

Type
Object

closeTooltip()

关闭提示框

deleteAll()

删除所有实体 等同于clearDraw 兼容不同习惯命名

deleteEntity(entity)

删除单个实体

Parameters:
Name Type Description
entity Entity

目标实体

deleteEntityById(id)

根据ID删除单个实体

Parameters:
Name Type Description
id String

目标实体ID

deleteEntityByTypeId(id)

根据类型ID批量删除实体

Parameters:
Name Type Description
id String

类型id

destroy()

销毁对象

destroySelectEvent()

销毁鼠标选中事件

endDraw() → {Object}

用于外部控制,完成绘制,比如手机端无法双击结束

Returns:

返回绘制对象本身

Type
Object

flyTo(entity, optsopt)

定位实体 实际调用的是ViewerEx.flyTo接口 opts详情参考ViewerEx.flyTo接口说明

Parameters:
Name Type Attributes Default Description
entity Entity

目标实体

opts Object <optional>
{}

带有以下属性的对象:

Properties
Name Type Attributes Default Description
duration Object <optional>
3

飞行时间

getCoordinates(entity) → {Array}

获取实体的经纬度值 坐标数组

Parameters:
Name Type Description
entity Entity

目标实体

Returns:
Type
Array

getCurrentEntity() → {Object}

获取当前编辑的要素

Returns:

返回正在编辑的实体

Type
Object

getDataSource() → {Object}

获取数据源

Returns:
Type
Object

getEntityById(id, bContinueDraw) → {Entity}

根据ID获取实体

Parameters:
Name Type Description
id String

实体id

bContinueDraw Boolean

是否继续现有绘制

Returns:
Type
Entity

getEntityByTypeId(id, bContinueDraw) → {Array}

根据类型ID获取实体

Parameters:
Name Type Description
id String

类型id

bContinueDraw Boolean

是否继续现有绘制

Returns:
Type
Array

getEntitys(noStop) → {Array}

获取所有绘制的实体对象列表

Parameters:
Name Type Description
noStop Boolean

是否不停止现有绘制

Returns:
Type
Array

getPositions(entity) → {Array}

获取实体的坐标数组 Cart3类型

Parameters:
Name Type Description
entity Entity

目标实体

Returns:
Type
Array

hasDraw() → {Boolean}

是否存在绘制

Returns:
Type
Boolean

hasDrawing() → {Boolean}

获取是否还在绘制中

Returns:
Type
Boolean

hasEdit(var)

设置是否允许编辑

Parameters:
Name Type Description
var Boolean

是否允许编辑

initialize(viewer, optionsopt)

初始化

Parameters:
Name Type Attributes Default Description
viewer Viewer

场景对象

options Object <optional>
{}

带有以下属性的对象:

Properties
Name Type Attributes Default Description
removeScreenSpaceEvent Boolean <optional>
true

是否移除viewer.screenSpaceEventHandler的左键单双击响应函数

hasEdit Boolean <optional>
true

是否开启编辑

heightOffset Boolean <optional>
0

绘制抬高

isContinued Boolean <optional>
false

是否连续绘制

isAutoEditing Boolean <optional>
true

绘制完成后是否自动激活编辑

tooltipPosOffset Array <optional>
[30,0]

tooltip的显示位置相对鼠标位置的偏移量 eg:[30,-30]表示向右偏移30像素,向上偏移30像素

eventType Object <optional>
{}

操作模式 可根据不同需求灵活配置 0表示无操作 1左键单击 2左键双击 3中键单击 4右键单击 5按下ESC
该参数可在config.json中配置 默认值如下:
"eventType": {
"addPoint":1,
"deletePoint":5,
"drawSuccess":[2,4],
"drawCancel":0 //默认情况下没有配置取消绘制
},

Properties
Name Type Attributes Description
addPoint Number | Array <optional>

添加点的操作

deletePoint Number | Array <optional>

删除上个有效点的操作

drawSuccess Number | Array <optional>

绘制完成的操作

drawCancel Number | Array <optional>

取消绘制的操作

isMyEntity(entity) → {Boolean}

是否为当前编辑器编辑的实体

Parameters:
Name Type Description
entity Entity

目标实体

Returns:
Type
Boolean

jsonToEntity(json, isClear, isFly) → {Array}

加载goejson数据 兼容旧版本方法名 等同于loadJson

Parameters:
Name Type Description
json JSON

json对象

isClear Boolean

是否清除其他实体

isFly Boolean

是否飞到实体位置

Returns:

实体数组

Type
Array

loadJson(json, optsopt) → {Array}

加载goejson数据 定位有两种选择 flyTo或flyToByBoundingSphere
区别在于flyTo最终是按照总区域中心点定位的 flyToByBoundingSphere是按照总区域的包围球来定位的 选择其中一个即可 一般来说包围球定位效果更好

Parameters:
Name Type Attributes Default Description
json JSON

json对象

opts Object <optional>
{}

含有以下属性的对象:

Properties
Name Type Attributes Description
clear Boolean <optional>

是否清除其他实体

flyTo Boolean <optional>

是否飞到实体位置 若为true 则会执行ViewerEx.flyTo接口 opts中可添加视角设置相关参数 详情参考ViewerEx.flyTo参数说明

flyToByBoundingSphere Boolean <optional>

是否飞到实体位置 若为true 则会执行ViewerEx.flyToByBoundingSphere接口 opts中可添加视角设置相关参数 详情参考ViewerEx.flyToByBoundingSphere参数说明

onEachFeature function <optional>

添加到地图前的回调方法,接收参数为(feature, feature.properties.type)

onEachEntity function <optional>

添加到地图后的回调方法 接收参数为(feature, entity)

typeID String <optional>

给当前json文件下的实体添加类型标识 可通过标识批量获取或删除实体

Returns:

实体数组

Type
Array

remove(entity)

删除单个实体 兼容不同习惯命名

Parameters:
Name Type Description
entity Entity

目标实体

removeAll()

删除所有实体 等同于clearDraw 兼容不同习惯命名

setPositions(positions, entity) → {Entity}

修改坐标、高程

Parameters:
Name Type Description
positions Array

点组信息 点类型Cart3

entity Entity

目标实体

Returns:

返回修改的实体

Type
Entity

setTooltipPosOffset(arropt)

绘制时tooltip的显示位置相对鼠标位置的偏移量 eg:[30,-30]表示向右偏移30像素,向上偏移30像素

Parameters:
Name Type Attributes Default Description
arr Array <optional>
[30,0]

相对鼠标位置的偏移量,像素单位

setVisible(visible)

设置可见性

Parameters:
Name Type Description
visible Boolean

是否显示

startDraw(attributeopt, drawOkCalbackopt) → {Entity}

开始绘制

Parameters:
Name Type Attributes Default Description
attribute Object <optional>
{}

带有以下属性的对象:

Properties
Name Type Attributes Default Description
id String <optional>

实体ID 可以通过ID来删除实体 不传时会自动生成 可通过ent.id来获取 需要注意的是,ID重复时会自动修改ID

type String <optional>

绘制类型 参考Cesium中Entity包含的类型 纯小写字母

allowSelfIntersect Boolean <optional>
true

绘制polyline/polygon时是否允许点组自交

success function <optional>

绘制完成回调

cancel function <optional>

绘制完成回调

style Object <optional>
{}

绘制样式 参考Entity中各种图元的样式

drawOkCalback function <optional>

绘制完成回调 作用和success相同

Returns:

返回绘制的实体

Type
Entity

startEditing(entity)

开始编辑

Parameters:
Name Type Description
entity Entity

编辑对象

stopDraw() → {Object}

停止绘制

Returns:

返回绘制对象本身

Type
Object

stopEditing()

停止编辑

toGeoJSON(entity, bContinueDraw, bClose) → {Object}

转换实体为geojson

Parameters:
Name Type Description
entity Entity

目标实体

bContinueDraw Boolean

是否继续现有绘制

bClose Boolean

导出点组是否闭合

Returns:
Type
Object

updateAttribute(attribute, entity, onlyAttributesopt) → {Entity}

修改属性

Parameters:
Name Type Attributes Default Description
attribute Object

带有以下属性的对象:

Properties
Name Type Attributes Default Description
style Object <optional>
{}

样式信息

attr Object <optional>
{}

属性信息

entity Entity

目标实体

onlyAttributes Boolean <optional>
false

是否仅更新属性

Returns:

返回修改后的对象

Type
Entity

updateStyle(styleopt, entity)

修改实体样式

Parameters:
Name Type Attributes Default Description
style Object <optional>
{}

样式信息

entity Entity

目标实体