# GraphicsLayer

#### new Cesium.GraphicsLayer(viewer, options)
MapGIS/GraphicsLayer.js 40

标绘管理图层

Name | Type | Description
--- | --- | ---
`viewer` | Viewer |
`options` | Object |
Name | Type | Default | Description
--- | --- | --- | ---
`getGraphic` | function | `function` | optional 添加标绘对象成功后的回调函数。
`revokeModel` | function | `function` | optional 撤销添加模型的回调函数。
`revokePoint` | function | `function` | optional 撤销添加点，广告牌，文字框的回调函数。

##### Example:

    var graphicsLayer = new Cesium.GraphicsLayer(viewer);
    viewer.scene.layers.appendGraphicsLayer(graphicsLayer);

### Members

#### readonly editTool : EditTool
MapGIS/GraphicsLayer.js 77

图层编辑工具

#### readonly graphicList : HashMap
MapGIS/GraphicsLayer.js 66

图形集合，包含该图层内所有图形对象的键值对

### Methods

#### addGraphic(graphic) → Graphic
MapGIS/GraphicsLayer.js 178

添加绘制图形

Name | Type | Description
--- | --- | ---
`graphic` | Object | 不同类型实体参考：参见`Graphic.graphicType`

##### Returns:

放回回添加的图形

##### Example:

    var graphicsLayer = new Cesium.GraphicsLayer(viewer);
    var graphic = new Cesium.Graphic(type: 'label',style: {color: viewModel.color,text: 'hezihan',font: '50px Helvetica',pixelSize: 20,
                                      pixelOffsetScaleByDistance: false,
                                      horizontalOrigin: Cesium.HorizontalOrigin.right,
                                      fillColor: '#818518',
                                      isScaleByDistance: true, //是否远近缩放
                                      distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 50000)},
                                      name: 'box1',attributes: { key: 'www', map: 4645 },getGraphic: getGraphic);
    graphicsLayer.addGraphic(graphic);

#### addModel(options)
MapGIS/GraphicsLayer.js 215

添加模型

Name | Type | Description
--- | --- | ---
`options` | Object |

#### calculateBoundingSphere() → BoundingSphere
MapGIS/GraphicsLayer.js 772

计算当前标绘图层的外包围球

##### Returns:

外包围球。

#### destroy()
MapGIS/GraphicsLayer.js 848

移除整个图层

#### exportToJson() → String
MapGIS/GraphicsLayer.js 754

整个图层导出为json文件

##### Returns:

json格式的字符串。

#### flyTo(options)
MapGIS/GraphicsLayer.js 791

跳转到该图层

Name | Type | Description
--- | --- | ---
`options` | Object | 跳转参数，参见`Camera#flyToBoundingSphere`

#### getAllGraphic() → Array.<Object>
MapGIS/GraphicsLayer.js 650

获取图层所有标绘图形

##### Returns:

返回所有图形对象

#### getGraphicByGroupName(name) → Array.<Object>|Undefined
MapGIS/GraphicsLayer.js 607

根据GroupName获取标绘图形对象

Name | Type | Description
--- | --- | ---
`name` | String | 图形ID

##### Returns:

返回对象组

#### getGraphicByID(ID) → Object|Undefined
MapGIS/GraphicsLayer.js 558

根据ID获取标绘图形对象

Name | Type | Description
--- | --- | ---
`ID` | String | 图形ID

##### Returns:

返回图层对象或者返回false查询失败

#### getGraphicByIndex(index) → Object
MapGIS/GraphicsLayer.js 625

根据序号获取标绘图形对象

Name | Type | Description
--- | --- | ---
`index` | String | 图形序号

##### Returns:

返回图形对象

#### getGraphicByName(name, type) → Array.<Object>|Undefined
MapGIS/GraphicsLayer.js 575

根据name获取标绘图形对象

Name | Type | Description
--- | --- | ---
`name` | String | 图形ID
`type` | String | 类型，equal、like

##### Returns:

返回对象组

#### getIndexByGraphic() → Boolean
MapGIS/GraphicsLayer.js 634

根据对象获取index

##### Returns:

#### loadJson(json)
MapGIS/GraphicsLayer.js 800

加载json文件

Name | Type | Description
--- | --- | ---
`json` | String | json格式的字符串。

#### removeAllGraphic() → Boolean
MapGIS/GraphicsLayer.js 730

移除图层所有标绘图形

##### Returns:

移除是否成功

#### removeGraphicByGroupName(name)
MapGIS/GraphicsLayer.js 674

根据GroupName移除一组标绘图形

Name | Type | Description
--- | --- | ---
`name` | String | 组名

#### removeGraphicByID(ID, noRemove)
MapGIS/GraphicsLayer.js 660

根据ID移除标绘图形

Name | Type | Description
--- | --- | ---
`ID` | String | 图形ID
`noRemove` | Boolean | 不使用自带的remove

#### removeGraphicByIndex(index)
MapGIS/GraphicsLayer.js 698

根据序号移除标绘图形

Name | Type | Description
--- | --- | ---
`index` | String | 图形序号

#### removeLastGraphic()
MapGIS/GraphicsLayer.js 713

移除最后一个标绘图形

#### removePickingGraphic()
MapGIS/GraphicsLayer.js 721

移除选中标绘图形

#### startDrawing(options)
MapGIS/GraphicsLayer.js 115

开始绘制图形 (注意：内部会开始地形深度检测功能)

Name | Type | Description
--- | --- | ---
`options` | Object |
Name | Type | Default | Description
--- | --- | --- | ---
`type` | String | `'none'` | optional 绘制类型：参照`Graphic.graphicType`
`isContinued` | Boolean | `true` | optional 是否连续绘制
`drawWithHeight` | Boolean | `false` | optional 是否绘制高度，当为true时使用鼠标绘制高度，当为false时使用参数设置的统一高度
`style` | Object |  | optional 图元样式信息 详情参见`Style`
`editPointStyle` | Object |  | optional 编辑点样式信息 详情参见`Style.EditPointStyle`
`attributes` | Object |  | optional 图元属性
`name` | String |  | optional 图元名称
`show` | Boolean | `true` | optional 图元是否显示
`asynchronous` | Boolean | `false` | optional 默认为阻塞式更新，true为异步更新，false为阻塞式更新。
`heading` | Number | `0.0` | optional 偏航角，弧度。
`pitch` | Number | `0.0` | optional 俯仰角，弧度。
`roll` | Number | `0.0` | optional 翻滚角，弧度。
`transformX` | Number | `0.0` | optional 局部坐标系X方向平移量，单位米，X方向为纬线方向
`transformY` | Number | `0.0` | optional 局部坐标系Y方向平移量，单位米，Y方向为经线方向
`transformZ` | Number | `0.0` | optional 局部坐标系Z方向平移量，单位米，Z方向为垂直地表方向

##### Example:

    var graphicsLayer = new Cesium.GraphicsLayer(viewer,{getGraphic:getGraphic});
    graphicsLayer.graphicsLayer.startDrawing({type: Cesium.Graphic.graphicType.box,style: { color: Cesium.color.BLUE,  extrudedHeight: 100 },name: 'box1',attributes: { key: 'www', map: 4645 }});
    function getGraphic(e) {console.log(e);}

#### startEdit()
MapGIS/GraphicsLayer.js 539

开始编辑

#### stopDrawing()
MapGIS/GraphicsLayer.js 514

移除所有鼠标事件，停止绘制

#### stopEdit()
MapGIS/GraphicsLayer.js 546

停止编辑