OpenLayers.Format.KML - OpenLayers

# OpenLayers. Format.KML

Read/Wite KML. Create a new instance with the OpenLayers.Format.KML constructor.

#### Inherits from

- OpenLayers.Format.XML

Summary

OpenLayers. Format.KML | Read/Wite KML.
Properties |
kmlns | {String} KML Namespace to use.
placemarksDesc | {String} Name of the placemarks.
foldersName | {String} Name of the folders.
foldersDesc | {String} Description of the folders.
extractAttributes | {Boolean} Extract attributes from KML.
extractStyles | {Boolean} Extract styles from KML.
internalns | {String} KML Namespace to use -- defaults to the namespace of the Placemark node being parsed, but falls back to kmlns.
features | {Array} Array of features
styles | {Object} Storage of style objects
styleBaseUrl | {String}
fetched | {Object} Storage of KML URLs that have been fetched before in order to prevent reloading them.
maxDepth | {Integer} Maximum depth for recursive loading external KML URLs Defaults to 0: do no external fetching
Constructor |
OpenLayers. Format.KML | Create a new parser for KML.
Functions |
read | Read data from a string, and return a list of features.
parseData | Read data from a string, and return a list of features.
parseLinks | Finds URLs of linked KML documents and fetches them
fetchLink | Fetches a URL and returns the result
parseStyles | Looks for Style nodes in the data and parses them Also parses StyleMap nodes, but only uses the ‘normal’ key
parseStyle | Parses the children of a Style node and builds the style hash accordingly
parseStyleMaps | Looks for Style nodes in the data and parses them Also parses StyleMap nodes, but only uses the ‘normal’ key
parseFeatures | Loop through all Placemark nodes and parse them.
parseFeature | This function is the core of the KML parsing code in OpenLayers.
getStyle | Retrieves a style from a style hash using styleUrl as the key If the styleUrl doesn’t exist yet, we try to fetch it Internet
Properties |
parseGeometry | Properties of this object are the functions that parse geometries based on their type.
Functions |
parseGeometry. point | Given a KML node representing a point geometry, create an OpenLayers point geometry.
parseGeometry. linestring | Given a KML node representing a linestring geometry, create an OpenLayers linestring geometry.
parseGeometry. polygon | Given a KML node representing a polygon geometry, create an OpenLayers polygon geometry.
parseGeometry. multigeometry | Given a KML node representing a multigeometry, create an OpenLayers geometry collection.
parseAttributes |
parseProperty | Convenience method to find a node and return its value
write | Accept Feature Collection, and return a string.
createFolderXML | Creates and returns a KML folder node
createPlacemarkXML | Creates and returns a KML placemark node representing the given feature.
buildGeometryNode | Builds and returns a KML geometry node with the given geometry.
Properties |
buildGeometry | Object containing methods to do the actual geometry node building based on geometry type.
Functions |
buildGeometry. point | Given an OpenLayers point geometry, create a KML point.
buildGeometry. multipoint | Given an OpenLayers multipoint geometry, create a KML GeometryCollection.
buildGeometry. linestring | Given an OpenLayers linestring geometry, create a KML linestring.
buildGeometry. multilinestring | Given an OpenLayers multilinestring geometry, create a KML GeometryCollection.
buildGeometry. linearring | Given an OpenLayers linearring geometry, create a KML linearring.
buildGeometry. polygon | Given an OpenLayers polygon geometry, create a KML polygon.
buildGeometry. multipolygon | Given an OpenLayers multipolygon geometry, create a KML GeometryCollection.
buildGeometry. collection | Given an OpenLayers geometry collection, create a KML MultiGeometry.
buildCoordinatesNode | Builds and returns the KML coordinates node with the given geometry <coordinates>...</coordinates>

### Properties

### kmlns

{String} KML Namespace to use. Defaults to 2.0 namespace.

### placemarksDesc

{String} Name of the placemarks. Default is “No description available.”

### foldersName

{String} Name of the folders. Default is “OpenLayers export.”

### foldersDesc

{String} Description of the folders. Default is “Exported on [date].”

### extractAttributes

{Boolean} Extract attributes from KML. Default is true. Extracting styleUrls requires this to be set to true

### extractStyles

{Boolean} Extract styles from KML. Default is false. Extracting styleUrls also requires extractAttributes to be set to true

### internalns

{String} KML Namespace to use -- defaults to the namespace of the Placemark node being parsed, but falls back to kmlns.

### features

{Array} Array of features

### styles

{Object} Storage of style objects

### styleBaseUrl

{String}

### fetched

{Object} Storage of KML URLs that have been fetched before in order to prevent reloading them.

### maxDepth

{Integer} Maximum depth for recursive loading external KML URLs Defaults to 0: do no external fetching

### Constructor

### OpenLayers. Format.KML

