Class: GeoJSONParser

GeoJSONParser(dataSource)

Parses a GeoJSON and creates shapes representing its contents. Points and MultiPoints in the GeoJSON are represented by Placemarks, Lines and MultiLines are represented by SurfacePolylines, and Polygons and MultiPolygons are represented by SurfacePolygons.

An attribute callback may also be specified to examine each geometry and configure the shape created for it. This function enables the application to assign independent attributes to each shape. An argument to this function provides any attributes specified in a properties member of GeoJSON feature.

Constructor

new GeoJSONParser(dataSource)

Constructs a GeoJSON object for a specified GeoJSON data source. Call load to retrieve the GeoJSON and create shapes for it.
Parameters:
Name Type Description
dataSource String | Object The data source of the GeoJSON. Can be a URL to an external resource, or a JSON string, or a JavaScript object representing a parsed GeoJSON string.
Source:
Throws:
If the specified data source is null or undefined.
Type
ArgumentError

Members

(readonly) dataSource :String|Object

The GeoJSON data source as specified to this GeoJSON's constructor.
Type:
  • String | Object
Source:

(readonly) geoJSONObject :Object

The GeoJSON object resulting from the parsing of GeoJSON string.
Type:
  • Object
Source:

(readonly) geoJSONType :String

The type of the GeoJSON. The type can be one of the following:
  • GeoJSONConstants.TYPE_POINT
  • GeoJSONConstants.TYPE_MULTI_POINT
  • GeoJSONConstants.TYPE_LINE_STRING
  • GeoJSONConstants.TYPE_MULTI_LINE_STRING
  • GeoJSONConstants.TYPE_POLYGON
  • GeoJSONConstants.TYPE_MULTI_POLYGON
  • GeoJSONConstants.TYPE_GEOMETRY_COLLECTION
  • GeoJSONConstants.TYPE_FEATURE
  • GeoJSONConstants.TYPE_FEATURE_COLLECTION
This value is defined after GeoJSON parsing.
Type:
  • String
Source:

(readonly) layer :RenderableLayer

The layer containing the shapes representing the geometries in this GeoJSON, as specified to this GeoJSON's constructor or created by the constructor if no layer was specified.
Type:
Source:

(readonly) parserCompletionCallback :function

The completion callback specified to load. An optional function called when the GeoJSON loading is complete and all the shapes have been added to the layer.
Type:
  • function
Source:

(readonly) shapeConfigurationCallback :function

The attribute callback specified to load. See that method's description for details.
Type:
  • function
Default Value:
Source:

Methods

(static) tryParseJSONString(str) → {Object}

Tries to parse a JSON string into a JavaScript object.
Parameters:
Name Type Description
str String the string to try to parse.
Source:
Returns:
the object if the string is valid JSON; otherwise null.
Type
Object

addRenderablesForFeature(layer, feature)

Calls addRenderablesForGeometry or addRenderablesForGeometryCollection depending on the type of feature geometry. Applications typically do not call this method directly. It is called by addRenderablesForGeoJSON.
Parameters:
Name Type Description
layer RenderableLayer The layer in which to place the newly created shapes.
feature GeoJSONFeature The Feature object.
Source:
Throws:
  • If the specified layer is null or undefined.
    Type
    ArgumentError
  • If the specified feature is null or undefined.
    Type
    ArgumentError

addRenderablesForFeatureCollection(layer, featureCollection)

Iterates over the GeoJSON FeatureCollection features and creates GeoJSONFeatures for them. Applications typically do not call this method directly. It is called by addRenderablesForGeoJSON.
Parameters:
Name Type Description
layer RenderableLayer The layer in which to place the newly created shapes.
featureCollection GeoJSONFeatureCollection The FeatureCollection object.
Source:
Throws:
  • If the specified layer is null or undefined.
    Type
    ArgumentError
  • If the specified featureCollection is null or undefined.
    Type
    ArgumentError

