Features and Geometries

Features

Feature refers to a basic building block that represents some element on a map. Features can include points, lines, polygons, or other geometries that provide spatial information on the map.

Features can be styled, clicked on for interaction. They play a central role in creating dynamic and interactive maps by allowing developers to represent and manipulate geographic data efficiently.

GeoMap supports the following features:

MarkerFeature

Marker feature represents a marker element with predefined PointGeometry. It is displayed with marker icon in a map component.

The following example demonstrates how to create and place a marker on a map:

@ViewComponent("geoMap.vector.vectorSource")
private VectorSource vectorSource;

@Subscribe
public void onInit(final InitEvent event) {
    vectorSource.addFeature(new MarkerFeature
            (GeometryUtils.createPoint(40, 40)));
}

PointFeature

Point feature represents a point with predefined PointGeometry. It is displayed as a point with default style. For more details see Feature documentation.

The following example demonstrates how to create and place a point on a map:

@ViewComponent("geoMap.vector.vectorSource")
private VectorSource vectorSource;

@Subscribe
public void onInit(final InitEvent event) {
    vectorSource.addFeature(new PointFeature
            (GeometryUtils.createPoint(13.046446, 47.797916)));
}

LineStringFeature

LineStringFeature represents a linear feature on a map, typically drawn as a polyline connecting multiple points. The polyline feature comes with a predefined LineStringGeometry. For more details see Feature documentation.

The following example demonstrates how to create and place a polyline on a map:

private final GeometryFactory geometries = GeometryUtils.getGeometryFactory();

@ViewComponent("geoMap.vector.vectorSource")
private VectorSource vectorSource;

@Subscribe
public void onInit(final InitEvent event) {
    vectorSource.addFeature(new LineStringFeature
            (geometries.createLineString(new Coordinate[]{
                    new Coordinate(13, 20),
                    new Coordinate(13, 32),
                    new Coordinate(25, 17)})));
}

PolygonFeature

PolygonFeature represents a closed geometric shape on a map that defines an area or region. This feature is used to display and work with polygons, which are defined by a collection of interconnected points forming a closed loop. The polygon feature comes with a predefined PolygonGeometry. For more details see Feature documentation.

The following example demonstrates how to create and place a polygon on a map:

private final GeometryFactory geometries = GeometryUtils.getGeometryFactory();

@ViewComponent("geoMap.vector.vectorSource")
private VectorSource vectorSource;

@Subscribe
public void onInit(final InitEvent event) {
    vectorSource.addFeature(new PolygonFeature
            (geometries.createPolygon
                    (geometries.createLinearRing(new Coordinate[]{
                            new Coordinate(1.2457020544488762, 42.476628901048684),
                            new Coordinate(-0.054875980233204155, 52.77260344863316),
                            new Coordinate(29.858418817454655, 46.105591288830624),
                            new Coordinate(1.2457020544488762, 42.476628901048684),
                    }))));
}

MultiMarkerFeature

Multi marker feature represents a collection of marker elements with predefined MultiPointGeometry. It is displayed with marker icons in a map component.

The following example demonstrates how to create and place MultiMarkerFeature on a map:

private final GeometryFactory geometries = GeometryUtils.getGeometryFactory();

@ViewComponent("geoMap.vectorLayer.vSource")
private VectorSource vSource;

@Subscribe
public void onInit(final InitEvent event) {
    MultiPoint multiMarkerPoint = geometries.createMultiPoint(new Point[]{
            GeometryUtils.createPoint(25.235641166883457, 39.917862345662456),
            GeometryUtils.createPoint(25.36806516981515, 37.08014053731078)});
    vSource.addFeature(new MultiMarkerFeature(multiMarkerPoint));
}

MultiPointFeature

Multipoint feature represents a multipoint with predefined MultiPointGeometry. It is displayed as points with default style. For more details see Feature documentation.

The following example demonstrates how to create and place a multipoint on a map:

private final GeometryFactory geometries = GeometryUtils.getGeometryFactory();

@ViewComponent("geoMap.vectorLayer.vSource")
private VectorSource vSource;

@Subscribe
public void onInit(final InitEvent event) {
    MultiPoint multiPoint = geometries.createMultiPoint(new Point[]{
            GeometryUtils.createPoint(2.348582286131592, 48.84306719072006),
            GeometryUtils.createPoint(-0.1503049900024013, 51.54906255948154)});
    vSource.addFeature(new MultiPointFeature(multiPoint));
}

MultiLineStringFeature

MultiLineStringFeature represents linear features on a map, typically drawn as a collection of multiple line strings. MultiLineStringFeature comes with a predefined MultiLineStringGeometry. For more details see Feature documentation.

The following example demonstrates how to create and place a multiline on a map:

private final GeometryFactory geometries = GeometryUtils.getGeometryFactory();

@ViewComponent("geoMap.vectorLayer.vSource")
private VectorSource vSource;

@Subscribe
public void onInit(final InitEvent event) {
    LineString lineString1 = geometries.createLineString(new Coordinate[]{
            new Coordinate(37.59610278959945, 55.75230701125054),
            new Coordinate(24.94409456852425, 60.18627418174103),
            new Coordinate(12.483009200616205, 41.87228189777008)});

    LineString lineString2 = geometries.createLineString(new Coordinate[]{
            new Coordinate(30.799901492251276, 36.89489780945887),
            new Coordinate(-3.71329777467964, 40.4106248584977)});

    MultiLineString multiLineString = geometries.createMultiLineString(
            new LineString[]{lineString1, lineString2});
    vSource.addFeature(new MultiLineStringFeature(multiLineString));
}

MultiPolygonFeature

MultiPolygonFeature represents a geometry consisting of multiple polygons grouped together. Each polygon within MultiPolygonFeature comprises a closed shape defined by a sequence of points, and comes with a predefined MultiPolygonGeometry. For more details see Feature documentation.

The following example demonstrates how to create and place MultiPolygonFeature on a map:

private final GeometryFactory geometries = GeometryUtils.getGeometryFactory();

@ViewComponent("geoMap.vectorLayer.vSource")
private VectorSource vSource;

@Subscribe
public void onInit(final InitEvent event) {
    Polygon polygon1 = geometries.createPolygon(
            geometries.createLinearRing(new Coordinate[]{
                    new Coordinate(25.095057034220535, 31.6734818426374),
                    new Coordinate(25.095057034220535, 21.916591864189783),
                    new Coordinate(36.273764258555126, 21.916591864189783),
                    new Coordinate(31.711026615969566, 30.893621948904325),
                    new Coordinate(25.095057034220535, 31.6734818426374)}));

    Polygon polygon2 = geometries.createPolygon(
            geometries.createLinearRing(new Coordinate[]{
                    new Coordinate(26.836428848759905, 40.89954566030514),
                    new Coordinate(26.836428848759905, 35.71188725771292),
                    new Coordinate(45.08737941910209, 36.265661479563505),
                    new Coordinate(43.49042124419716, 41.4148387201449),
                    new Coordinate(26.836428848759905, 40.89954566030514)}));

    MultiPolygon multiPolygon = geometries.createMultiPolygon(new Polygon[]
            {polygon1, polygon2});
    vSource.addFeature(new MultiPolygonFeature(multiPolygon));
}

Geometries

PointGeometry

PointGeometry is an object that contains org.locationtech.jts.geom.Point from the JTS library.

LineStringGeometry

LineStringGeometry is an object that contains org.locationtech.jts.geom.LineString from the JTS library.

PolygonGeometry

PolygonGeometry is an object that contains org.locationtech.jts.geom.Polygon from the JTS library.

MultiPointGeometry

MultiPointGeometry is an object that contains org.locationtech.jts.geom.MultiPoint from the JTS library.

MultiLineStringGeometry

MultiLineStringGeometry is an object that contains org.locationtech.jts.geom.MultiLineString from the JTS library.

MultiPolygonGeometry

MultiPolygonGeometry is an object that contains org.locationtech.jts.geom.MultiPolygon from the JTS library.