Create a new parser for KML.

#### Parameters

options | {Object} An optional object whose properties will be set on this instance.

### Functions

### read

> read: function( | data | )

Read data from a string, and return a list of features.

#### Parameters

data | {String} or {DOMElement} data to read/parse.

#### Returns

{Array(OpenLayers.Feature.Vector)} List of features.

### parseData

> parseData: function( | data,
> | options | )

Read data from a string, and return a list of features.

#### Parameters

data | {String} or {DOMElement} data to read/parse.
options | {Object} Hash of options

#### Returns

{Array(OpenLayers.Feature.Vector)} List of features.

### parseLinks

> parseLinks: function( | nodes,
> | options | )

Finds URLs of linked KML documents and fetches them

#### Parameters

nodes | {Array} of {DOMElement} data to read/parse.
options | {Object} Hash of options

### fetchLink

> fetchLink: function( | href | )

Fetches a URL and returns the result

#### Parameters

href | {String} url to be fetched

### parseStyles

> parseStyles: function( | nodes,
> | options | )

Looks for Style nodes in the data and parses them Also parses StyleMap nodes, but only uses the ‘normal’ key

#### Parameters

nodes | {Array} of {DOMElement} data to read/parse.
options | {Object} Hash of options

### parseStyle

> parseStyle: function( | node | )

Parses the children of a Style node and builds the style hash accordingly

#### Parameters

node | {DOMElement} Style node

### parseStyleMaps

> parseStyleMaps: function( | nodes,
> | options | )

Looks for Style nodes in the data and parses them Also parses StyleMap nodes, but only uses the ‘normal’ key

#### Parameters

nodes | {Array} of {DOMElement} data to read/parse.
options | {Object} Hash of options

### parseFeatures

> parseFeatures: function( | nodes,
> | options | )

Loop through all Placemark nodes and parse them. Will create a list of features

#### Parameters

nodes | {Array} of {DOMElement} data to read/parse.
options | {Object} Hash of options

### parseFeature

> parseFeature: function( | node | )

This function is the core of the KML parsing code in OpenLayers. It creates the geometries that are then attached to the returned feature, and calls parseAttributes() to get attribute data out.

#### Parameters

node | {DOMElement}

#### Returns

{OpenLayers.Feature.Vector} A vector feature.

### getStyle

> getStyle: function( | styleUrl,
> | options | )

Retrieves a style from a style hash using styleUrl as the key If the styleUrl doesn’t exist yet, we try to fetch it Internet

#### Parameters

styleUrl | {String} URL of style
options | {Object} Hash of options

#### Returns

{Object} | (reference to) Style hash

### Properties

### parseGeometry

Properties of this object are the functions that parse geometries based on their type.

### Functions

### parseGeometry. point

Given a KML node representing a point geometry, create an OpenLayers point geometry.

#### Parameters

node | {DOMElement} A KML Point node.

#### Returns

{OpenLayers.Geometry.Point} A point geometry.

### parseGeometry. linestring

Given a KML node representing a linestring geometry, create an OpenLayers linestring geometry.

#### Parameters

node | {DOMElement} A KML LineString node.

#### Returns

{OpenLayers.Geometry.LineString} A linestring geometry.

### parseGeometry. polygon

Given a KML node representing a polygon geometry, create an OpenLayers polygon geometry.

#### Parameters

node | {DOMElement} A KML Polygon node.

#### Returns

{OpenLayers.Geometry.Polygon} A polygon geometry.

### parseGeometry. multigeometry

Given a KML node representing a multigeometry, create an OpenLayers geometry collection.

#### Parameters

node | {DOMElement} A KML MultiGeometry node.

#### Returns

{OpenLayers.Geometry.Collection} A geometry collection.

### parseAttributes

> parseAttributes: function( | node | )

#### Parameters

node | {DOMElement}

#### Returns

{Object} An attributes object.

### parseProperty

> parseProperty: function( | xmlNode,
> | namespace,
> | tagName | )

Convenience method to find a node and return its value

#### Parameters

xmlNode | {<DOMElement>}
namespace | {String} namespace of the node to find
tagName | {String} name of the property to parse

#### Returns

{String} The value for the requested property (defaults to null)

### write

> write: function( | features | )

Accept Feature Collection, and return a string.

#### Parameters

