$g. Feature

new $g.Feature(geometry, propertiesopt)

Constructs a new Feature.

Parameters:
NameTypeAttributesDescription
geometry$g.Geometry

The feature's geometry

propertiesobject<optional>

Properties for the feature. The values should be strings.

Since
  • 6.0.0

Members

geometry :$g.Geometry

The geometry associated with this feature.

Since
  • 6.0.0

(readonly) properties :object

The properties associated with this feature. Modifying this property directly has no effect, use .setProperty() instead.

Type:
  • object
Since
  • 6.0.0

Methods

(static) fromElement(element, geometry) → {$g.Feature}

Creates a feature from the given semantic element or hit.

Parameters:
NameTypeDescription
element$k.SemanticElement | $k.Hit

The semantic element or hit

geometry$g.Geometry | $k.AttributeType | string

The feature's geometry or the internal name of a geometry attribute type

Since
  • 6.0.0
Throws:

If the second argument referes to an attribute type that has no (unique) value at the element

Type
$k.exception.NotUnique
Returns:
Type: 
$g.Feature

setColor(color)

Sets the color for this feature's geometry on the map.

Parameters:
NameTypeDescription
color$k.Color | string

Color value, color name (e.g. 'red') or hex value (e.g. '#ff0000')

Since
  • 6.0.0

setElement(element)

Sets the semantic element associated with this feature, e.g. for click actions and tooltips.

Parameters:
NameTypeDescription
element$k.SemanticElement

The semantic element

Since
  • 6.0.0

setGeometry(geometry)

Sets the geometry associated with this feature.

Parameters:
NameTypeDescription
geometry$g.Geometry

The geometry

Since
  • 6.0.0

setIcon(icon)

Sets the icon for this feature that is shown in map markers.

Parameters:
NameTypeDescription
icon$k.Attribute | $k.Blob | string

The icon attribute or blob. An id string of an icon attribute is also accepted.

Since
  • 6.0.0
Throws:

setProperty(property, value)

Sets a custom property to be included in the GeoJSON's properties object.

Parameters:
NameTypeDescription
propertystring

Name of the property

valueany

Value of the property

Since
  • 6.0.0

setTooltip(tooltip)

Sets the tooltip for this feature that is shown when hovering over it. The tooltip supports basic formatting using HTML.

Parameters:
NameTypeDescription
tooltipstring

The tooltip (HTML) string

Since
  • 6.0.0

toGeoJSON() → {object}

Creates a GeoJSON object from this feature. Note that all property values not representable in JSON will be omitted.

Since
  • 6.0.0
Throws:

If this feature has no geometry assigned or cannot be represented as GeoJSON for some other reason.

Type
$k.exception.InvalidValue
Returns:

GeoJSON object.

Type: 
object