JS API
Map Object
QueryEngine Object
Layer Object
Feature Object
Query Object
GeoJson Function Library (Experimental)

Layer Object

The Layer object is created using either the usingLayer or usingNewLayer methods of the Map Object.

It provides a fluent layer object for chaining methods relating to the layer on the map as per the example below.

Parameters

No parameters.

NOTE: The Layer object is never created directly, rather is is created using either the usingLayer or usingNewLayer methods of the Map Object.

Example

var map = new Mapzania.Map("map-div", "AFRICA", function () {

    map.usingLayer("REGIONS")
        .hide();

    map.usingLayer("COUNTRIES")
        .filterByText("LandLocked=='Y'")
        .convertToCentroids()
        .style({ fillColor: "#0000FF"})
        .update();
});

Methods

addFeature

Adds a feature to the layer.

Parameters

Name Required Description
feature Yes A GeoJSON Feature to be added to the layer.

Example

var map = new Mapzania.Map("map-div", "AFRICA");

var feature = {
      type: "Feature",
      geometry: {
        type: "LineString",
        coordinates: [[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]]
      },
      properties: { streetName: "Markus Street", streetType: "mainroad" }
    };

map.usingNewLayer("MY_FEATURES")
  .addFeature(feature)
  .update();

addFeatureCollection

Adds a feature collection to the layer.

Parameters

Name Required Description
featureCollection Yes A GeoJSON FeatureCollection to be added to the layer.

Example

var map = new Mapzania.Map("map-div", "AFRICA");

var features = {
    type: "FeatureCollection",
    features: [{
      type: "Feature",
      geometry: {
        type: "LineString",
        coordinates: [[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]]
      },
      properties: { streetName: "Markus Street", streetType: "mainroad" }
    }]
  };

map.usingNewLayer("MY_FEATURES")
  .addFeatureCollection(features)
  .update();

bringForwards

Brings the layer forwards by one in the layer stack.

This will make the layer more visible as it will be closer to the front/top of the map.

Parameters

No parameters.

Example

map.usingLayer("LAYER2")
	.bringForwards();

bufferGeometry

Creates an filter that buffers geometry. Buffering geometry converts the geometry to the polygon type in the case of points or lines. The geometry is the essentially "inflated" by the factor that is provided. See this for a working example.

Parameters

Name Required Description
factor Yes the factor represents a size (in degrees) by which to buffer (inflate) the geometry.
options No An object for custom configuration of the bufferGeometry filter. The possible options are shown in the section below.

Options

Name Default Description
side "both" This option applies only to buffering of line layers. It determines the side of the line that the buffering is done.

Valid values for this option are:
- "both"
- "left"
- "right"
- "inner"
- "outer"
joins "round" This option applies only to buffering of line layers. It describes how the joins (elbows) of the line should be buffered.

Valid values for this option are:
- "round"
- "mitred"
- "bevel"
ends "round" This option applies only to buffering of line layers. It describes how the ends of the line should be buffered.

Valid values for this option are:
- "round"
- "square"
- "flat"
mitreLimit This option applies only to buffering of line layers. It is only applicable in the case of joins="mitred". It sets the limit of the mitre.

Example

map.usingLayer("PRIMARY_ROADS")
    .bufferGeometry(0.010, {side:"left", joins:"bevel", end:"flat"})
    .style({
        strokeColor: "#000000",
        fillColor: "#FF0000",
        strokeWidth: 1
    })
    .update();

changeProperties

Creates an filter that restricts, adds or changes the feature properties that are returned from a layer. This is analogous to the SELECT clause of a SQL query.

Parameters

Name Required Description
properties Yes Accepts either an array of strings or a comma-delimited string. Each string is a property definition in the following format:

expression AS/as/As property-name
or
expression

If the "AS property-name' clause is excluded, the name of the property will be the underlying property in the expression, if it is simply the property name or automatically generated if it is an expression or built-in keyword.

Expressions can be anything that is valid for the filterByText filter.

A number of built-in keywords exist:
- Area() - This returns an the area of the geometry related to the feature.
- Length() - This returns the length of the geometry related to the feature.

Example

map.usingLayer("COUNTRIES")
  .changeProperties(["Name", "Region", "CALC_AREA"])
  .update();

map.usingLayer("COUNTRIES")
  .changeProperties("Name AS 'Country Name'")
  .update();
  
map.usingLayer("COUNTRIES")
  .changeProperties("Format(Population / Area(), '#,###.0') as Density")
  .update();

map.usingLayer("COUNTRIES")
  .changeProperties("Population / Area()")
  .update();

map.usingLayer("COUNTRIES")
  .changeProperties("Area() As 'MyArea', Length() As 'MyLength'")
  .update();

clearFilters

Removes all filters from a layer.

Parameters

No parameters.

Example

var map = new Mapzania.Map("map-div", "AFRICA");

map.usingLayer("COUNTRIES")
  .clearFilters()
  .update();

clearFeatures

Clears the features from a layer.

Note: this works only for features that have been created client-side.

Layers which have server-side layer-sources will overwrite changes when they are updated (e.g. panning or zooming).

Parameters

No parameters.

Example

var map = new Mapzania.Map("map-div", "AFRICA");

map.usingLayer("MY_FEATURES")
  .clearFeatures()
  .update();

clearStyle

Clears all client-side styles that were applied to a layer.

Parameters

No parameters.

Example

var map = new Mapzania.Map("map-div", "WORLD");

map.usingLayer("COUNTRIES")
    .clearStyle()
    .update()

clipByFeatureCollection

Creates an filter that clips features on the layer based on whether or not they are inside of a GeoJSON FeatureCollection.

Parameters

Name Required Description
featureCollection Yes A GeoJSON FeatureCollection.

Example

var featureCollection = {
  type:"FeatureCollection",
  features: [
    {
      type: "Feature",    
      geometry: {
        coordinates: [
          [
            [4.88922, 52.37072],
            [4.89526, 52.37114],
            [4.89209, 52.36931],
            [4.88925, 52.37072]
          ]
        ],
        type: "Polygon"
      }
    }
  ]
};

map.usingLayer("COUNTRIES")
  .clipByFeatureCollection(featureCollection)
  .update();

convertToCentroids

Creates an filter that converts all geometry to a point that represents its centroid. See this for a working example.

Parameters

No parameters.

Example

map.usingLayer("COUNTRIES")
    .convertToCentroids()
    .style({ fillColor: "#0000FF"})
    .update();

filterByBoundingBox

Creates an filter that filters features based on a bounding box.

Parameters

Name Required Description
bbox Yes The bounding box by which features are filtered.

The format of the bbox parameter is an array of numbers and conforms to the GeoJSON standard for a bounding box i.e. [minX, minY, maxX, maxY] where:

- minX (The minimum x-value of the bounding box)
- minY (The minimum y-value of the bounding box)
- maxX (The maximum x-value of the bounding box)
- maxY (The maximum y-value of the bounding box)

Example

map.usingLayer("COUNTRIES")
  .filterByBoundingBox([12.4, 9.5, 24.6, 41.2])
  .update(); 

filterByFeatureCollection

Creates an filter that filters features based on whether or not they are contained by a GeoJSON FeatureCollection.

Parameters

Name Required Description
features Yes A GeoJSON FeatureCollection.
options No An object for the configuration of the filterByFeatureCollection filter. The possible options are shown in the section below.

Options

Name Default Description
operator 'intersects' Defines the spatial operator that will be applied in the filter. Possible values are:
- 'intersects'
- 'contains'
- 'crosses'

Example

var featureCollection = {
  type:"FeatureCollection",
  features: [
    {
      type: "Feature",    
      geometry: {
        coordinates: [
          [
            [4.88922, 52.37072],
            [4.89526, 52.37114],
            [4.89209, 52.36931],
            [4.88925, 52.37072]
          ]
        ],
        type: "Polygon"
      }
    }
  ]
};

map.usingLayer("COUNTRIES")
  .filterByFeatureCollection(featureCollection);
  .update();

filterByNearest

Creates an filter that filters features based on their proximity to a point (latitude, longitude).

Parameters

Name Required Description
point Yes The GeoJSON Point from which to test proximity. latitude value of the coordinate.
options No An object for the configuration of the filterByNearest filter. The possible options are shown in the section below.

Options

Name Default Description
take 1 The number of features to return.
includeDistance false If this is true, the distance to each feature is added as a property to the feature

Example

map.usingLayer("COUNTRIES")
  .filterByNearest({type:"Point", coordinates:[10.2, -12.5]}, {take:3})
  .update();

filterByText

Creates an filter that filters features based on a text-based query statement. This is analogous to the WHERE clause of a SQL query.

Parameters

Name Required Description
statement Yes The text-based query statement.

The following operators are supported:
- Logical: or, ||, and, &&
- Relational: =, ==, !=, <>, <, >, <=, >=
- Unary: !, not
- Arithmetic: +, -, *, /, %
- Bitwise: &, |, ^, <<, >>, ~

The following mathematical functions are supported:
- Numeric: Ceiling, Exp, Floor, Log, Log10, Max, Min, Pow, Round, Sign, Sqrt, Truncate
- Trigonometric: Acos, Asin, Atan, Cos, Sin, Tan

The following built-in functions are supported:
- Like(item-to-compare, comparison-expression) e.g. Like(NAME, 'John%')
- In(item, list-of-items) e.g. In(NAME, 'Fred', 'John', 'Pete')
- Format(item, format-string) e.g. Format(DATE, 'yyyy-MM-dd')

Example

var map = new Mapzania.Map("map-div", "AFRICA");

map.usingLayer("COUNTRIES")
  .filterByText("LandLocked=='Y'")
  .update();

getFeatureCollection

Returns a feature-collection in GeoJSON format of all the local features shown on the map.

Parameters

No Parameters

Example

var map = new Mapzania.Map("map-div", "AFRICA");

var geojson = map.usingLayer("COUNTRIES")
  .getFeatureCollection();

hide

Sets the visibility of a layer to false.

Parameters

No parameters.

Example

var map = new Mapzania.Map("map-div", "WORLD");

map.usingLayer("COUNTRIES")
    .hide();

sendBackwards

Sends the layer backwards by one in the layer stack.

This will make the layer less visible as it will be further from the front/top of the map.

Parameters

No parameters.

Example

map.usingLayer("LAYER2")
	.sendBackwards();

show

Sets the visibility of a layer to true and loads the content for the layer if it has not been done yet.

Parameters

No parameters.

Example

var map = new Mapzania.Map("map-div", "WORLD");

map.usingLayer("COUNTRIES")
    .show(); 

style

Adds a style to a layer. This style will replace any styles that have already been applied using this method and will supercede any styles that have been configured by the MapStyler.

Parameters

Name Required Description
style Yes An object defining the style. All properties are optional and may be left out.
- fillColor (The fill color of the feature)
- strokeColor (The stroke color of the feature)
- strokeWidth (The width of the stroke of the feature)
- size (Applies to point layers and is the diameter of the point)

Example

var map = new Mapzania.Map("map-div", "WORLD");

map.usingLayer("COUNTRIES")
    .style({ fillColor: "#0000FF"})
    .update();

update

Causes the layer to redraw after its underlying data has changed. This might be due to database changes, styling changes or features being added to the layer on the client.

Parameters

No parameters.

Example

var map = new Mapzania.Map("map-div", "AFRICA");

map.usingLayer("COUNTRIES")
  .filterByText("LandLocked=='Y'")
  .style({ fillColor: "#CCCCCC"})
  .update();

usingFeature

Get a Feature Object from the map based on an id parameter.

This feature object is a fluent object and can be used to chain method calls to the feature as per the example below.

Parameters

Name Required Description
id Yes The id of the feature that will be used.

Example

var map = new Mapzania.Map("map-div", "AFRICA");

map.usingLayer("COUNTRIES")
  .usingFeature("107")
    .show()
    .style({ fillColor: "#FF0000"})
    .update();