Class GSLayer
Extends GSAbstractLayer.
GSLayer objects are used to work with collections of features.
Layers allow all features owned by the layer to be added, removed, or updated
collectively.
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
GSLayer(name, options)
Creates a new
GSLayer. |
- Properties borrowed from class GSAbstractLayer:
- name
| Method Attributes | Method Name and Description |
|---|---|
|
addFeature(feature)
Adds the specified feature to this layer.
|
|
|
addFeatures(features)
Adds the features in the specified array to this layer.
|
|
|
addFeaturesJson(data, onCreate, args)
Adds the features specified in JSON notation to this layer.
|
|
|
clear()
Removes all features from this layer
|
|
|
Returns the minimum bounds (NZMG) that encompasses all features
that belong to this layer
|
|
|
getFeatureById(id)
Gets the feature with the passed id
|
|
|
Returns this layer's features
|
|
|
remove()
Called by the map when removing this layer
|
|
|
removeFeature(feature, destroy)
Removes the specified feature from this layer.
|
|
|
setVisible(visible)
Sets the visibility of the features contained by this layer
|
|
|
toJson()
Outputs a JSON representation of this layer
|
|
|
toString()
Returns a string representation of this layer for debugging purposes
|
- Methods borrowed from class GSAbstractLayer:
- isBaseLayer, isVisible, setZIndex
Class Detail
GSLayer(name, options)
Creates a new
GSLayer. The name parameter is required and
is used to reference this layer in map operations that work with layers.
- Parameters:
- {String} name
- the unique name for this layer
- {Object} options Optional
- an object literal specifying options for this layer. The following options may be specified:
- {int} options.zIndex
- the zIndex to display this layer at
- {boolean} options.visible
trueif this layer should initially be visible on the map (defaults totrue)
Method Detail
addFeature(feature)
Adds the specified feature to this layer.
- Parameters:
- {Object} feature
- the map feature to add
addFeatures(features)
Adds the features in the specified array to this layer.
- Parameters:
- {Array} features
- an array of features to be added to this layer
addFeaturesJson(data, onCreate, args)
Adds the features specified in JSON notation to this layer. Currently
this method can be used to instantiate point features only.
The minimum properties required for each POI data object are:
- name - this will be displayed in the POI feature tooltip
- x - the NZMG X coordinate
- y - the NZMG Y coordinate
- jsclass - the map feature class that should be instantiated, in this case
GSPointFeature
- Parameters:
- {Array} data
- an array of map features described in JSON notation
- {Function} onCreate
- an optional callback function that will be called after each map feature has been created. It takes 2 parameters: the first is the instance of the feature class that's been created, and the 2nd is the current array element
- {mixed} args Optional
- any number of optional, user-defined arguments that will be
passed to the
onCreatecallback function
- Deprecated:
- use GSLayer#addFeatures instead
- Throws:
- {Error}
- if the feature data specifies a non-existent map feature class to instantiate
clear()
Removes all features from this layer
{GSBounds}
getBounds()
Returns the minimum bounds (NZMG) that encompasses all features
that belong to this layer
- Returns:
- {GSBounds} the minimum bounds that encompass this layer's features
{Object}
getFeatureById(id)
Gets the feature with the passed id
- Parameters:
- id
- Returns:
- {Object} the feature with the passed id or
undefinedif no features were matched
{Array}
getFeatures()
Returns this layer's features
- Returns:
- {Array} an array of map features
remove()
Called by the map when removing this layer
{GSMapFeature}
removeFeature(feature, destroy)
Removes the specified feature from this layer.
- Parameters:
- {Object} feature
- the map feature to remove
- {Boolean} destroy
- if
truefeature event listeners will be removed in addition to removing the feature from the DOM. Defaults totrue
- Returns:
- {GSMapFeature} the map feature that was removed or
nullif the feature was not contained within this layer
setVisible(visible)
Sets the visibility of the features contained by this layer
- Parameters:
- {boolean} visible
trueif this layer's features should be visible
{String}
toJson()
Outputs a JSON representation of this layer
- Returns:
- {String} a JSON string
{String}
toString()
Returns a string representation of this layer for debugging purposes
- Returns:
- {String} the string representation of the features contained by this layer