GeoScript

Table Of Contents

Previous topic

proj.Projection

Next topic

The workspace module

The layer module

The layer module provides a constructor for Layer objects.

js> var LAYER = require("geoscript/layer");

layer.Layer

class layer.Layer

Create a new layer. If a workspace is not provided, a temporary layer will be created. If a layer is created without a schema, a default schema will be applied.

Example Use

Sample code to create a temporary layer:

js> var layer = new LAYER.Layer({name: "temp"});

js> var layer = new LAYER.Layer({
  >     name: "temp",
  >     fields: [{name: "geom", type: "Geometry"}]
  > });

js> var FEATURE = require("geoscript/feature");
js> var schema = new FEATURE.Schema({
  >     name: "temp",
  >     fields: [{name: "geom", type: "Geometry"}]
  > });
js> var layer = new LAYER.Layer({schema: schema});

Config Properties

style

style.Style Optional style to be used when rendering this layer as part of a map. In addition to a style instance, a style config object can be provided.

title

String Optional title for the layer.

Properties

Layer.bounds

geom.Bounds The bounds for all features on this layer.

Layer.count

Number The number of features contained in the layer.

Layer.features

cursor.Cursor A cursor object for accessing all features on the layer.

Example use:

js> layer.features.forEach(function(feature) {
  >     print(feature.toString());
  > });
Layer.json

String The JSON representation of this layer. This representation does not include members for each feature in the layer.

Layer.name

String The layer name (read-only).

Layer.projection

proj.Projection Optional projection for the layer. If set, any features added to the layer will be tranformed to this projection if they are in a different projection. This must be set before features are added to the layer.

Layer.schema

feature.Schema The schema for this layer (read-only).

Layer.style

style.Style The style to be used when rendering this layer as part of a map.

Layer.temporary

Boolean The layer has not been persisted to a workspace (read-only).

Layer.title

String The layer title. Defaults to the layer name.

Methods

Layer.add()
Parameters:objObject A feature.Feature or a feature attribute values object.

Add a feature to a layer. Optionally, an object with feature attribute values may be provided.

Example use:

js> var GEOM = require("geoscript/geom");
js> layer.add({geom: new GEOM.Point([0, 1])});
Layer.clone()
Parameters:nameString New layer name. If not provided, one will be generated.
Returns:layer.Layer The layer clone.

Create a temporary copy of this layer.

Layer.get()
Parameters:idString || Filter Feature identifier. Alternatively you can provide an arbitrary filter. In the case of a filter, only the first feature in the resulting query will be returned.
Returns:feature.Feature

Get a single feature using the feature id.

Layer.getBounds()
Parameters:filterfilter.Filter Optional filter or CQL string.
Returns:geom.Bounds

Get the bounds for all features on the layer. Optionally, the bounds can be generated for all features that match the given filter.

Layer.getCount()
Parameters:filterfilter.Filter Optional filter or CQL string.
Returns:Number

Get the number of features on the layer matching the given filter.

Layer.query()
Parameters:filterfilter.Filter or String A filter or a CQL string.
Returns:cursor.Cursor A cursor for accessing queried features.

Query for features from the layer. The return will be an object with forEach, hasNext, and next methods. If no filter is provided, all features will be included in the results.

Example use:

js> layer.query("name = 'foo'").forEach(function(feature) {
  >     print(feature.toString());
  > });
Layer.remove()
Parameters:filterfilter.Filter or String or feature.Feature

Remove features from a layer that match the given filter or CQL string. Alternatively, a feature can be provided to remove a single feature from the layer.

Example use:

js> var GEOM = require("geoscript/geom");
js> layer.add({geom: new GEOM.Point([1, 2])});
js> layer.remove("INTERSECTS(geom, POINT(1 2))");
Layer.update()

Update any features that have been modified since the last update. This persists feature changes.