Class: annotationLayer

geo. annotationLayer

new geo.annotationLayer(arg){geo.annotationLayer}

Layer to handle direct interactions with different features. Annotations (features) can be created by calling mode() or cancelled with mode(null). There is also an "edit" mode which is used when modifying an annotation.

Name Type Description
arg geo.annotationLayer.spec optional

Specification for the new layer.

Fires:
Returns:
Type Description
geo.annotationLayer

Extends

Type Definitions

geo.annotationLayer.labelRecordobject

Properties:
Name Type Argument Description
text string

The text of the label

position geo.geoPosition

The position of the label in map gcs coordinates.

style geo.textFeature.styleSpec <optional>

A geo.textFeature style object.

geo.annotationLayer.specgeo.layer.spec

Object specification for an annotation layer.

Properties:
Name Type Argument Default Description
dblClickTime number <optional>
300

The delay in milliseconds that is treated as a double-click when working with annotations.

adjacentPointProximity number <optional>
5

The minimum distance in display coordinates (pixels) between two adjacent points when creating a polygon or line. A value of 0 requires an exact match.

continuousPointProximity number <optional>
5

The minimum distance in display coordinates (pixels) between two adjacent points when dragging to create an annotation. false disables continuous drawing mode.

continuousPointColinearity number <optional>
1.0deg

The minimum angle between a series of three points when dragging to not interpret them as colinear. Only applies if continuousPointProximity is not false.

finalPointProximity number <optional>
10

The maximum distance in display coordinates (pixels) between the starting point and the mouse coordinates to signal closing a polygon. A value of 0 requires an exact match. A negative value disables closing a polygon by clicking on the start point.

showLabels boolean <optional>
true

Truthy to show feature labels that are allowed by the associated feature to be shown.

clickToEdit boolean <optional>
false

Truthy to allow clicking an annotation to place it in edit mode.

defaultLabelStyle geo.textFeature.styleSpec <optional>

Default styles for labels.

id number <optional>

The id of the layer. Defaults to a increasing sequence.

map geo.map <optional>
null

Parent map of the layer.

renderer string | geo.renderer <optional>

Renderer to associate with the layer. If not specified, either annotations or features can be used to determine the renderer. If a geo.renderer instance, the renderer is not recreated; not all renderers can be shared by multiple layers.

autoshareRenderer boolean <optional>
true

If truthy and the renderer supports it, auto-share renderers between layers. Currently, auto-sharing can only occur for webgl renderers, and will only occur between adjacent layers than have the same opacity. Shared renderers has slightly different behavior than non-shared renderers: changing z-index may result in rerendering and be slightly slower; only one DOM canvas is used for all shared renderers. Some features have slight z-stacking differences in shared versus non-shared renderers.

canvas HTMLElement <optional>

If specified, use this canvas rather than a canvas associaied with the renderer directly. Renderers may not support sharing a canvas.

annotations Array.<string> | object <optional>

A list of annotations that will be used on this layer, used to select a renderer. Instead of a list, if this is an object, the keys are the annotation names, and the values are each a list of modes that will be used with that annotation. See featuresForAnnotations more details. This is ignored if renderer is specified.

features Array.<string> <optional>

A list of features that will be used on this layer, used to select a renderer. Features are the basic feature names (e.g., 'quad'), or the feature name followed by a required capability (e.g., 'quad.image'). This is ignored if renderer or annotations is specified.

active boolean <optional>
true

Truthy if the layer has the active css class and may receive native mouse events.

attribution string <optional>

An attribution string to display.

opacity number <optional>
1

The layer opacity on a scale of [0-1].

name string <optional>
''

A name for the layer for user convenience. If specified, this is also the id property of the containing DOM element.

selectionAPI boolean <optional>
true

Truthy if the layer can generate selection and other interaction events.

sticky boolean <optional>
true

Truthy if the layer should navigate with the map.

visible boolean <optional>
true

Truthy if the layer is visible.

zIndex number <optional>

The z-index to assign to the layer (defaults to the index of the layer inside the map).

Members

inherited idle

Getter for the idle state. Read only.

Properties:
Name Type Description
idle boolean

true if the object is idle (onIdle would call a handler immediately).

inherited protectednewLayerId

Gets a new id number for a layer.

Methods

inherited active(arg){boolean|this}

Get/Set whether or not the layer is active. An active layer will receive native mouse when the layer is on top. Non-active layers will never receive native mouse events.

Name Type Description
arg boolean optional

If specified, the new active value.

Returns:
Type Description
boolean | this

addAnnotation(annotation, gcs){this}

