private void adjustDateLineCrossingPoints() {
      ArrayList<LatLon> corners = new ArrayList<LatLon>(Arrays.asList(sw, se, nw, ne));
      if (!LatLon.locationsCrossDateLine(corners)) return;

      double lonSign = 0;
      for (LatLon corner : corners) {
        if (Math.abs(corner.getLongitude().degrees) != 180)
          lonSign = Math.signum(corner.getLongitude().degrees);
      }

      if (lonSign == 0) return;

      if (Math.abs(sw.getLongitude().degrees) == 180
          && Math.signum(sw.getLongitude().degrees) != lonSign)
        sw = new Position(sw.getLatitude(), sw.getLongitude().multiply(-1), sw.getElevation());
      if (Math.abs(se.getLongitude().degrees) == 180
          && Math.signum(se.getLongitude().degrees) != lonSign)
        se = new Position(se.getLatitude(), se.getLongitude().multiply(-1), se.getElevation());
      if (Math.abs(nw.getLongitude().degrees) == 180
          && Math.signum(nw.getLongitude().degrees) != lonSign)
        nw = new Position(nw.getLatitude(), nw.getLongitude().multiply(-1), nw.getElevation());
      if (Math.abs(ne.getLongitude().degrees) == 180
          && Math.signum(ne.getLongitude().degrees) != lonSign)
        ne = new Position(ne.getLatitude(), ne.getLongitude().multiply(-1), ne.getElevation());
    }
    public SquareSector(
        int UTMZone,
        String hemisphere,
        Sector UTMZoneSector,
        double SWEasting,
        double SWNorthing,
        double size) {
      this.UTMZone = UTMZone;
      this.hemisphere = hemisphere;
      this.UTMZoneSector = UTMZoneSector;
      this.SWEasting = SWEasting;
      this.SWNorthing = SWNorthing;
      this.size = size;

      // Compute corners positions
      this.sw = computePosition(this.UTMZone, this.hemisphere, SWEasting, SWNorthing);
      this.se = computePosition(this.UTMZone, this.hemisphere, SWEasting + size, SWNorthing);
      this.nw = computePosition(this.UTMZone, this.hemisphere, SWEasting, SWNorthing + size);
      this.ne = computePosition(this.UTMZone, this.hemisphere, SWEasting + size, SWNorthing + size);
      this.squareCenter =
          computePosition(
              this.UTMZone, this.hemisphere, SWEasting + size / 2, SWNorthing + size / 2);

      // Compute approximate bounding sector and center point
      if (this.sw != null && this.se != null && this.nw != null && this.ne != null) {
        adjustDateLineCrossingPoints();
        this.boundingSector = Sector.boundingSector(Arrays.asList(sw, se, nw, ne));
        if (!isInsideGridZone())
          this.boundingSector = this.UTMZoneSector.intersection(this.boundingSector);

        this.centroid =
            this.boundingSector != null ? this.boundingSector.getCentroid() : this.squareCenter;
        // this.squareCenter = this.boundingSector.getCentroid();
      }

      // Check whether this square is truncated by the grid zone boundary
      this.isTruncated = !isInsideGridZone();
    }
Ejemplo n.º 3
0
    public void actionPerformed(ActionEvent e) {
      if (!this.isEnabled()) {
        return;
      }

      if (NEW_AIRSPACE.equals(e.getActionCommand())) {
        this.createNewEntry(this.getView().getSelectedFactory());
      } else if (CLEAR_SELECTION.equals(e.getActionCommand())) {
        this.selectEntry(null, true);
      } else if (SIZE_NEW_SHAPES_TO_VIEWPORT.equals(e.getActionCommand())) {
        if (e.getSource() instanceof AbstractButton) {
          boolean selected = ((AbstractButton) e.getSource()).isSelected();
          this.setResizeNewShapesToViewport(selected);
        }
      } else if (ENABLE_EDIT.equals(e.getActionCommand())) {
        if (e.getSource() instanceof AbstractButton) {
          boolean selected = ((AbstractButton) e.getSource()).isSelected();
          this.setEnableEdit(selected);
        }
      } else if (OPEN.equals(e.getActionCommand())) {
        this.openFromFile();
      } else if (OPEN_URL.equals(e.getActionCommand())) {
        this.openFromURL();
      } else if (OPEN_DEMO_AIRSPACES.equals(e.getActionCommand())) {
        this.openFromPath(DEMO_AIRSPACES_PATH);
        this.zoomTo(
            LatLon.fromDegrees(47.6584074779224, -122.3059199579634),
            Angle.fromDegrees(-152),
            Angle.fromDegrees(75),
            750);
      } else if (REMOVE_SELECTED.equals(e.getActionCommand())) {
        this.removeEntries(Arrays.asList(this.getSelectedEntries()));
      } else if (SAVE.equals(e.getActionCommand())) {
        this.saveToFile();
      } else if (SELECTION_CHANGED.equals(e.getActionCommand())) {
        this.viewSelectionChanged();
      }
    }