Class MapPolygon
- Last UpdatedJan 17, 2025
- 5 minute read
Class MapPolygon
- java.lang.Object
-
- com.here.NativeBase
-
- com.here.sdk.mapview.MapPolygon
-
public final class MapPolygon extends NativeBase
A visual representation of a polygon on the map. Can be used to visualize areas of all shapes and sizes.
The geometry to be visualized is represented by an instance of
GeoPolygon
. To display circular areas (for example, a position accuracy indicator) use a GeoPolygon created from aGeoCircle
usingGeoPolygon(GeoCircle)
.Note:
- The polygon shape should not cover more than half of the globe, otherwise unexpected results may occur.
- Polygons which are self-intersecting are not supported and may lead to render artifacts.
- The inner boundaries (holes) specified in the GeoPolygon are ignored.
-
-
Constructor Summary
Constructors Constructor Description MapPolygon(GeoPolygon geometry, Color color)
Creates a new MapPolygon instance with outline visualization disabled and containing the geometry passed in.MapPolygon(GeoPolygon geometry, Color color, Color outlineColor, double outlineWidthInPixels)
Creates a new MapPolygon instance with outline visualization enabled and containing the geometry passed in.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getDrawOrder()
Gets the draw order of this map polygon relative to other map polygons.Color
getFillColor()
Gets the current color of the fill.GeoPolygon
getGeometry()
Gets the current geometry of the polygon.Metadata
getMetadata()
Gets the Metadata instance attached to this polygon.Color
getOutlineColor()
Gets the color of the polygon outline.double
getOutlineWidth()
Gets the outline width of the polygon in pixels.java.util.List<MapMeasureRange>
getVisibilityRanges()
Gets the list of visibility ranges.void
setDrawOrder(int value)
Sets the draw order of this map polygon relative to other map polygons.void
setFillColor(Color value)
Sets the current color of the fill.void
setGeometry(GeoPolygon value)
Sets a new geometry to update the appearance.void
setMetadata(Metadata value)
Sets the Metadata instance to be attached to this polygon.void
setOutlineColor(Color value)
Sets the color of the polygon outline.void
setOutlineWidth(double value)
Sets the outline width of the polygon in pixels.void
setVisibilityRanges(java.util.List<MapMeasureRange> value)
Sets visibility ranges for this map polygon.
-
-
-
Constructor Detail
-
MapPolygon
public MapPolygon(@NonNull GeoPolygon geometry, @NonNull Color color)
Creates a new MapPolygon instance with outline visualization disabled and containing the geometry passed in.
The winding order of the vertices can be in clockwise or counter-clockwise order. It is recomended to provide the outer boundary ordered clockwise and closed.
Note:
- The polygon shape should not cover more than half of the globe, otherwise unexpected results may occur.
- Polygons which are self-intersecting are not supported and may lead to render artifacts.
- The inner boundaries (holes) specified in the GeoPolygon are ignored.
- Parameters:
geometry
-The list of vertices representing the outer boundary of polygon.
color
-The fill color for the polygon
-
MapPolygon
public MapPolygon(@NonNull GeoPolygon geometry, @NonNull Color color, @NonNull Color outlineColor, double outlineWidthInPixels)
Creates a new MapPolygon instance with outline visualization enabled and containing the geometry passed in.
Transparent outlines are not supported. Any color with transparency (alpha value other than 1) will be rendered as fully opaque by interpreting the alpha value as 1.
The winding order of the vertices can be in clockwise or counter-clockwise order. It is recomended to provide the outer boundary ordered clockwise and closed.
Note:
- The polygon shape should not cover more than half of the globe, otherwise unexpected results may occur.
- Polygons which are self-intersecting are not supported and may lead to render artifacts.
- The inner boundaries (holes) specified in the GeoPolygon are ignored.
- Parameters:
geometry
-The list of vertices representing the outer boundary of polygon.
color
-The fill color for the polygon.
outlineColor
-The color of the polygon outline, alpha channel is ignored and treated as 1.
outlineWidthInPixels
-The width of the polygon outline (in pixels). Negative values are clamped to 0.
-
-
Method Detail
-
getGeometry
@NonNull public GeoPolygon getGeometry()
Gets the current geometry of the polygon.
- Returns:
The geometry of the polygon. Setting a new geometry will update the appearance.
-
setGeometry
public void setGeometry(@NonNull GeoPolygon value)
Sets a new geometry to update the appearance.
The winding order of the vertices can be in clockwise or counter-clockwise order. It is recomended to provide the outer boundary ordered clockwise and closed.
Note:
- The polygon shape should not cover more than half of the globe, otherwise unexpected results may occur.
- Polygons which are self-intersecting are not supported and may lead to render artifacts.
- The inner boundaries (holes) specified in the GeoPolygon are ignored.
- Parameters:
value
-The geometry of the polygon. Setting a new geometry will update the appearance.
-
getMetadata
@Nullable public Metadata getMetadata()
Gets the Metadata instance attached to this polygon.
- Returns:
The Metadata instance attached to this polygon,
null
by default.
-
setMetadata
public void setMetadata(@Nullable Metadata value)
Sets the Metadata instance to be attached to this polygon.
- Parameters:
value
-The Metadata instance attached to this polygon,
null
by default.
-
getFillColor
@NonNull public Color getFillColor()
Gets the current color of the fill.
- Returns:
Color of the polygon's fill.
-
setFillColor
public void setFillColor(@NonNull Color value)
Sets the current color of the fill.
Fully transparent color (alpha set to 0) disables the fill completely.
- Parameters:
value
-Color of the polygon's fill.
-
getDrawOrder
public int getDrawOrder()
Gets the draw order of this map polygon relative to other map polygons. Default value is 0.
- Returns:
The draw order of this map polygon relative to other map polygons.
-
setDrawOrder
public void setDrawOrder(int value)
Sets the draw order of this map polygon relative to other map polygons.
Polygon with higher draw order value are drawn on top of polygons with lower draw order.
In case multiple polygons have the same draw order value then the order in which they were added to the scene matters. Last added polygon is drawn on top.
Allowed range is 0-1023. Values outside this range will be clamped.
- Parameters:
value
-The draw order of this map polygon relative to other map polygons.
-
getVisibilityRanges
@NonNull public java.util.List<MapMeasureRange> getVisibilityRanges()
Gets the list of visibility ranges. The map polygon is visible only inside these map measure ranges. When empty (the default), the map polygon is visible without map measure restrictions.
- Returns:
The list of visibility ranges. The map polygon is visible only inside these map measure ranges.
-
setVisibilityRanges
public void setVisibilityRanges(@NonNull java.util.List<MapMeasureRange> value)
Sets visibility ranges for this map polygon. A range is half open - [minimumZoomLevel, maximumZoomLevel), the given maximum value is not contained in the range. The map polygon is visible only inside these map measure ranges.
When empty (the default), the map polygon is visible without map measure restrictions. Only
MapMeasureRange
(s) ofMapMeasure.Kind.ZOOM_LEVEL
type are supported.MapMeasureRange
(s) of other unsupported types will be ignored.- Parameters:
value
-The list of visibility ranges. The map polygon is visible only inside these map measure ranges.
-
getOutlineColor
@NonNull public Color getOutlineColor()
Gets the color of the polygon outline. The default outline color is opaque white.
- Returns:
The color of the polygon outline.
-
setOutlineColor
public void setOutlineColor(@NonNull Color value)
Sets the color of the polygon outline.
Transparent outlines are not supported. Any color with transparency (alpha value other than 1) will be rendered as fully opaque.
- Parameters:
value
-The color of the polygon outline.
-
getOutlineWidth
public double getOutlineWidth()
Gets the outline width of the polygon in pixels.
By default, the outline width is set to zero.
- Returns:
The width of the polygon outline in pixels.
-
setOutlineWidth
public void setOutlineWidth(double value)
Sets the outline width of the polygon in pixels.
The value should be greater than or equal to 0. Negative values are clamped to zero.
- Parameters:
value
-The width of the polygon outline in pixels.
-
-