KNMapPolygon
INFO
This English reference is based on Directions SDK 1.12.8-hotfix02. For the latest version, see the Korean reference.
Creates a polygon to display on the map. You can configure its fill, outline, and line style. Polygon vertices use KATEC coordinates and must be specified in clockwise order. To add a polygon to the map, create a KNMapPolygon and register it with KNMapView. Use KNMapPolygon.addHole to add holes.
Constructor
Creates a KNMapPolygon from KATEC-coordinate vertices specified in clockwise order.
KNMapPolygon(points: List<FloatPoint>, fillColor: Int, strokeColor: Int, strokeWidth: Float, strokeDashType: KNLineDashType, priority: Int)TIP
A marker always has a higher priority than other objects such as circles and polygons. Therefore, even if the values overlap, the marker is displayed on the top layer.
Properties
| Name | Description | Type |
|---|---|---|
fillColor | Polygon fill color | var fillColor: Int |
strokeColor | Polygon outline color | var strokeColor: Int |
strokeWidth | Polygon outline width (default: 2, outline thickness setting range: 1~5) | var strokeWidth: Float |
strokeDashType | Polygon outline style: solid, dotted, dashed, dash-dotted, or dash-double-dotted. (default: KNLineDashType_Solid) | var strokeDashType: KNLineDashType |
priority | Polygon display priority. A higher number places it above polygons with lower priorities. (default: 0, priority setting range: 0~65535) | var priority: Int |
isVisible | Whether the polygon is visible (default: true) | var isVisible: Boolean |
tag | Tag assigned to the polygon. Tags are Int values that can categorize or distinguish polygons. (optional) | var tag: Int |
id (readOnly) | Unique polygon ID | var id: Int |
Example code — KNMapPolygon
fun createPolygonWithMapView(): KNMapPolygon {
val center = WGS84ToKATEC(127.11019081347423,37.3941851228957)
val pos = (KNSDK.sharedGpsManager()?.lastValidGpsData?.pos) ?: FloatPoint(321397.72f, 532790.94f)
val polygonVertex = arrayListOf<FloatPoint>()
polygonVertex.add(FloatPoint(pos.x - 100f, pos.y - 100f))
polygonVertex.add(FloatPoint(pos.x + 100f, pos.y - 100f))
polygonVertex.add(FloatPoint(pos.x + 100f, pos.y + 100f))
polygonVertex.add(FloatPoint(pos.x - 100f, pos.y + 100f))
return KNMapPolygon(polygonVertex,
fillColor = Color.BLUE,
strokeColor = Color.YELLOW,
strokeWidth = 3f,
strokeDashType = KNLineDashType.KNLineDashType_Dotted,
priority = 1)
}Methods
addHole
Adds holes to the polygon. Each hole is defined by a list of KATEC-coordinate vertices in clockwise order.
Example code — addHole
fun createPolygonHoleWithMapView(): KNMapPolygon {
val center = WGS84ToKATEC(127.11019081347423,37.3941851228957)
val pos = (KNSDK.sharedGpsManager()?.lastValidGpsData?.pos) ?: FloatPoint(321397.72f, 532790.94f)
val polygonVertex = arrayListOf()
polygonVertex.add(FloatPoint(pos.x - 100f, pos.y - 100f))
polygonVertex.add(FloatPoint(pos.x + 100f, pos.y - 100f))
polygonVertex.add(FloatPoint(pos.x + 100f, pos.y + 100f))
polygonVertex.add(FloatPoint(pos.x - 100f, pos.y + 100f))
return KNMapPolygon(polygonVertex,
fillColor = Color.BLUE,
strokeColor = Color.YELLOW,
strokeWidth = 3f,
strokeDashType = KNLineDashType.KNLineDashType_Dotted,
priority = 1).apply {
val holeVertex = arrayListOf()
holeVertex.add(FloatPoint(pos.x - 50f, pos.y - 50f))
holeVertex.add(FloatPoint(pos.x + 50f, pos.y - 50f))
holeVertex.add(FloatPoint(pos.x + 50f, pos.y + 50f))
holeVertex.add(FloatPoint(pos.x - 50f, pos.y + 50f))
addHole(mutableListOf(holeVertex))
}
}fun addHole( holePosition: MutableList<MutableList<FloatPoint>> )Parameters
| Name | Description |
|---|---|
holePosition | Vertex list of each hole |