new Graphic(options)
支持如下方法:
[1、给图元添加属性字段]标绘图元对象
请参考以下示例:
1、初始化标绘图层
2、添加一个多边形图元
3、新增一个类型为div的标绘对象
4、更多示例
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
|
Examples
// ES5引入方式
const { GraphicsLayer, Graphic } = zondy.cesium
// ES6引入方式
import { GraphicsLayer, Graphic } from "@mapgis/webclient-cesium-plugin"
//初始化一个标绘图层
const graphicsLayer = new GraphicsLayer(viewer, {});
viewer.scene.layers.appendGraphicsLayer(graphicsLayer);
//添加一个Marker基础标绘对象
const marker = new Graphic({
//类型
type: 'marker',
//位置点
positions: [new Cesium.Cartesian3(-1160028.4895404815, 5443801.569087819, 3103982.2120705717)],
//样式
style: {
labelStyle: {
//字体
font: '30px sans-serif',
//文字内容
text: '这是Marker',
//文字颜色
fillColor: Cesium.Color.RED
},
billboardStyle: {
//billboard图片链接
image: 'http://webclient.smaryun.com:8200/NoneSpatialData/image/icon.png'
},
//文字相对于图片方位
labelPlaceType: 'topCenter',
//文字相对于图片间距
labelPadding: 20,
//离地高度
offsetHeight: 100,
//marker的屏幕像素偏移
pixelOffset: new Cesium.Cartesian2(0, 0)
},
});
//添加Marker
graphicsLayer.addGraphic(marker);
//修改样式
marker.style.labelPlaceType = "leftCenter";
marker.style.labelStyle.fillColor = Cesium.Color.BLUE;
marker.style.billboardStyle.width = 100;
// ES5引入方式
const { GraphicsLayer, Graphic } = zondy.cesium
// ES6引入方式
import { GraphicsLayer, Graphic } from "@mapgis/webclient-cesium-plugin"
//初始化一个标绘图层
const graphicsLayer = new GraphicsLayer(viewer, {});
viewer.scene.layers.appendGraphicsLayer(graphicsLayer);
// 添加一个多边形图元
const polygonGraphic = new Graphic({
type: 'polygon',
positions: [
Cesium.Cartesian3.fromDegrees(113.9514, 30.0129, 0),
Cesium.Cartesian3.fromDegrees(113.964, 30.0219, 0),
Cesium.Cartesian3.fromDegrees(113.9753, 30.015, 0),
Cesium.Cartesian3.fromDegrees(113.9624, 30.0075, 0),
Cesium.Cartesian3.fromDegrees(113.9514, 30.0129, 0)
],
style: {
color: Cesium.Color.AQUA
}
});
//将标绘点添加入标绘图层
graphicsLayer.addGraphic(polygonGraphic);
//平移多边形,修改transformX、transformY、transformZ,三个值组成一个平移向量,朝这个方向平移,笛卡尔坐标
polygonGraphic.transformX += 100;
polygonGraphic.transformY += 2000;
polygonGraphic.transformZ += 300;
//通过经纬度计算笛卡尔平移向量
const position1 = new Cesium.Cartographic(114.103, 30.25, 100);
const position2 = new Cesium.Cartographic(114.211, 30.46, 100);
position1 = Cesium.Cartesian3.fromDegrees(position1.longitude, position1.latitude, position1.height);
position2 = Cesium.Cartesian3.fromDegrees(position2.longitude, position2.latitude, position2.height);
const translate = Cesium.Cartesian3.subtract(position2, position1);
polygonGraphic.transformX += translate.x;
polygonGraphic.transformY += translate.y;
polygonGraphic.transformZ += translate.z;
//旋转多边形,修改heading、pitch、roll来实现三个轴向旋转,弧度值
polygonGraphic.heading += 0.1;
polygonGraphic.pitch += 0.1;
polygonGraphic.roll += 0.1;
// ES5引入方式
const { GraphicsLayer, Graphic } = zondy.cesium
// ES6引入方式
import { GraphicsLayer, Graphic } from "@mapgis/webclient-cesium-plugin"
//新增一个类型为div的标绘对象
//创建一个html字符串或者一个html标签对象
const html = "";
//创建一个标绘对象
const graphic = new Graphic({
//标绘类型
type: 'div',
//标绘位置
positions: [Cesium.Cartesian3.fromDegrees(114.285992, 30.585234, 0)],
//标绘样式
style: {
//html字符串或标签对象
html: html,
//html相对原始位置的屏幕像素偏移
pixelOffset: new Cesium.Cartesian2(0, 0),
//额外抬升高度
offsetHeight: 0
},
//开启时,当对象在模型内部时,会隐藏,开启此功能会有性能损耗
enableVFC: false,
//当div对象和主相机的距离超过20000000米时,隐藏div对象
disappearByDistance: 20000000
});
//将标绘添加入标绘图层
graphicsLayer.addGraphic(graphic);
//创建完成后,实时修改
graphic.style.html = "新的html";
graphic.style.pixelOffset = new Cesium.Cartesian2(0, 156);
graphic.style.offsetHeight = 2000;
Members
-
Graphic.graphicType
-
图元类型
Properties:
Name
Type
Default
Description
point
String
'point'
可选
点,类型(type)为point时样式参数参照Style.PointStyle
marker
String
'marker'
可选
marker,类型(type)为marker时样式参数参照Style.MarkerStyle
label
String
'label'
可选
文本,类型(type)为label时样式参数参照Style.Cesium.LabelStyle
billboard
String
'billboard'
可选
广告牌,类型(type)为billboard时样式参数参照Style.BillboardStyle
polyline
String
'polyline'
可选
线,类型(type)为polyline时样式参数参照Style.PolylineStyle
polylineVolume
String
'polylineVolume'
可选
圆管线,类型(type)为polylineVolume时样式参数参照Style.PolylineVolumeStyle
polygon
String
'polygon'
可选
面(区),类型(type)为polygon时样式参数参照Style.PolygonStyle
rectangle
String
'rectangle'
可选
矩形,类型(type)为rectangle时样式参数参照Style.RectangleStyle
square
String
'square'
可选
正方形,类型(type)squareStyle.SquareStyle
circle
String
'circle'
可选
圆,类型(type)为circle时样式参数参照Style.CircleStyle
corridor
String
'corridor'
可选
方管线,类型(type)为corridor时样式参数参照Style.CorridorStyle
cylinder
String
'cylinder'
可选
圆台(圆锥),类型(type)为cylinder时样式参数参照Style.CylinderStyle
ellipsoid
String
'ellipsoid'
可选
椭球,类型(type)为ellipsoid时样式参数参照Style.EllipsoidStyle
sphere
String
'sphere'
可选
圆球,类型(type)为sphere时样式参数参照Style.SphereStyle
wall
String
'wall'
可选
墙,类型(type)为wall时样式参数参照Style.WallStyle
box
String
'box'
可选
盒子,类型(type)为box时样式参数参照Style.BoxStyle
model
String
'model'
可选
gltf模型,类型(type)为model时样式参数参照Style.ModelStyle
dynamicRiver
String
'dynamicRiver'
可选
河流,类型(type)为dynamicRiver时样式参数参照Style.RiverStyle
-
allowPickingBoolean
-
图形对象是否可以选中
-
asynchronousBoolean
-
图形对象是否阻塞更新,一般设置为false避免更新时闪烁
-
attributesObject
-
图形对象属性键值对
-
boundingSphereCesium.BoundingSphere
-
图元对象包围盒
-
coordinateArray.<Cesium.Cartesian3>
-
图形实体位置数组(经纬度+高程,度)
-
editingBoolean
-
图形对象是否在编辑状态
-
enableVFCBoolean
-
是否开启视锥体检测,仅当类型为div时生效
-
headingNumber
-
图形对象偏航角,弧度。
-
idString
-
图形ID
-
isPointBoolean
-
图形是否为点,文本或者广告牌
-
modelMatrixCesium.Matrix4
-
图元对象旋转平移矩阵
-
nameNumber
-
图形对象名称
-
parentLayerGraphicsLayer
-
图元父图层
-
pitchNumber
-
图形对象俯仰角,弧度。
-
positionsArray.<Cesium.Cartesian3>
-
图形实体位置数组
-
primitiveCesium.Primitive
-
图形对象primitive
-
rollNumber
-
图形对象翻滚角,弧度。
-
showBoolean
-
图形是否显示
-
styleStyle
-
图元对象样式信息
Example
var graphic = new Graphic({type:label,style:{text:'mapgis'}});
graphic.style.text = 'mapgispro';
-
transformXNumber
-
图形对象局部坐标系X方向平移量,单位米,X方向为纬线方向
-
transformYNumber
-
图形对象局部坐标系y方向平移量,单位米,y方向为经线方向
-
transformZNumber
-
图形对象局部坐标系z方向平移量,单位米,z方向为垂直地表方向
-
typeString
-
图元类型 参照Graphic.graphicType
-
updatedfunction
-
图形更新后的回调,请在这个回调里面获取图形参数,不要在vue上绑定图形对象
Methods
-
addAttributes(key, value)
engineExtensions/graphic/Graphic.js, line 3169
-
Name
Type
Description
key
String
关键字
value
String
|
Object
值