public void selectRenderables(DrawContext dc, Sector vs) {
      // Select our renderables
      if (this.gridElements == null) createRenderables();

      boolean drawMetricLabels = getSizeInPixels(dc) > MIN_CELL_SIZE_PIXELS * 2;
      String graticuleType = getTypeFor((int) this.size);
      for (GridElement ge : this.gridElements) {
        if (ge.isInView(dc, vs)) {
          if (ge.type.equals(GridElement.TYPE_LINE_NORTH) && this.isNorthNeighborInView(dc))
            continue;
          if (ge.type.equals(GridElement.TYPE_LINE_EAST) && this.isEastNeighborInView(dc)) continue;

          if (drawMetricLabels)
            metricScaleSupport.computeMetricScaleExtremes(
                this.UTMZone, this.hemisphere, ge, this.size * 10);
          addRenderable(ge.renderable, graticuleType);
        }
      }

      if (getSizeInPixels(dc) <= MIN_CELL_SIZE_PIXELS * 2) return;

      // Select grid renderables
      if (this.squareGrid == null)
        this.squareGrid =
            new SquareGrid(
                this.UTMZone,
                this.hemisphere,
                this.UTMZoneSector,
                this.SWEasting,
                this.SWNorthing,
                this.size);
      if (this.squareGrid.isInView(dc)) {
        this.squareGrid.selectRenderables(dc, vs);
      } else this.squareGrid.clearRenderables();
    }
    public void selectRenderables(DrawContext dc, Sector vs) {
      // Select our renderables
      if (this.gridElements == null) createRenderables();

      int gridStep = (int) this.size / 10;
      boolean drawMetricLabels = getSizeInPixels(dc) > MIN_CELL_SIZE_PIXELS * 4 * 1.7;
      String graticuleType = getTypeFor(gridStep);

      for (GridElement ge : this.gridElements) {
        if (ge.isInView(dc, vs)) {
          if (drawMetricLabels)
            metricScaleSupport.computeMetricScaleExtremes(
                this.UTMZone, this.hemisphere, ge, this.size);

          addRenderable(ge.renderable, graticuleType);
        }
      }

      if (getSizeInPixels(dc) <= MIN_CELL_SIZE_PIXELS * 4 * 2) return;

      // Select sub grids renderables
      if (this.subGrids == null) createSubGrids();
      for (SquareGrid sg : this.subGrids) {
        if (sg.isInView(dc)) {
          sg.selectRenderables(dc, vs);
        } else sg.clearRenderables();
      }
    }
  /**
   * Select the visible grid elements
   *
   * @param dc the current <code>DrawContext</code>.
   */
  protected void selectRenderables(DrawContext dc) {
    if (dc == null) {
      String message = Logging.getMessage("nullValue.DrawContextIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }
    Sector vs = dc.getVisibleSector();
    OrbitView view = (OrbitView) dc.getView();
    // Compute labels offset from view center
    Position centerPos = view.getCenterPosition();
    Double pixelSizeDegrees =
        Angle.fromRadians(
                view.computePixelSizeAtDistance(view.getZoom())
                    / dc.getGlobe().getEquatorialRadius())
            .degrees;
    Double labelOffsetDegrees = pixelSizeDegrees * view.getViewport().getWidth() / 4;
    Position labelPos =
        Position.fromDegrees(
            centerPos.getLatitude().degrees - labelOffsetDegrees,
            centerPos.getLongitude().degrees - labelOffsetDegrees,
            0);
    Double labelLatDegrees = labelPos.getLatitude().normalizedLatitude().degrees;
    labelLatDegrees = Math.min(Math.max(labelLatDegrees, -76), 78);
    labelPos =
        new Position(
            Angle.fromDegrees(labelLatDegrees), labelPos.getLongitude().normalizedLongitude(), 0);

    if (vs != null) {
      for (GridElement ge : this.gridElements) {
        if (ge.isInView(dc)) {
          if (ge.renderable instanceof GeographicText) {
            GeographicText gt = (GeographicText) ge.renderable;
            if (labelPos.getLatitude().degrees < 72
                || "*32*34*36*".indexOf("*" + gt.getText() + "*") == -1) {
              // Adjust label position according to eye position
              Position pos = gt.getPosition();
              if (ge.type.equals(GridElement.TYPE_LATITUDE_LABEL))
                pos =
                    Position.fromDegrees(
                        pos.getLatitude().degrees,
                        labelPos.getLongitude().degrees,
                        pos.getElevation());
              else if (ge.type.equals(GridElement.TYPE_LONGITUDE_LABEL))
                pos =
                    Position.fromDegrees(
                        labelPos.getLatitude().degrees,
                        pos.getLongitude().degrees,
                        pos.getElevation());

              gt.setPosition(pos);
            }
          }

          this.graticuleSupport.addRenderable(ge.renderable, GRATICULE_UTM);
        }
      }
      // System.out.println("Total elements: " + count + " visible sector: " + vs);
    }
  }
    public void createRenderables() {
      this.gridElements = new ArrayList<GridElement>();
      double gridStep = this.size / 10;
      Position p1, p2;
      ArrayList<Position> positions = new ArrayList<Position>();

      // South-North lines
      for (int i = 1; i <= 9; i++) {
        double easting = this.SWEasting + gridStep * i;
        positions.clear();
        p1 = computePosition(this.UTMZone, this.hemisphere, easting, SWNorthing);
        p2 = computePosition(this.UTMZone, this.hemisphere, easting, SWNorthing + this.size);
        if (this.isTruncated) {
          computeTruncatedSegment(p1, p2, this.UTMZoneSector, positions);
        } else {
          positions.add(p1);
          positions.add(p2);
        }
        if (positions.size() > 0) {
          p1 = positions.get(0);
          p2 = positions.get(1);
          Object polyline = createLineRenderable(positions, Polyline.GREAT_CIRCLE);
          Sector lineSector = Sector.boundingSector(p1, p2);
          GridElement ge = new GridElement(lineSector, polyline, GridElement.TYPE_LINE_EASTING);
          ge.setValue(easting);
          this.gridElements.add(ge);
        }
      }
      // West-East lines
      for (int i = 1; i <= 9; i++) {
        double northing = this.SWNorthing + gridStep * i;
        positions.clear();
        p1 = computePosition(this.UTMZone, this.hemisphere, SWEasting, northing);
        p2 = computePosition(this.UTMZone, this.hemisphere, SWEasting + this.size, northing);
        if (this.isTruncated) {
          computeTruncatedSegment(p1, p2, this.UTMZoneSector, positions);
        } else {
          positions.add(p1);
          positions.add(p2);
        }
        if (positions.size() > 0) {
          p1 = positions.get(0);
          p2 = positions.get(1);
          Object polyline = createLineRenderable(positions, Polyline.GREAT_CIRCLE);
          Sector lineSector = Sector.boundingSector(p1, p2);
          GridElement ge = new GridElement(lineSector, polyline, GridElement.TYPE_LINE_NORTHING);
          ge.setValue(northing);
          this.gridElements.add(ge);
        }
      }
    }
    public void createRenderables() {
      this.gridElements = new ArrayList<GridElement>();

      ArrayList<Position> positions = new ArrayList<Position>();
      Position p1, p2;
      Object polyline;
      Sector lineSector;

      // left segment
      positions.clear();
      if (this.isTruncated) {
        computeTruncatedSegment(sw, nw, this.UTMZoneSector, positions);
      } else {
        positions.add(sw);
        positions.add(nw);
      }
      if (positions.size() > 0) {
        p1 = positions.get(0);
        p2 = positions.get(1);
        polyline = createLineRenderable(positions, Polyline.GREAT_CIRCLE);
        lineSector = Sector.boundingSector(p1, p2);
        GridElement ge = new GridElement(lineSector, polyline, GridElement.TYPE_LINE_WEST);
        ge.setValue(this.SWEasting);
        this.gridElements.add(ge);
      }

      // right segment
      positions.clear();
      if (this.isTruncated) {
        computeTruncatedSegment(se, ne, this.UTMZoneSector, positions);
      } else {
        positions.add(se);
        positions.add(ne);
      }
      if (positions.size() > 0) {
        p1 = positions.get(0);
        p2 = positions.get(1);
        polyline = createLineRenderable(positions, Polyline.GREAT_CIRCLE);
        lineSector = Sector.boundingSector(p1, p2);
        GridElement ge = new GridElement(lineSector, polyline, GridElement.TYPE_LINE_EAST);
        ge.setValue(this.SWEasting + this.size);
        this.gridElements.add(ge);
      }

      // bottom segment
      positions.clear();
      if (this.isTruncated) {
        computeTruncatedSegment(sw, se, this.UTMZoneSector, positions);
      } else {
        positions.add(sw);
        positions.add(se);
      }
      if (positions.size() > 0) {
        p1 = positions.get(0);
        p2 = positions.get(1);
        polyline = createLineRenderable(positions, Polyline.GREAT_CIRCLE);
        lineSector = Sector.boundingSector(p1, p2);
        GridElement ge = new GridElement(lineSector, polyline, GridElement.TYPE_LINE_SOUTH);
        ge.setValue(this.SWNorthing);
        this.gridElements.add(ge);
      }

      // top segment
      positions.clear();
      if (this.isTruncated) {
        computeTruncatedSegment(nw, ne, this.UTMZoneSector, positions);
      } else {
        positions.add(nw);
        positions.add(ne);
      }
      if (positions.size() > 0) {
        p1 = positions.get(0);
        p2 = positions.get(1);
        polyline = createLineRenderable(positions, Polyline.GREAT_CIRCLE);
        lineSector = Sector.boundingSector(p1, p2);
        GridElement ge = new GridElement(lineSector, polyline, GridElement.TYPE_LINE_NORTH);
        ge.setValue(this.SWNorthing + this.size);
        this.gridElements.add(ge);
      }

      // Label
      if (this.name != null) {
        // Only add a label to squares above some dimension
        if (this.boundingSector.getDeltaLon().degrees
                    * Math.cos(this.centroid.getLatitude().radians)
                > .2
            && this.boundingSector.getDeltaLat().degrees > .2) {
          LatLon labelPos = null;
          if (this.UTMZone != 0) // Not at poles
          {
            labelPos = this.centroid;
          } else if (this.isPositionInside(new Position(this.squareCenter, 0))) {
            labelPos = this.squareCenter;
          } else if (this.squareCenter.getLatitude().degrees
                  <= this.UTMZoneSector.getMaxLatitude().degrees
              && this.squareCenter.getLatitude().degrees
                  >= this.UTMZoneSector.getMinLatitude().degrees) {
            labelPos = this.centroid;
          }
          if (labelPos != null) {
            GeographicText text = new UserFacingText(this.name, new Position(labelPos, 0));
            text.setPriority(this.size * 10);
            this.gridElements.add(
                new GridElement(this.boundingSector, text, GridElement.TYPE_GRIDZONE_LABEL));
          }
        }
      }
    }