# KmlDataSource

#### new Cesium.KmlDataSource(options)
DataSources/KmlDataSource.js 2634

A `DataSource` which processes Keyhole Markup Language 2.2 (KML).

KML support in Cesium is incomplete, but a large amount of the standard, as well as Google's `gx` extension namespace, is supported. See Github issue #873 for a detailed list of what is and isn't support. Cesium will also write information to the console when it encounters most unsupported features.

Non visual feature data, such as `atom:author` and `ExtendedData` is exposed via an instance of `KmlFeatureData`, which is added to each `Entity` under the `kml` property.

Name | Type | Description
--- | --- | ---
`options` | Object | An object with the following properties:
Name | Type | Default | Description
--- | --- | --- | ---
`camera` | Camera |  | The camera that is used for viewRefreshModes and sending camera properties to network links.
`canvas` | HTMLCanvasElement |  | The canvas that is used for sending viewer properties to network links.
`ellipsoid` | Ellipsoid | `Ellipsoid.WGS84` | optional The global ellipsoid used for geographical calculations.
`credit` | Credit | String |  | optional A credit for the data source, which is displayed on the canvas.
`classificationType` | ClassificationType |  | optional An enum Property specifying whether this polyline will classify terrain, 3D Tiles, or both when on the ground.

##### Example:

    var viewer = new Cesium.Viewer('cesiumContainer');
    viewer.dataSources.add(Cesium.KmlDataSource.load('../../SampleData/facilities.kmz',
         {
              camera: viewer.scene.camera,
              canvas: viewer.scene.canvas
         })
    );

##### Demo:

- Cesium Sandcastle KML Demo

##### See:

- Open Geospatial Consortium KML Standard
- Google KML Documentation

### Members

#### changedEvent : Event
DataSources/KmlDataSource.js 2762

Gets an event that will be raised when the underlying data changes.

#### clock : DataSourceClock
DataSources/KmlDataSource.js 2732

Gets the clock settings defined by the loaded KML. This represents the total availability interval for all time-dynamic data. If the KML does not contain time-dynamic data, this value is undefined.

#### clustering : EntityCluster
DataSources/KmlDataSource.js 2827

Gets or sets the clustering options for this data source. This object can be shared between multiple data sources.

#### credit : Credit
DataSources/KmlDataSource.js 2845

Gets the credit that will be displayed for the data source

#### entities : EntityCollection
DataSources/KmlDataSource.js 2742

Gets the collection of `Entity` instances.

#### errorEvent : Event
DataSources/KmlDataSource.js 2772

Gets an event that will be raised if an error is encountered during processing.

#### isLoading : Boolean
DataSources/KmlDataSource.js 2752

Gets a value indicating if the data source is currently loading data.

#### kmlTours : Array.<KmlTour>
DataSources/KmlDataSource.js 2855

Gets the KML Tours that are used to guide the camera to specified destinations on given time intervals.

#### loadingEvent : Event
DataSources/KmlDataSource.js 2782

Gets an event that will be raised when the data source either starts or stops loading.

#### name : String
DataSources/KmlDataSource.js 2714

Gets or sets a human-readable name for this instance. This will be automatically be set to the KML document name on load.

#### refreshEvent : Event
DataSources/KmlDataSource.js 2792

Gets an event that will be raised when the data source refreshes a network link.

#### show : Boolean
DataSources/KmlDataSource.js 2812

Gets whether or not this data source should be displayed.

#### swipeEnabled : Boolean
DataSources/KmlDataSource.js 2867

开启卷帘对比分析

Default Value: `false`

#### swipeInverse : Number
DataSources/KmlDataSource.js 2890

单独控制该图层是否进行反转，小于0不反转，大于0时反转，等于0失效。该属性的控制优先级高于`Scene#swipeController`中的inverse属性.若要取消该属性对本图层的独立控制需要将该属性置为0.

Default Value: `0`

#### unsupportedNodeEvent : Event
DataSources/KmlDataSource.js 2802

Gets an event that will be raised when the data source finds an unsupported node type.

### Methods

#### static Cesium.KmlDataSource.load(data, options) → Promise.<KmlDataSource>
DataSources/KmlDataSource.js 2701

Creates a Promise to a new instance loaded with the provided KML data.

Name | Type | Description
--- | --- | ---
`data` | Resource | String | Document | Blob | A url, parsed KML document, or Blob containing binary KMZ data or a parsed KML document.
`options` | KmlDataSource.LoadOptions | optional An object specifying configuration options

##### Returns:

A promise that will resolve to a new KmlDataSource instance once the KML is loaded.

#### load(data, options) → Promise.<KmlDataSource>
DataSources/KmlDataSource.js 2920

Asynchronously loads the provided KML data, replacing any existing data.

Name | Type | Description
--- | --- | ---
`data` | Resource | String | Document | Blob | A url, parsed KML document, or Blob containing binary KMZ data or a parsed KML document.
`options` | Object | optional An object with the following properties:
Name | Type | Default | Description
--- | --- | --- | ---
`sourceUri` | Resource | String |  | optional Overrides the url to use for resolving relative links and other KML network features.
`clampToGround` | Boolean | `false` | optional true if we want the geometry features (Polygons, LineStrings and LinearRings) clamped to the ground. If true, lines will use corridors so use Entity.corridor instead of Entity.polyline.
`classificationType` | Boolean | `ClassificationType.BOTH` | optional An enum Property specifying whether this polyline will classify terrain, 3D Tiles, or both when on the ground.
`ellipsoid` | Ellipsoid | `Ellipsoid.WGS84` | optional The global ellipsoid used for geographical calculations.

##### Returns:

A promise that will resolve to this instances once the KML is loaded.

#### update(time) → Boolean
DataSources/KmlDataSource.js 3140

Updates any NetworkLink that require updating.

Name | Type | Description
--- | --- | ---
`time` | JulianDate | The simulation time.

##### Returns:

True if this data source is ready to be displayed at the provided time, false otherwise.

### Type Definitions

#### Cesium.KmlDataSource.LoadOptions
DataSources/KmlDataSource.js 2582

Initialization options for the `load` method.

##### Properties:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`camera` | Camera |  |  | The camera that is used for viewRefreshModes and sending camera properties to network links.
`canvas` | HTMLCanvasElement |  |  | The canvas that is used for sending viewer properties to network links.
`sourceUri` | String | <optional> |  | Overrides the url to use for resolving relative links and other KML network features.
`clampToGround` | Boolean | <optional> | false | true if we want the geometry features (Polygons, LineStrings and LinearRings) clamped to the ground.
`ellipsoid` | Ellipsoid | <optional> | Ellipsoid.WGS84 | The global ellipsoid used for geographical calculations.
`credit` | Credit | String | <optional> |  | A credit for the data source, which is displayed on the canvas.