Add an annotation to the layer. The annotation could be in any state.

Name Type Description
annotation geo.annotation

Te annotation to add.

gcs string | geo.transform | null optional

undefined to use the interface gcs, null to use the map gcs, or any other transform.

Fires:
Returns:
Type Description
this The current layer.

inherited addChild(child){this}

Add a child (or an array of children) to the object.

Name Type Description
child geo.object | Array.<geo.object>

A child object or array of child objects.

Returns:
Type Description
this

inherited addFeature(feature){this}

Add a feature to the layer if it is not already present.

Name Type Description
feature object

the feature to add.

Returns:
Type Description
this

inherited addPromise(promise){this}

Add the promise here and also propagate up the scene tree.

Name Type Description
promise Promise

A promise object.

Returns:
Type Description
this

Get an annotation by its id.

Name Type Description
id number

The annotation ID.

Returns:
Type Description
geo.annotation The selected annotation or undefined if none matches the id.

annotations(){Array.<geo.annoation>}

Get the list of annotations on the layer.

Returns:
Type Description
Array.<geo.annoation> An array of annotations.

inherited attribution(arg){string|this}

Get or set the attribution html content that will displayed with the layer. By default, nothing will be displayed. Note, this content is not html escaped, so care should be taken when renderering user provided content.

Name Type Description
arg string nullable

An html fragment

Returns:
Type Description
string | this Chainable as a setter

inherited autoshareRenderer(){boolean}

Get the setting of autoshareRenderer.

Returns:
Type Description
boolean

inherited canvas(){HTMLCanvasElement}

Get canvas of the layer.

Returns:
Type Description
HTMLCanvasElement The canvas element associated with the layer.

Get an array of the child objects.

Returns:
Type Description
Array.<geo.object> A copy of the array of child objects.

Clear all features in layer.

Returns:
Type Description
this

inherited createFeature(featureName, arg){geo.feature}

Create a feature by name.

Name Type Description
featureName string

The name of the feature to create.

arg object

Properties for the new feature.

Returns:
Type Description
geo.feature The created feature.

Return last time data got changed.

Returns:
Type Description
geo.timestamp The data time.

inherited deleteFeature(feature){this}

Delete feature.

Name Type Description
feature geo.feature

The feature to delete.

Returns:
Type Description
this

displayDistance(coord1, gcs1, coord2, gcs2){number}

Calculate the display distance for two coordinate in the current map.

Name Type Description
coord1 geo.geoPosition | geo.screenPosition

The first coordinates.

gcs1 string | geo.transform | null

undefined to use the interface gcs, null to use the map gcs, 'display' if the coordinates are already in display coordinates, or any other transform.

coord2 geo.geoPosition | geo.screenPosition

the second coordinates.

gcs2 string | geo.transform | null optional

undefined to use the interface gcs, null to use the map gcs, 'display' if the coordinates are already in display coordinates, or any other transform.

Returns:
Type Description
number the Euclidian distance between the two coordinates.

Update if necessary and draw the layer.

Returns:
Type Description
this The current layer.

inherited features(val){Array.<geo.feature>|this}

Get/Set drawables.

Name Type Description
val Array.<geo.feature>

A list of features, or unspecified to return the current feature list. If a list is provided, features are added or removed as needed.

Returns:
Type Description
Array.<geo.feature> | this The current features associated with the layer or the current layer.

Transform coordinates from a local coordinate system to world coordinates.

Name Type Description
input geo.geoPosition

Renderer coordinates.

Returns:
Type Description
geo.geoPosition World coordinates.

inherited gcsFeatures(val){string|this}

Get or set the gcs for all features. For features, the default is usually the map's ingcs.

Name Type Description
val string optional nullable

If undefined, return the current gcs. If null, use the map's interface gcs. Otherwise, set a new value for the gcs. When getting the current gcs, if not all features have the same gcs, undefined will be returned.

Returns:
Type Description
string | this A string used by geo.transform. If the map interface gcs is in use, that value will be returned. If the gcs is set, return the current class instance.

inherited geoIsOn(event, handler){boolean}

Report if an event handler is bound to this object.

Name Type Description
event string | Array.<string>

An event or list of events to check.

handler function optional

A function that might be bound. If undefined, this will report true if there is any handler for the specified event.

Returns:
Type Description
boolean true if any of the specified events are bound to the specified handler.

geojson(geojson, clear, gcs, includeCrs){object|number|undefined}

Return the current set of annotations as a geojson object. Alternately, add a set of annotations from a geojson object.

Name Type Description
geojson string | objectFile optional

If present, add annotations based on the given geojson object. If undefined, return the current annotations as geojson. This may be a JSON string, a javascript object, or a File object.

clear boolean | string optional

If true, when adding annotations, first remove all existing objects. If 'update', update existing annotations and remove annotations that no longer exist. If falsy, update existing annotations and leave annotations that have not chaged.

gcs string | geo.transform | null optional

undefined to use the interface gcs, null to use the map gcs, or any other transform.

includeCrs boolean optional

If truthy, include the coordinate system in the output.

Returns:
Type Description
object | number | undefined If geojson was undefined, the current annotations is a javascript object that can be converted to geojson using JSON.stringify. If geojson is specified, either the number of annotations now present upon success, or undefined if the value in geojson was not able to be parsed.

inherited geoOff(event, arg){this}

Remove handlers from one event or an array of events. If no event is provided all handlers will be removed.

Name Type Description
event string | Array.<string> optional

An event or a list of events from geo.event or defined by the user, or undefined to remove all events (in which case arg is ignored).

arg function | Array.<function()> optional nullable

A function or array of functions to remove from the events or a falsy value to remove all handlers from the events.

Returns:
Type Description
this

inherited geoOn(event, handler){this}

Bind an event handler to this object.

Name Type Description
event string

An event from geo.event or a user-defined value.

handler function

A function that is called when event is triggered. The function is passed a geo.event object.

Returns:
Type Description
this

inherited geoTrigger(event, args, childrenOnly){this}

Trigger an event (or events) on this object and call all handlers.

Name Type Description
event string

The event to trigger.

args object

Arbitrary argument to pass to the handler.

childrenOnly boolean optional

If truthy, only propagate down the tree.

Returns:
Type Description
this

inherited height(){number}

Return the height of the layer in pixels.

Returns:
Type Description
number The height of the parent map in pixels.

inherited id(val){string|this}

Get/Set id of the layer.

Name Type Description
val string | null optional

If null, generate a new layer id. Otherwise, if specified, the new id of the layer.

Returns:
Type Description
string | this

inherited initialized(val){boolean|this}

Get/Set if the layer has been initialized.

Name Type Description
val boolean optional

If specified, update the intialized value. Otherwise, return the current instance.

Returns:
Type Description
boolean | this Either the initialized value or this.

Get the map associated with this layer.

Returns:
Type Description
geo.map The map associated with the layer.

mode(arg, editAnnotation){string|null|this}

Get or set the current mode.

Name Type Description
arg string | null optional

undefined to get the current mode, null to stop creating/editing, this.modes.edit ('edit') plus an annotation to switch to edit mode, or the name of the type of annotation to create. Available annotations can listed via geo.listAnnotations.

editAnnotation geo.annotation optional

If arg === this.modes.edit, this is the annotation that should be edited.

Fires:
Returns:
Type Description
string | null | this The current mode or the layer.

inherited modified(){this}

Update the timestamp to the next global timestamp value.

Returns:
Type Description
this

inherited moveDown(n){this}

Bring the layer below the given number of layers. This will rotate the current z-indices for this and the previous n layers.

Name Type Default Description
n number 1 optional

The number of positions to move.

Returns:
Type Description
this

inherited moveToBottom(){this}

Bring the layer to the bottom of the map layers.

Returns:
Type Description
this

inherited moveToTop(){this}

Bring the layer to the top of the map layers.

Returns:
Type Description
this

inherited moveUp(n){this}

Bring the layer above the given number of layers. This will rotate the current z-indices for this and the next n layers.

Name Type Default Description
n number 1 optional

The number of positions to move.

Returns:
Type Description
this

inherited name(val){string|this}

Get/Set name of the layer.

Name Type Description
val string optional

If specified, the new name of the layer.

Returns:
Type Description
string | this

inherited node(){div}

Get root node of the layer.

Returns:
Type Description
div

inherited onIdle(handler){this}

Bind a handler that will be called one time when all internal promises are resolved. If there are no outstanding promises, this is invoked synchronously.

Name Type Description
handler function

A function taking no arguments.

Returns:
Type Description
this

inherited opacity(opacity){number|this}

Get or set the current layer opacity. The opacity is in the range [0-1]. An opacity of 0 is not the same as setting visible(false), as interactions can still occurr with the layer.

Name Type Description
opacity number optional

If specified, set the opacity. Otherwise, return the opacity.

Returns:
Type Description
number | this The current opacity or the current layer.

options(arg1, arg2){object|this}

Set or get options.

Name Type Description
arg1 string | object optional

If undefined, return the options object. If a string, either set or return the option of that name. If an object, update the options with the object's values.

arg2 object optional

If arg1 is a string and this is defined, set the option to this value.

Returns:
Type Description
object | this If options are set, return the annotation, otherwise return the requested option or the set of options.

Get/set parent of the object.

Name Type Description
arg geo.sceneObject optional

The new parant or undefined to get the current parent.

Returns:
Type Description
this | geo.sceneObject

removeAllAnnotations(skipCreating, update){number}

Remove all annotations from the layer.

Name Type Description
skipCreating boolean optional

If truthy, don't remove annotations that are in the create state.

update boolean optional

If false, don't update the layer after removing the annotation.

Returns:
Type Description
number The number of annotations that were removed.

removeAnnotation(annotation, update){boolean}

Remove an annotation from the layer.

Name Type Description
annotation geo.annoation

The annotation to remove.

update boolean

If false, don't update the layer after removing the annotation.

Fires:
Returns:
Type Description
boolean true if an annotation was removed.

inherited removeChild(child){this}

Remove a child (or array of children) from the object.

Name Type Description
child geo.object | Array.<geo.object>

A child object or array of child objects.

Returns:
Type Description
this

inherited removeFeature(feature){this}

Remove a feature without destroying it.

Name Type Description
feature geo.feature

The feature to remove.

Returns:
Type Description
this

Get the renderer for the layer.

Returns:
Type Description
geo.renderer The renderer associated with the layer or null if there is no renderer.

inherited rendererName(){string}

Get the name of the renderer.

Returns:
Type Description
string

inherited selectionAPI(val){boolean|this}

Get/Set selectionAPI of the layer.

Name Type Description
val boolean optional

If specified change the selectionAPI state of the layer, otherwise return the current state.

Returns:
Type Description
boolean | this The selectionAPI state or the current layer.

inherited sticky(){boolean}

Get whether or not the layer is sticky (navigates with the map).

Returns:
Type Description
boolean

inherited timestamp(){number}

Get time.

Returns:
Type Description
number The timestamp. This is 0 if the timestamp has never been modified.

Transform coordinates from world coordinates into a local coordinate system specific to the underlying renderer. This method is exposed to allow direct access the rendering context, but otherwise should not be called directly. The default implementation is the identity operator.

Name Type Description
input geo.geoPosition

World coordinates.

Returns:
Type Description
geo.geoPosition Renderer coordinates.

Return the modified time for the last update that did something.

Returns:
Type Description
geo.timestamp The update time.

validateAttribute(value, dataType){number|string|object|boolean|undefined}

Validate a value for an attribute based on a specified data type. This returns a sanitized value or undefined if the value was invalid. Data types include:

  • color: a css string, #rrggbb hex string, #rgb hex string, number, or object with r, g, b properties in the range of [0-1].
  • opacity: a floating point number in the range [0, 1].
  • positive: a floating point number greater than zero.
  • boolean: a string whose lowercase value is 'false', 'off', or 'no', and falsy values are false, all else is true. null and undefined are still considered invalid values.
  • booleanOrNumber: a string whose lowercase value is 'false', 'off', 'no', 'true', 'on', or 'yes', falsy values that aren't 0, and true are handled as booleans. Otherwise, a floating point number that isn't NaN or an infinity.
  • coordinate2: either an object with x and y properties that are numbers, or a string of the form [,] with optional whitespace, or a JSON encoded object with x and y values, or a JSON encoded list of at leasst two numbers.
  • number: a floating point number that isn't NaN or an infinity.
  • angle: a number that represents radians. If followed by one of deg, grad, or turn, it is converted to radians. An empty string is also allowed.
  • text: any text string.
Name Type Description
value number | string | object | boolean

The value to validate.

dataType string

The data type for validation.

Returns:
Type Description
number | string | object | boolean | undefined The sanitized value or undefined.

inherited visible(val){boolean|this}

Get/Set visibility of the layer.

Name Type Description
val boolean optional

If specified, change the visibility, otherwise return it.

Returns:
Type Description
boolean | this The current visibility or the layer.

inherited width(){number}

Return the width of the layer in pixels.

Returns:
Type Description
number The width of the parent map in pixels.

inherited zIndex(zIndex, allowDuplicate){number|this}

Get or set the z-index of the layer. The z-index controls the display order of the layers in much the same way as the CSS z-index property.

Name Type Description
zIndex number optional

The new z-index, or undefined to return the current z-index.

allowDuplicate boolean optional

When setting the z index, if this is truthy, allow other layers to have the same z-index. Otherwise, ensure that other layers have distinct z-indices from this one.

Returns:
Type Description
number | this