@Override
  public Layer createLayer(LayerContext ctx, PropertySet configuration) {
    CoordinateReferenceSystem targetCrs = null;
    if (ctx != null) {
      targetCrs = (CoordinateReferenceSystem) ctx.getCoordinateReferenceSystem();
    }
    FeatureCollection<SimpleFeatureType, SimpleFeature> fc;
    fc =
        (FeatureCollection<SimpleFeatureType, SimpleFeature>)
            configuration.getValue(FeatureLayerType.PROPERTY_NAME_FEATURE_COLLECTION);
    if (fc == null) {
      try {
        final URL url =
            (URL) configuration.getValue(FeatureLayerType.PROPERTY_NAME_FEATURE_COLLECTION_URL);
        FeatureSource<SimpleFeatureType, SimpleFeature> featureSource =
            FeatureUtils.getFeatureSource(url);
        fc = featureSource.getFeatures();
      } catch (IOException e) {
        throw new IllegalArgumentException(e);
      }
    }
    final CoordinateReferenceSystem featureCrs =
        (CoordinateReferenceSystem)
            configuration.getValue(FeatureLayerType.PROPERTY_NAME_FEATURE_COLLECTION_CRS);
    final Geometry clipGeometry =
        (Geometry)
            configuration.getValue(FeatureLayerType.PROPERTY_NAME_FEATURE_COLLECTION_CLIP_GEOMETRY);

    fc =
        FeatureUtils.clipCollection(
            fc,
            featureCrs,
            clipGeometry,
            DefaultGeographicCRS.WGS84,
            null,
            targetCrs,
            ProgressMonitor.NULL);

    return new FeatureLayer(this, fc, configuration);
  }
  @Override
  public void actionPerformed(CommandEvent event) {
    JTextArea textArea = new JTextArea(16, 32);
    textArea.setEditable(true);

    JPanel contentPanel = new JPanel(new BorderLayout(4, 4));
    contentPanel.add(new JLabel("Geometry Well-Known-Text (WKT):"), BorderLayout.NORTH);
    contentPanel.add(new JScrollPane(textArea), BorderLayout.CENTER);

    VisatApp visatApp = VisatApp.getApp();
    ModalDialog modalDialog =
        new ModalDialog(visatApp.getApplicationWindow(), DLG_TITLE, ModalDialog.ID_OK_CANCEL, null);
    modalDialog.setContent(contentPanel);
    modalDialog.center();
    if (modalDialog.show() == ModalDialog.ID_OK) {
      String wellKnownText = textArea.getText();
      if (wellKnownText == null || wellKnownText.isEmpty()) {
        return;
      }
      ProductSceneView sceneView = visatApp.getSelectedProductSceneView();
      VectorDataLayer vectorDataLayer =
          InsertFigureInteractorInterceptor.getActiveVectorDataLayer(sceneView);
      if (vectorDataLayer == null) {
        return;
      }

      SimpleFeatureType wktFeatureType =
          PlainFeatureFactory.createDefaultFeatureType(DefaultGeographicCRS.WGS84);
      ListFeatureCollection newCollection = new ListFeatureCollection(wktFeatureType);
      SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(wktFeatureType);
      SimpleFeature wktFeature =
          featureBuilder.buildFeature("ID" + Long.toHexString(currentFeatureId++));
      Geometry geometry;
      try {
        geometry = new WKTReader().read(wellKnownText);
      } catch (ParseException e) {
        visatApp.handleError("Failed to convert WKT into geometry", e);
        return;
      }
      wktFeature.setDefaultGeometry(geometry);
      newCollection.add(wktFeature);

      FeatureCollection<SimpleFeatureType, SimpleFeature> productFeatures =
          FeatureUtils.clipFeatureCollectionToProductBounds(
              newCollection, sceneView.getProduct(), null, ProgressMonitor.NULL);
      if (productFeatures.isEmpty()) {
        visatApp.showErrorDialog(DLG_TITLE, "The geometry is not contained in the product.");
      } else {
        vectorDataLayer.getVectorDataNode().getFeatureCollection().addAll(productFeatures);
      }
    }
  }