features | {Array(OpenLayers.Feature.Vector} An array of features.

#### Returns

{String} A KML string.

### createFolderXML

> createFolderXML: function()

Creates and returns a KML folder node

#### Returns

{DOMElement}

### createPlacemarkXML

> createPlacemarkXML: function( | feature | )

Creates and returns a KML placemark node representing the given feature.

#### Parameters

feature | {OpenLayers.Feature.Vector}

#### Returns

{DOMElement}

### buildGeometryNode

> buildGeometryNode: function( | geometry | )

Builds and returns a KML geometry node with the given geometry.

#### Parameters

geometry | {OpenLayers.Geometry}

#### Returns

{DOMElement}

### Properties

### buildGeometry

Object containing methods to do the actual geometry node building based on geometry type.

### Functions

### buildGeometry. point

Given an OpenLayers point geometry, create a KML point.

#### Parameters

geometry | {OpenLayers.Geometry.Point} A point geometry.

#### Returns

{DOMElement} A KML point node.

### buildGeometry. multipoint

Given an OpenLayers multipoint geometry, create a KML GeometryCollection.

#### Parameters

geometry | {OpenLayers.Geometry.Point} A multipoint geometry.

#### Returns

{DOMElement} A KML GeometryCollection node.

### buildGeometry. linestring

Given an OpenLayers linestring geometry, create a KML linestring.

#### Parameters

geometry | {OpenLayers.Geometry.LineString} A linestring geometry.

#### Returns

{DOMElement} A KML linestring node.

### buildGeometry. multilinestring

Given an OpenLayers multilinestring geometry, create a KML GeometryCollection.

#### Parameters

geometry | {OpenLayers.Geometry.Point} A multilinestring geometry.

#### Returns

{DOMElement} A KML GeometryCollection node.

### buildGeometry. linearring

Given an OpenLayers linearring geometry, create a KML linearring.

#### Parameters

geometry | {OpenLayers.Geometry.LinearRing} A linearring geometry.

#### Returns

{DOMElement} A KML linearring node.

### buildGeometry. polygon

Given an OpenLayers polygon geometry, create a KML polygon.

#### Parameters

geometry | {OpenLayers.Geometry.Polygon} A polygon geometry.

#### Returns

{DOMElement} A KML polygon node.

### buildGeometry. multipolygon

Given an OpenLayers multipolygon geometry, create a KML GeometryCollection.

#### Parameters

geometry | {OpenLayers.Geometry.Point} A multipolygon geometry.

#### Returns

{DOMElement} A KML GeometryCollection node.

### buildGeometry. collection

Given an OpenLayers geometry collection, create a KML MultiGeometry.

#### Parameters

geometry | {OpenLayers.Geometry.Collection} A geometry collection.

#### Returns

{DOMElement} A KML MultiGeometry node.

### buildCoordinatesNode

> buildCoordinatesNode: function( | geometry | )

Builds and returns the KML coordinates node with the given geometry <coordinates>...</coordinates>

#### Parameters

geometry | {OpenLayers.Geometry}

#### Return

{DOMElement}

> read: function( | data | )

Read data from a string, and return a list of features.

> parseData: function( | data,
> | options | )

Read data from a string, and return a list of features.

> parseLinks: function( | nodes,
> | options | )

Finds URLs of linked KML documents and fetches them

> fetchLink: function( | href | )

Fetches a URL and returns the result

> parseStyles: function( | nodes,
> | options | )

Looks for Style nodes in the data and parses them Also parses StyleMap nodes, but only uses the ‘normal’ key
This class represents a UserStyle obtained from a SLD, containing styling rules.

> parseStyle: function( | node | )

Parses the children of a Style node and builds the style hash accordingly

> parseStyleMaps: function( | nodes,
> | options | )

Looks for Style nodes in the data and parses them Also parses StyleMap nodes, but only uses the ‘normal’ key

> parseFeatures: function( | nodes,
> | options | )

Loop through all Placemark nodes and parse them.

> parseFeature: function( | node | )

This function is the core of the KML parsing code in OpenLayers.

> getStyle: function( | styleUrl,
> | options | )

Retrieves a style from a style hash using styleUrl as the key If the styleUrl doesn’t exist yet, we try to fetch it Internet

> parseAttributes: function( | node | )

> parseProperty: function( | xmlNode,
> | namespace,
> | tagName | )

Convenience method to find a node and return its value

> write: function( | features | )

Accept Feature Collection, and return a string.

> createFolderXML: function()

Creates and returns a KML folder node

> createPlacemarkXML: function( | feature | )

Creates and returns a KML placemark node representing the given feature.

> buildGeometryNode: function( | geometry | )

Builds and returns a KML geometry node with the given geometry.

> buildCoordinatesNode: function( | geometry | )

Builds and returns the KML coordinates node with the given geometry coordinates...</coordinates>
Create a new parser for KML.
Read and write XML.
Vector features use the OpenLayers.Geometry classes as geometry description.
Point geometry class.
A LineString is a Curve which, once two points have been added to it, can never be less than two points long.
Polygon is a collection of Geometry.LinearRings.
A Collection is exactly what it sounds like: A collection of different Geometries.
A Geometry is a description of a geographic object.
A Linear Ring is a special LineString which is closed.
Close