Articles and Tutorials

GSLayer

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.

GSLayer objects should not be instantiated directly but created through a call to the GSMap object that will contain the layer:

var roadLayer = myMap.createLayer("roads");

By default a newly created layer is visible on the map. This means that calling either the layer's addFeature() or addFeatures() method will cause the added features to appear upon the map immediately. In situations where this isn't the desired behaviour the layers visible property can be set to false before any features are added.


Field Summary
 String name
          The layer name
 private visible
          true if the features contained by this layer should be visible on the map
 
Constructor Summary
GSLayer (<String> name)
            GSLayer should not be directly instantiated, it's created through a call to the GSMap object that will contain the layer.
 
Method Summary
 void addFeature(<Object> feature)
           Adds the specified feature to this layer.
 void addFeatures(features)
           Adds the features in the specified array to this layer.
 void addFeaturesJson(<String> data, <Function> onCreate)
           Adds the features specified in JSON notation to this layer.
 void clear()
           Removes all features from this layer
 GSBounds getBounds()
           Returns the minimum bounds (NZMG) that encompasses all features that belong to this layer
 void removeFeature(<Object> feature)
           Removes the specified feature from this layer.
 void setVisible(<boolean> visible)
           Sets the visibility of the features contained by this layer
 String toString()
           Returns a string representation of this layer for debugging purposes

Field Detail

name

String name
    The layer name

visible

private visible
    true if the features contained by this layer should be visible on the map
Constructor Detail

GSLayer

GSLayer(<String> name)
    GSLayer should not be directly instantiated, it's created through a call to the GSMap object that will contain the layer. Creates a new GSLayer. The name parameter is required and is used to reference this layer in map operations that work with layers.
  •  
      name - the unique name for this layer
  • Parameters:
Method Detail

addFeature

void addFeature(<Object> feature)
    Adds the specified feature to this layer.
  •  
      feature - the map feature to add
  • Parameters:

addFeatures

void addFeatures(features)
    Adds the features in the specified array to this layer.
  •  
      an - array of features to be added to this layer
  • Parameters:

addFeaturesJson

void addFeaturesJson(<String> data, <Function> onCreate)
    Adds the features specified in JSON notation to this layer. Currently this method can be used to instantiate point features only.
  •  
      data - an array of map features described in JSON notation
      onCreate - [optional] a 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
      arg - [optional] any number of user-defined arguments that will be passed to the onCreate callback function
  • Parameters:
  •  
      - NoSuchClassException if the feature data specifies a non-existent map feature class to instantiate
  • Throws:

clear

void clear()
    Removes all features from this layer

getBounds

GSBounds getBounds()
    Returns the minimum bounds (NZMG) that encompasses all features that belong to this layer
  •  
      the minimum bounds that encompass this layer's features
  • Returns:

removeFeature

void removeFeature(<Object> feature)
    Removes the specified feature from this layer.
  •  
      feature - the map feature to remove
  • Parameters:

setVisible

void setVisible(<boolean> visible)
    Sets the visibility of the features contained by this layer
  •  
      visible - true if this layer's features should be visible
  • Parameters:

toString

String toString()
    Returns a string representation of this layer for debugging purposes
  •  
      the string representation of the features contained by this layer
  • Returns: