[ Whereis® API Home ] [ Developers' Guide ] [ Layers ]

Geometry types are vector-based spatial objects that can be plotted on a map. Typically, geometry objects are used to represent boundaries and paths. There are several types, including the Point, LineString and Polygon. A route line is an example of a LineString geometry.

Types

The following types of geometry are available.

Type

Description

EMS.Geometry.Point(<EMS.LonLat>)

A point geometry representing a single LonLat, rendered as a ring.
EMS.Geometry.MultiPoint([<EMS.LonLat>]A collection of point geometries grouped as one geometry.

EMS.Geometry.LineString([<EMS.Lonlat>])

A open ended polyline with two or more points
EMS.Geometry.MultiLineString([<EMS.Lonlat>])A collection of linestrings grouped as one geometry

EMS.Geometry.LinearRing([<EMS.LonLat>])

A closed linestring, with three or more points

EMS.Geometry.Polygon([<EMS.Geometry.LinearRing>])

A closed loop polygon, comprising an outer ring, witch consecutive rings represented as internal "exclusion zones"

EMS.Geometry.MultiPolygon([<EMS.Geometry.Polygon>])

A collection of polygons grouped as one geometry (e.g. a group of islands)
The Basics

 The following code snippet demonstrates how to add a new vector layer to your map, create a feature with basic point geometry, and add it to the layer. This snippet assumes you have a map.

var layer = new EMS.Layer.Vector("Vectors");
map.addLayers([layer]);

var lonlat = new EMS.LonLat(144.9, -37.9);
var geometry = new EMS.Geometry.Point(lonlat);
var feature = new EMS.Feature.Vector(geometry);.
layer.addFeatures([feature]);
Line Geometry

To create a more complex geometry such as a LineString, construct a geometry object, passing in a list of EMS.LonLat objects. The following code snippets show you how.

var lonlats = [
 new EMS.LonLat(144.9, -37.9),
 new EMS.LonLat(144.7, -37.9),
 new EMS.LonLat(144.8, -37.8)
];
var geometry = new EMS.Geometry.LineString(lonlats);
...
Polygon Geometry

To construct a polygon, first create a LinearRing, or rings, and add them as a list to your Polygon constructor. Similarly, to construct a MultiPolygon geometry you will need a list of Polygons.

var lonlats = [
 new EMS.LonLat(144.9, -37.9),
 new EMS.LonLat(144.7, -37.9),
 new EMS.LonLat(144.8, -37.8)
];
var linearRing = new EMS.Geometry.LinearRing(lonlats);
var geometry = new EMS.Geometry.Polygon([linearRing]);
...
Custom Styling

To override style elements, include a style when you construct your feature

var style = OpenLayers.Util.applyDefaults(
   {
     strokeColor: "#0000ff", 
     strokeWidth: 4
   },
   OpenLayers.Feature.Vector.style['select']
);
var geometry = new EMS.Geometry.Point(lonlat);
var feature = new EMS.Feature.Vector(geometry, null, style); 
...
Attributes

For each feature you can attach an additional attributes object, which can be extra information about the feature, or anything you like. For example:

var attributes = {
   name:"My Feature",
   id: 123,
   type: "Parks and Gardens"
};
var feature = new EMS.Feature.Vector(geometry, attributes);
...

 

 

 

 

 

NEXT PAGE

NOTES
Icon

On some web browsers adding too many objects or overly complex geometries can cause poor performance during render, drag and zoom events. This can be partially avoided by running the "simplify" function that is found on line-based geometry objects. Always test the limits of your target browsers.

Icon

To see this in action check out the map overlay geometry live examples:

Point geometry

Linestring geometry

Polygon and regular polygon

Circle and ellipse

Icon

For information about importing formatted geospatial data from a file or local resource, check out:

Importing geometry from a URI