예제 #1
0
  /**
   * Prepares the graphics for the layer. This is where the getRectangle() method call is made on
   * the dted.
   *
   * <p>Occasionally it is necessary to abort a prepare call. When this happens, the map will set
   * the cancel bit in the LayerThread, (the thread that is running the prepare). If this Layer
   * needs to do any cleanups during the abort, it should do so, but return out of the prepare asap.
   */
  public synchronized OMGraphicList prepare() {

    if (isCancelled()) {
      Debug.message("dted", getName() + "|DTEDLayer.prepare(): aborted.");
      return null;
    }

    Projection projection = getProjection();

    if (projection == null) {
      Debug.error("DTED Layer needs to be added to the MapBean before it can draw images!");
      return new OMGraphicList();
    }

    DTEDCacheManager cache = getCache();

    if (!(projection instanceof EqualArc)) {
      // fireRequestInfoLine("DTED works faster with an Equal Arc projection (CADRG/LLXY).");
    }

    Debug.message("basic", getName() + "|DTEDLayer.prepare(): doing it");

    // Setting the OMGraphicsList for this layer. Remember, the
    // OMGraphicList is made up of OMGraphics, which are generated
    // (projected) when the graphics are added to the list. So,
    // after this call, the list is ready for painting.

    // call getRectangle();
    if (Debug.debugging("dted")) {
      Debug.output(
          getName()
              + "|DTEDLayer.prepare(): "
              + "calling getRectangle "
              + " with projection: "
              + projection
              + " ul = "
              + projection.getUpperLeft()
              + " lr = "
              + projection.getLowerRight());
    }

    OMGraphicList omGraphicList;

    if (projection.getScale() < maxScale) {
      omGraphicList = cache.getRectangle(projection);
    } else {
      fireRequestInfoLine("  The scale is too small for DTED viewing.");
      Debug.error(
          "DTEDLayer: scale (1:"
              + projection.getScale()
              + ") is smaller than minimum (1:"
              + maxScale
              + ") allowed.");
      omGraphicList = new OMGraphicList();
    }
    // ///////////////////
    // safe quit
    int size = 0;
    if (omGraphicList != null) {
      size = omGraphicList.size();
      Debug.message(
          "basic", getName() + "|DTEDLayer.prepare(): finished with " + size + " graphics");

      // // Don't forget to project them. Since they are only
      // // being recalled if the projection has changed, then we
      // // need to force a reprojection of all of them because the
      // // screen position has changed.
      // omGraphicList.project(projection, true);

    } else {
      Debug.message("basic", getName() + "|DTEDLayer.prepare(): finished with null graphics list");
    }

    return omGraphicList;
  }
예제 #2
0
  /** Create the query to be sent to the server, based on current settings. */
  public String createQueryString(Projection p) {

    if (queryHeader == null) {
      return null;
    }

    String bbox = "undefined";
    String height = "undefined";
    String width = "undefined";

    String sCoordParamName = WMTConstants.SRS;

    if (p != null) {
      Point2D ul = p.getUpperLeft();
      Point2D lr = p.getLowerRight();

      if (wmsVersion.compareTo("1.3.0") == 0) {
        bbox =
            Double.toString(lr.getY())
                + ","
                + Double.toString(ul.getX())
                + ","
                + Double.toString(ul.getY())
                + ","
                + Double.toString(lr.getX());
        sCoordParamName = WMTConstants.CRS;
        errorHandling = "INIMAGE";
      } else {
        bbox =
            Double.toString(ul.getX())
                + ","
                + Double.toString(lr.getY())
                + ","
                + Double.toString(lr.getX())
                + ","
                + Double.toString(ul.getY());
      }

      height = Integer.toString(p.getHeight());
      width = Integer.toString(p.getWidth());
    }

    StringBuffer buf = new StringBuffer(queryHeader);
    buf.append("?")
        .append(WMTConstants.VERSION)
        .append("=")
        .append(wmsVersion)
        .append("&")
        .append(WMTConstants.REQUEST)
        .append("=")
        .append(mapRequestName)
        .append("&")
        .append(sCoordParamName)
        .append("=")
        .append("EPSG:4326")
        .append("&")
        .append(WMTConstants.BBOX)
        .append("=")
        .append(bbox)
        .append("&")
        .append(WMTConstants.HEIGHT)
        .append("=")
        .append(height)
        .append("&")
        .append(WMTConstants.WIDTH)
        .append("=")
        .append(width)
        .append("&")
        .append(WMTConstants.EXCEPTIONS)
        .append("=")
        .append(errorHandling);

    if (imageFormat != null) {
      buf.append("&").append(WMTConstants.FORMAT).append("=").append(imageFormat);

      String baseImageFormat = imageFormat;
      if (baseImageFormat.indexOf('/') > 0)
        baseImageFormat = baseImageFormat.substring(baseImageFormat.indexOf('/'));
      if (baseImageFormat.equals(WMTConstants.IMAGEFORMAT_JPEG)) {
        buf.append("&quality=").append(imageQuality);
      }
    }

    if (transparent != null) {
      buf.append("&").append(WMTConstants.TRANSPARENT).append("=").append(transparent);
    }

    if (backgroundColor != null) {
      buf.append("&").append(WMTConstants.BGCOLOR).append("=").append(backgroundColor);
    }

    if (layers != null) {
      buf.append("&").append(WMTConstants.LAYERS).append("=").append(layers);
    }

    String cStyles = styles;
    if (cStyles == null) {
      cStyles = "";
    }

    // if (styles != null) {
    buf.append("&").append(WMTConstants.STYLES).append("=").append(cStyles);
    // }

    if (Debug.debugging("wms")) {
      Debug.output("query string: " + buf);
    }

    /*
     * Included to allow for one or more vendor specific parameters to be
     * specified such as ESRI's ArcIMS's "ServiceName" parameter.
     */
    if (vendorSpecificNames != null) {
      if (vendorSpecificValues != null) {
        StringTokenizer nameTokenizer = new StringTokenizer(vendorSpecificNames, ",");
        StringTokenizer valueTokenizer = new StringTokenizer(vendorSpecificValues, ",");
        String paramName = null;
        String paramValue = null;
        while (nameTokenizer.hasMoreTokens()) {
          try {
            paramName = nameTokenizer.nextToken();
            paramValue = valueTokenizer.nextToken();
            buf.append("&").append(paramName).append("=").append(paramValue);
          } catch (NoSuchElementException e) {
            if (Debug.debugging("wms")) {
              Debug.output(
                  "WMSPlugIn.getRectangle(): " + "parameter \"" + paramName + "\" has no value");
            }
          }
        }
      }
    }
    return buf.toString();
  }
예제 #3
0
  public void actionPerformed(ActionEvent ae) {
    Debug.message("saveimage", "SaveAsImageMenuItem: actionPerformed");

    if (mapHandler == null) {
      Debug.output("SaveAsImageMenuItem: mapHandler = null, returning");
      return;
    }

    MapBean mb = (MapBean) mapHandler.get("com.bbn.openmap.MapBean");

    if (mb != null) {
      Debug.message("saveimage", "MapBean found, creating image");
      try {

        while (true) {
          SaveAsImageFileChooser chooser =
              new SaveAsImageFileChooser(mb.getWidth(), mb.getHeight());

          int returnVal = chooser.showSaveDialog(getParent());
          if (returnVal == JFileChooser.APPROVE_OPTION) {
            String filename = chooser.getSelectedFile().getAbsolutePath();
            if (formatter == null) {
              break;
            }

            filename = checkFileName(filename, formatter.getFormatLabel().toLowerCase());
            if (filename == null) {
              // This is the reason for the while
              // loop, the name didn't really pass
              // muster, so we'll try again.
              continue;
            }

            int imageHeight = chooser.getImageHeight();
            int imageWidth = chooser.getImageWidth();

            byte[] imageBytes = formatter.getImageFromMapBean(mb, imageWidth, imageHeight);
            FileOutputStream binFile = new FileOutputStream(filename);
            binFile.write(imageBytes);
            binFile.close();
            if (Debug.debugging("saveimage")) {
              com.bbn.openmap.proj.Projection proj = mb.getProjection();
              Debug.output(
                  "Created image at "
                      + filename
                      + "where projection covers "
                      + proj.getUpperLeft()
                      + " to "
                      + proj.getLowerRight());
            }
            break;
          } else if (returnVal == JFileChooser.CANCEL_OPTION) {
            break;
          }
        }
      } catch (IOException e) {
        Debug.error("SaveAsImageMenuItem: " + e);
      }
    }
    return;
  }