addRenderablesForGeoJSON(layer)

Iterates over this GeoJSON's geometries and creates shapes for them. See the following methods for the details of the shapes created and their use of the shapeConfigurationCallback:
Parameters:
Name Type Description
layer RenderableLayer The layer in which to place the newly created shapes.
Source:
Throws:
If the specified layer is null or undefined.
Type
ArgumentError

addRenderablesForGeometry(layer, geometry, properties)

Parameters:
Name Type Description
layer RenderableLayer The layer in which to place the newly created shapes.
geometry GeoJSONGeometry An object containing the current geometry.
properties Object An object containing the attribute-value pairs found in GeoJSON feature properties member.
Source:
Throws:

addRenderablesForGeometryCollection(layer, geometryCollection, properties)

Iterates over the GeoJSON GeometryCollection geometries and creates GeoJSONGeometrys for them. Applications typically do not call this method directly. It is called by addRenderablesForGeoJSON.
Parameters:
Name Type Description
layer RenderableLayer The layer in which to place the newly created shapes.
geometryCollection GeoJSONGeometryCollection The GeometryCollection object.
properties Object The properties related to the GeometryCollection geometry.
Source:
Throws:
  • If the specified layer is null or undefined.
    Type
    ArgumentError
  • If the specified featureCollection is null or undefined.
    Type
    ArgumentError

addRenderablesForLineString(layer, geometry, properties)

Creates a SurfacePolyline for a LineString geometry. Applications typically do not call this method directly. It is called by addRenderablesForGeometry.

This method invokes this GeoJSON's shapeConfigurationCallback for the geometry.

Parameters:
Name Type Description
layer RenderableLayer The layer in which to place the newly created shapes.
geometry GeoJSONGeometryLineString The LineString geometry object.
properties Object The properties related to the LineString geometry.
Source:
Throws:
  • If the specified layer is null or undefined.
    Type
    ArgumentError
  • If the specified geometry is null or undefined.
    Type
    ArgumentError

addRenderablesForMultiLineString(layer, geometry, properties)

Creates SurfacePolylines for a MultiLineString geometry. Applications typically do not call this method directly. It is called by addRenderablesForGeometry.

This method invokes this GeoJSON's shapeConfigurationCallback for the geometry.

Parameters:
Name Type Description
layer RenderableLayer The layer in which to place the newly created shapes.
geometry GeoJSONGeometryMultiLineString The MultiLineString geometry object.
properties Object The properties related to the MultiLineString geometry.
Source:
Throws:
  • If the specified layer is null or undefined.
    Type
    ArgumentError
  • If the specified geometry is null or undefined.
    Type
    ArgumentError

addRenderablesForMultiPoint(layer, geometry, properties)

Creates Placemarks for a MultiPoint geometry. Applications typically do not call this method directly. It is called by addRenderablesForGeometry.

This method invokes this GeoJSON's shapeConfigurationCallback for the geometry.

Parameters:
Name Type Description
layer RenderableLayer The layer in which to place the newly created shapes.
geometry GeoJSONGeometryMultiPoint The MultiPoint geometry object.
properties Object The properties related to the MultiPoint geometry.
Source:
Throws:
  • If the specified layer is null or undefined.
    Type
    ArgumentError
  • If the specified geometry is null or undefined.
    Type
    ArgumentError

addRenderablesForMultiPolygon(layer, geometry, properties)

Creates SurfacePolygons for a MultiPolygon geometry. Applications typically do not call this method directly. It is called by addRenderablesForGeometry.

This method invokes this GeoJSON's shapeConfigurationCallback for the geometry.

Parameters:
Name Type Description
layer RenderableLayer The layer in which to place the newly created shapes.
geometry GeoJSONGeometryMultiPolygon The MultiPolygon geometry object.
properties Object The properties related to the MultiPolygon geometry.
Source:
Throws:
  • If the specified layer is null or undefined.
    Type
    ArgumentError
  • If the specified geometry is null or undefined.
    Type
    ArgumentError

