/**
   * @param wfsClient
   * @throws NoSuchAuthorityCodeException
   * @throws FactoryException
   * @throws IOException
   * @throws IndexOutOfBoundsException
   * @throws ParseException
   */
  public OsmInspectorLayer(GeoFabrikWFSClient wfsClient, ProgressMonitor monitor)
      throws NoSuchAuthorityCodeException, FactoryException, IOException, IndexOutOfBoundsException,
          ParseException {
    super("OsmInspector");

    arrFeatures = new ArrayList<>();
    osmiBugInfo = new LinkedHashMap<>();
    selectGeomType = new ArrayList<>();

    // Step 3 - discovery; enhance to iterate over all types with bounds

    String typeNames[] = wfsClient.getTypeNames();
    renderer = new StreamingRenderer();
    CRS.decode(Main.getProjection().toCode());
    crsOSMI = CRS.decode("EPSG:4326");
    content = new MapContent(crsOSMI);

    selectGeomType.add(GeomType.POINT);
    for (int idx = 1; idx < typeNames.length; ++idx) {
      String typeName = typeNames[idx];
      Set<FeatureId> selectedFeatures = new HashSet<>();

      FeatureCollection<SimpleFeatureType, SimpleFeature> features =
          wfsClient.getFeatures(typeName, monitor);
      setGeometry(selectGeomType, typeName);

      Main.info("Osm Inspector Features size: " + features.size());
      Style style = createDefaultStyle(idx, selectedFeatures);

      OSMIFeatureTracker tracker = new OSMIFeatureTracker(features);
      arrFeatures.add(tracker);
      FeatureIterator<SimpleFeature> it = tracker.getFeatures().features();

      while (it.hasNext()) {
        BugInfo theInfo = new BugInfo(it.next(), osmiBugInfo.size());
        osmiBugInfo.put(theInfo, theInfo.bugId);
      }

      content.addLayer(new FeatureLayer(tracker.getFeatures(), style));
    }

    osmiIndex = new BugIndex(osmiBugInfo);
    content.setTitle("Osm Inspector Errors");
    renderer.setMapContent(content);
    bIsChanged = true;

    // finally initialize the dialog
    dialog = new OsmInspectorDialog(this);
    this.updateView();
  }
  /**
   * @param wfsClient
   * @throws NoSuchAuthorityCodeException
   * @throws FactoryException
   * @throws IOException
   * @throws ParseException
   * @throws NoSuchElementException
   * @throws IndexOutOfBoundsException
   */
  public void loadFeatures(GeoFabrikWFSClient wfsClient)
      throws NoSuchAuthorityCodeException, FactoryException, IOException, IndexOutOfBoundsException,
          NoSuchElementException, ParseException {
    String typeNames[] = wfsClient.getTypeNames();

    content.layers().clear();
    selectGeomType.clear();
    selectGeomType.add(GeomType.POINT);

    ProgressMonitor monitor = new ProgressMonitor(Main.map.mapView, "Loading features", "", 0, 100);

    for (int idx = 1; idx < typeNames.length; ++idx) {
      String typeName = typeNames[idx];
      Set<FeatureId> selectedFeatures = new HashSet<>();

      monitor.setProgress(100 / typeNames.length * idx);
      FeatureCollection<SimpleFeatureType, SimpleFeature> features =
          wfsClient.getFeatures(typeName, monitor);
      setGeometry(selectGeomType, typeName);

      Main.info("Osm Inspector Features size: " + features.size());

      OSMIFeatureTracker tracker = arrFeatures.get(idx - layerOffset);
      tracker.mergeFeatures(features);

      FeatureIterator<SimpleFeature> it = tracker.getFeatures().features();

      while (it.hasNext()) {
        BugInfo theInfo = new BugInfo(it.next(), osmiBugInfo.size());
        if (!osmiBugInfo.keySet().contains(theInfo)) {
          osmiBugInfo.put(theInfo, theInfo.bugId);
        }
      }

      Style style = createDefaultStyle(idx, selectedFeatures);
      content.addLayer(new FeatureLayer(tracker.getFeatures(), style));
    }

    osmiIndex.append(osmiBugInfo);

    monitor.setProgress(100);
    monitor.close();
    bIsChanged = true;
    // dialog.updateDialog(this);
    dialog.refreshModel();
    // dialog.updateNextPrevAction(this);

    this.updateView();
  }