Read/Write KML. Create a new instance with the ALKMaps.Format.KML constructor.
ALKMaps. | Read/Write KML. |
Properties | |
namespaces | {Object} Mapping of namespace aliases to namespace URIs. |
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. |
kvpAttributes | {Boolean} Only used if extractAttributes is true. |
extractStyles | {Boolean} Extract styles from KML. |
extractTracks | {Boolean} Extract gx:Track elements from Placemark elements. |
trackAttributes | {Array} If extractTracks is true, points within gx:Track elements will be parsed as features with when, heading, tilt, and roll attributes. |
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 | |
ALKMaps. | Create a new parser for KML. |
Functions and Properties | |
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 |
parseKmlColor | Parses a kml color (in ‘aabbggrr’ format) and returns the corresponding color and opacity or null if the color is invalid. |
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. |
readers | Contains public functions, grouped by namespace prefix, that will be applied when a namespaced node is found matching the function name. |
parseFeature | This function is the core of the KML parsing code in ALKMaps. |
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 |
parseGeometry | Properties of this object are the functions that parse geometries based on their type. |
parseGeometry. | Given a KML node representing a point geometry, create an ALKMaps point geometry. |
parseGeometry. | Given a KML node representing a linestring geometry, create an ALKMaps linestring geometry. |
parseGeometry. | Given a KML node representing a polygon geometry, create an ALKMaps polygon geometry. |
parseGeometry. | Given a KML node representing a multigeometry, create an ALKMaps geometry collection. |
parseAttributes | |
parseExtendedData | Parse ExtendedData from KML. |
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. |
buildGeometry | Object containing methods to do the actual geometry node building based on geometry type. |
buildGeometry. | Given an ALKMaps point geometry, create a KML point. |
buildGeometry. | Given an ALKMaps multipoint geometry, create a KML GeometryCollection. |
buildGeometry. | Given an ALKMaps linestring geometry, create a KML linestring. |
buildGeometry. | Given an ALKMaps multilinestring geometry, create a KML GeometryCollection. |
buildGeometry. | Given an ALKMaps linearring geometry, create a KML linearring. |
buildGeometry. | Given an ALKMaps polygon geometry, create a KML polygon. |
buildGeometry. | Given an ALKMaps multipolygon geometry, create a KML GeometryCollection. |
buildGeometry. | Given an ALKMaps geometry collection, create a KML MultiGeometry. |
buildCoordinatesNode | Builds and returns the KML coordinates node with the given geometry <coordinates>...</coordinates> |
buildCoordinates | |
buildExtendedData |
{Boolean} Only used if extractAttributes is true. If set to true, attributes will be simple key-value pairs, compatible with other formats, Any displayName elements will be ignored. If set to false, attributes will be objects, retaining any displayName elements, but not compatible with other formats. Any CDATA in displayName will be read in as a string value. Default is false.
{Boolean} Extract gx:Track elements from Placemark elements. Default is false. If true, features will be generated for all points in all gx:Track elements. Features will have a when (Date) attribute based on when elements in the track. If tracks include angle elements, features will have heading, tilt, and roll attributes. If track point coordinates have three values, features will have an altitude attribute with the third coordinate value.
{Array} If extractTracks is true, points within gx:Track elements will be parsed as features with when, heading, tilt, and roll attributes. Any additional attribute names can be provided in trackAttributes.
read: function( data )
Read data from a string, and return a list of features.
data | {String} or {DOMElement} data to read/parse. |
{Array(ALKMaps.Feature.Vector)} List of features.
parseData: function( data, options )
Read data from a string, and return a list of features.
data | {String} or {DOMElement} data to read/parse. |
options | {Object} Hash of options |
{Array(ALKMaps.Feature.Vector)} List of features.
parseFeature: function( node )
This function is the core of the KML parsing code in ALKMaps. It creates the geometries that are then attached to the returned feature, and calls parseAttributes() to get attribute data out.
node | {DOMElement} |
{ALKMaps.Feature.Vector} A vector feature.
Given a KML node representing a point geometry, create an ALKMaps point geometry.
node | {DOMElement} A KML Point node. |
{ALKMaps.Geometry.Point} A point geometry.
Given a KML node representing a linestring geometry, create an ALKMaps linestring geometry.
node | {DOMElement} A KML LineString node. |
{ALKMaps.Geometry.LineString} A linestring geometry.
Given a KML node representing a polygon geometry, create an ALKMaps polygon geometry.
node | {DOMElement} A KML Polygon node. |
{ALKMaps.Geometry.Polygon} A polygon geometry.
Given a KML node representing a multigeometry, create an ALKMaps geometry collection.
node | {DOMElement} A KML MultiGeometry node. |
{ALKMaps.Geometry.Collection} A geometry collection.
parseExtendedData: function( node )
Parse ExtendedData from KML. Limited support for schemas/datatypes. See https://developers.google.com
parseProperty: function( xmlNode, namespace, tagName )
Convenience method to find a node and return its value
xmlNode | {<DOMElement>} |
namespace | {String} namespace of the node to find |
tagName | {String} name of the property to parse |
{String} The value for the requested property (defaults to null)
write: function( features )
Accept Feature Collection, and return a string.
features | {Array(ALKMaps.Feature.Vector)} An array of features. |
{String} A KML string.
createPlacemarkXML: function( feature )
Creates and returns a KML placemark node representing the given feature.
feature | {ALKMaps.Feature.Vector} |
{DOMElement}
buildGeometryNode: function( geometry )
Builds and returns a KML geometry node with the given geometry.
geometry | {ALKMaps.Geometry} |
{DOMElement}
Given an ALKMaps point geometry, create a KML point.
geometry | {ALKMaps.Geometry.Point} A point geometry. |
{DOMElement} A KML point node.
Given an ALKMaps multipoint geometry, create a KML GeometryCollection.
geometry | {ALKMaps.Geometry.Point} A multipoint geometry. |
{DOMElement} A KML GeometryCollection node.
Given an ALKMaps linestring geometry, create a KML linestring.
geometry | {ALKMaps.Geometry.LineString} A linestring geometry. |
{DOMElement} A KML linestring node.
Given an ALKMaps multilinestring geometry, create a KML GeometryCollection.
geometry | {ALKMaps.Geometry.Point} A multilinestring geometry. |
{DOMElement} A KML GeometryCollection node.
Given an ALKMaps linearring geometry, create a KML linearring.
geometry | {ALKMaps.Geometry.LinearRing} A linearring geometry. |
{DOMElement} A KML linearring node.
Given an ALKMaps polygon geometry, create a KML polygon.
geometry | {ALKMaps.Geometry.Polygon} A polygon geometry. |
{DOMElement} A KML polygon node.
Given an ALKMaps multipolygon geometry, create a KML GeometryCollection.
geometry | {ALKMaps.Geometry.Point} A multipolygon geometry. |
{DOMElement} A KML GeometryCollection node.
Given an ALKMaps geometry collection, create a KML MultiGeometry.
geometry | {ALKMaps.Geometry.Collection} A geometry collection. |
{DOMElement} A KML MultiGeometry node.
buildCoordinatesNode: function( geometry )
Builds and returns the KML coordinates node with the given geometry <coordinates>...</coordinates>
geometry | {ALKMaps.Geometry} |
{DOMElement}
buildCoordinates: function( point )
point | {ALKMaps.Geometry.Point} |
Returns {String} a coordinate pair
Read data from a string, and return a list of features.
read: function( data )
Read data from a string, and return a list of features.
parseData: function( data, options )
Finds URLs of linked KML documents and fetches them
parseLinks: function( nodes, options )
Fetches a URL and returns the result
fetchLink: function( href )
Looks for Style nodes in the data and parses them Also parses StyleMap nodes, but only uses the ‘normal’ key
parseStyles: function( nodes, options )
Parses a kml color (in ‘aabbggrr’ format) and returns the corresponding color and opacity or null if the color is invalid.
parseKmlColor: function( kmlColor )
Parses the children of a Style node and builds the style hash accordingly
parseStyle: function( node )
Looks for Style nodes in the data and parses them Also parses StyleMap nodes, but only uses the ‘normal’ key
parseStyleMaps: function( nodes, options )
Loop through all Placemark nodes and parse them.
parseFeatures: function( nodes, options )
This function is the core of the KML parsing code in ALKMaps.
parseFeature: function( node )
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
getStyle: function( styleUrl, options )
parseAttributes: function( node )
Parse ExtendedData from KML.
parseExtendedData: function( node )
Convenience method to find a node and return its value
parseProperty: function( xmlNode, namespace, tagName )
Accept Feature Collection, and return a string.
write: function( features )
Creates and returns a KML folder node
createFolderXML: function()
Creates and returns a KML placemark node representing the given feature.
createPlacemarkXML: function( feature )
Builds and returns a KML geometry node with the given geometry.
buildGeometryNode: function( geometry )
Builds and returns the KML coordinates node with the given geometry coordinates...</coordinates>
buildCoordinatesNode: function( geometry )
buildCoordinates: function( point )
buildExtendedData: function( attributes )