addRenderablesForPoint(layer, geometry, properties)

Creates a Placemark for a Point geometry. Applications typically do not call this method directly. It is called by addRenderablesForGeometry.

This method invokes this GeoJSON's shapeConfigurationCallback for the geometry.

Parameters:
Name Type Description
layer RenderableLayer The layer in which to place the newly created shapes.
geometry GeoJSONGeometryPoint The Point geometry object.
properties Object The properties related to the Point geometry.
Source:
Throws:
  • If the specified layer is null or undefined.
    Type
    ArgumentError
  • If the specified geometry is null or undefined.
    Type
    ArgumentError

addRenderablesForPolygon(layer, geometry, properties)

Creates a SurfacePolygon for a Polygon geometry. Applications typically do not call this method directly. It is called by addRenderablesForGeometry.

This method invokes this GeoJSON's shapeConfigurationCallback for the geometry.

Parameters:
Name Type Description
layer RenderableLayer The layer in which to place the newly created shapes.
geometry GeoJSONGeometryPolygon The Polygon geometry object.
properties Object The properties related to the Polygon geometry.
Source:
Throws:
  • If the specified layer is null or undefined.
    Type
    ArgumentError
  • If the specified geometry is null or undefined.
    Type
    ArgumentError

defaultShapeConfigurationCallback(geometry, properties) → {Object}

The default shapeConfigurationCallback for this GeoJSON. It is called if none was specified to the load method. This method assigns shared, default attributes to the shapes created for each geometry. Any changes to these attributes will have an effect in all shapes created by this GeoJSON.

For all geometry, the GeoJSON's properties are checked for an attribute named "name", "Name" or "NAME". If found, the returned shape configuration contains a name property holding the value associated with the attribute. This value is specified as the label displayName property for all shapes created. For Placemark shapes it is also specified as the placemark label. It is specified as the displayName for all other shapes.

Parameters:
Name Type Description
geometry GeoJSONGeometry An object containing the geometry associated with this GeoJSON.
properties Object An object containing the attribute-value pairs found in GeoJSON feature properties member.
Source:
Returns:
An object with properties as described above.
Type
Object

getReprojectedIfRequired(latitude, longitude, crsObject) → {Array.<Number>}

Reprojects GeoJSON geometry coordinates if required using proj4js.
Parameters:
Name Type Description
latitude Number The latitude coordinate of the geometry.
longitude Number The longitude coordinate of the geometry.
crsObject GeoJSONCRS The GeoJSON CRS object.
Source:
Throws:
  • If the specified latitude is null or undefined.
    Type
    ArgumentError
  • If the specified longitude is null or undefined.
    Type
    ArgumentError
  • If the specified crsObject is null or undefined.
    Type
    ArgumentError
Returns:
An array containing reprojected coordinates.
Type
Array.<Number>

load(parserCompletionCallback, shapeConfigurationCallback, layer)

Retrieves the GeoJSON, parses it and creates shapes representing its contents. The result is a layer containing the created shapes. A function can also be specified to be called for each GeoJSON geometry so that the attributes and other properties of the shape created for it can be assigned.
Parameters:
Name Type Description
parserCompletionCallback function An optional function called when the GeoJSON loading is complete and all the shapes have been added to the layer.
shapeConfigurationCallback function An optional function called by the addRenderablesFor* methods just prior to creating a shape for the indicated GeoJSON geometry. This function can be used to assign attributes to newly created shapes. The callback function's first argument is the current geometry object. The second argument to the callback function is the object containing the properties read from the corresponding GeoJSON properties member, if any. See the following methods for descriptions of the configuration properties they recognize:
layer RenderableLayer A RenderableLayer to hold the shapes created for each GeoJSON geometry. If null, a new layer is created and assigned to this object's layer property.
Source: