Class: AnnotationItem

OSDPaperjsAnnotation.AnnotationItem(feature)

Checklist for new AnnotationItem subclasses (see `convertPaperItemToAnnotation` + `toGeoJSONGeometry`): - If the tool uses `initializeGeoJSONFeature` with empty `coordinates`, the constructor may leave an incomplete paper graph until the user draws. `getCoordinates()`, `getProperties()`, and any `toGeoJSONGeometry()` override must not throw in that state—return empty arrays or zeroed metrics as appropriate. - Avoid unguarded `paperItem.children[n]`, `.segments`, or `project` access when those may not exist yet. - If `static paperItemShapeContract` returns `'compoundPath'`, polygon tools and history expect `paper.CompoundPath`; a plain `Path` (e.g. boolean result) triggers a bind-time warning unless the client wraps before assign. - Export shape remains validated via `toGeoJSONGeometry()` + RFC 7946 nesting (`geojsonGeometryShape.mjs`). Represents an annotation item that can be used in a map.

Constructor

new AnnotationItem(feature)

This constructor initializes a new annotation item based on the provided GeoJSON feature. It validates the GeoJSON geometry type and sets up the associated paper item and properties.
Parameters:
Name Type Description
feature Object The GeoJSON feature containing annotation data.
Properties:
Name Type Description
_paperItem paper.Item | null The associated paper item of the annotation.
_props Object The properties of the annotation.
Source:
Throws:
Throws an error if the GeoJSON geometry type is invalid.
Type
string

Members

paperItem

This method sets the associated paper item of the annotation item. It also applies special properties to the paper item to convert it into an annotation item.
Source:

subtype :string

This property returns the subtype from the supported types associated with the annotation item.
Type:
  • string
Source:

type :string

This property returns the type from the supported types associated with the annotation item.
Type:
  • string
Source:

(static) paperItemShapeContract

Optional editor contract for `paperItem` graph shape. Subclasses return `'compoundPath'` so bind can warn when the item is not a `paper.CompoundPath` (e.g. boolean ops returning a plain `Path`).
Source:

Methods

_supportsGeoJSONObj(obj) → {Boolean}

Parameters:
Name Type Description
obj Object the GeoJSON object to test
Source:
Returns:
whether this object is supported
Type
Boolean

getCoordinates() → {Array}

This method returns an array of coordinates representing the position of the annotation item.
Source:
Returns:
An array of coordinates.
Type
Array

getGeoJSONType() → {Object}

Source:
Returns:
object with fields 'type' and optionally 'subtype'
Type
Object

getLabel() → {string}

This method returns the label associated with the annotation item. It looks for the display name of the associated paper item or falls back to the subtype or type from supported types.
Source:
Returns:
The label.
Type
string

getProperties() → {Object}

This method returns the properties associated with the annotation item.
Source:
Returns:
The properties object.
Type
Object

getStyleProperties() → {Object}

This method returns the style properties of the annotation item in JSON format.
Source:
Returns:
The style properties in JSON format.
Type
Object

setStyle(properties)

This method sets the style properties of the annotation item using the provided properties object.
Parameters:
Name Type Description
properties Object The style properties to set.
Source:

supportsGeoJSONType(type, subtypeopt)

Tests whether a given GeoJSON geometry type and optional `properties.subtype` are supported
Parameters:
Name Type Attributes Description
type String
subtype String <optional>
Source:

toGeoJSONFeature() → {Object}

This method converts the annotation item into a GeoJSON feature object. It includes the geometry, properties, style, and other relevant information.
Source:
Returns:
The GeoJSON feature.
Type
Object

toGeoJSONGeometry() → {Object}

This method converts the annotation item into a GeoJSON geometry object, which includes the type, properties, and coordinates of the annotation.
Source:
Returns:
The GeoJSON geometry.
Type
Object

(static) enhanceReplaceWith(paperItem)

Assign the enhanced replaceWith behavior to a paper item (preserves selection and emits item-replaced). For internal use by convertPaperItemToAnnotation only. Subclasses should not call this; assign to this.paperItem and the setter will run convertPaperItemToAnnotation, which applies this enhancement.
Parameters:
Name Type Description
paperItem paper.Item The paper item to enhance.
Source:

(static) supportsGeoJSONType(type, subtypeopt) → {Boolean}

Tests whether the geojson type and (optional) subtype are supported by this type of annotation item
Parameters:
Name Type Attributes Description
type String
subtype String <optional>
Source:
Returns:
The base class always returns false; inheritinc classes override this with class-specific logic
Type
Boolean