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.

>> var Layer = require("geoscript/layer").Layer;

layer.Layer()

class layer.Layer(config)

Create a new layer. If a workspace is not provided, a temporary layer will be created.

Example Use

Sample code to create a temporary layer:

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

The code above is shorthand for more explicitly creating a schema and passing that to the layer.

>> var Schema = require("geoscript/feature").Schema;
>> var schema = Schema({
..   name: "temp3",
..   fields: [{name: "geom", type: "Geometry"}]
.. });
>> var 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.

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

feature.Collection() An iterator for accessing all features on the layer.

Example use:

>> 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 transformed 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(feature)
Arguments:

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

Example use:

>> var Point = require("geoscript/geom").Point;
>> layer.add({geom: Point([0, 1])});
Layer.clone(name)
Arguments:
  • 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(id)
Arguments:
  • idString or feature: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(filter)
Arguments:
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(filter)
Arguments:
Returns:

Number

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

Layer.query(filter)
Arguments:
  • filterfilter.Filter or String A filter or a CQL string.
Returns:

feature.Collection() An iterator 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:

>> layer.query("name = 'foo'").forEach(function(feature) {
..   print(feature.toString());
.. });
Layer.remove(filter)
Arguments:

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:

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

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