Class PolygonFeature

All Implemented Interfaces:
FeatureClickNotifier<PolygonFeature>, Serializable

public class PolygonFeature extends Feature implements FeatureClickNotifier<PolygonFeature>
Polygon feature with predefined PolygonGeometry. Usage example:
 protected void addPolygons(VectorSource source) {
     GeometryFactory geometryFactory = GeometryUtils.getGeometryFactory();

     LinearRing shell = geometryFactory.createLinearRing(new Coordinate[]{
             new Coordinate(9.844944, 44.011077),
             new Coordinate(12.286243, 44.525239),
             new Coordinate(18.389491, 40.011935),
             new Coordinate(15.732783, 38.003544),
             new Coordinate(9.844944, 44.011077),
     });
     Polygon polygon = geometryFactory.createPolygon(shell);
     source.addFeature(new PolygonFeature(polygon));
 }
 
See Also:
  • Constructor Details

    • PolygonFeature

      public PolygonFeature(org.locationtech.jts.geom.Polygon polygon)
  • Method Details

    • getGeometry

      public PolygonGeometry getGeometry()
      Overrides:
      getGeometry in class Feature
      Returns:
      feature's geometry
    • getPolygon

      public org.locationtech.jts.geom.Polygon getPolygon()
      Returns:
      polygon from feature's geometry getGeometry()
    • setPolygon

      public void setPolygon(org.locationtech.jts.geom.Polygon polygon)
      Sets polygon to feature's geometry
      Parameters:
      polygon - polygon to set
    • addStyles

      public void addStyles(Style... styles)
      Adds style to the feature. Note, if the feature contains custom styles, the default styles or added ones to the layer won't be applied to this feature. And you have to provide fully described style to the specific feature.

      For instance, custom polygon style:

       new PolygonFeature(geometries.createPolygon(shell))
               .withStyles(new PolygonStyle()
                       .withFill(new Fill("rgba(1, 147, 154, 0.2)"))
                       .withStroke(new Stroke()
                               .withWidth(3.)
                               .withColor("#123EAB"))
                       .build());
       
      Overrides:
      addStyles in class Feature
      Parameters:
      styles - styles to add
    • withStyles

      public PolygonFeature withStyles(Style... styles)
      Overrides:
      withStyles in class Feature
      Parameters:
      styles - styles to add
      Returns:
      current instance
    • withProperties

      public PolygonFeature withProperties(Map<String,Object> properties)
      Description copied from class: Feature
      Sets the properties that will be associated with the feature.

      For instance, if cluster specified weight property it will try to get it from the feature's properties. The same with heatmap when it is specified its weight property.

      Another example of using feature's properties is listening click events in source. For instance:

       vectorSource.addSourceFeatureClickListener(event -> {
           Feature feature = event.getFeature();
           String description = (String) feature.getProperties().get("description");
           notifications.show(description);
       });
       
      Overrides:
      withProperties in class Feature
      Parameters:
      properties - properties to set
      Returns:
      current instance
    • withProperty

      public PolygonFeature withProperty(String name, Object value)
      Description copied from class: Feature
      Sets the property that will be associated with the feature.

      For instance, if cluster specified weight property it will try to get it from the feature's properties. The same with heatmap when it is specified its weight property.

      Another example of using feature's properties is listening click events in source. For instance:

       vectorSource.addSourceFeatureClickListener(event -> {
           Feature feature = event.getFeature();
           String description = (String) feature.getProperties().get("description");
           notifications.show(description);
       });
       
      Overrides:
      withProperty in class Feature
      Parameters:
      name - property name
      value - value
      Returns:
      current instance
    • addClickListener

      public com.vaadin.flow.shared.Registration addClickListener(Consumer<FeatureClickNotifier.FeatureClickEvent<PolygonFeature>> listener)
      Description copied from interface: FeatureClickNotifier
      Adds feature click listener. Note, if the user makes double click on a feature, the FeatureClickNotifier.FeatureClickEvent will be fired twice.
      Specified by:
      addClickListener in interface FeatureClickNotifier<PolygonFeature>
      Parameters:
      listener - listener to add
      Returns:
      a registration object for removing an event listener
    • addSingleClickListener

      public com.vaadin.flow.shared.Registration addSingleClickListener(Consumer<FeatureClickNotifier.FeatureSingleClickEvent<PolygonFeature>> listener)
      Description copied from interface: FeatureClickNotifier
      Adds feature single click listener. Single click means that an event won't be fired if the user makes double click.
      Specified by:
      addSingleClickListener in interface FeatureClickNotifier<PolygonFeature>
      Parameters:
      listener - listener to add
      Returns:
      a registration object for removing an event listener
    • addDoubleClickListener

      public com.vaadin.flow.shared.Registration addDoubleClickListener(Consumer<FeatureClickNotifier.FeatureDoubleClickEvent<PolygonFeature>> listener)
      Description copied from interface: FeatureClickNotifier
      Adds feature double click listener.
      Specified by:
      addDoubleClickListener in interface FeatureClickNotifier<PolygonFeature>
      Parameters:
      listener - listener to add
      Returns:
      a registration object for removing an event listener