Пример #1
0
  private void layer(StringBuilder str, TileLayer layer, String baseurl) {
    str.append("  <Layer>\n");
    LayerMetaInformation layerMeta = layer.getMetaInformation();

    if (layerMeta == null) {
      appendTag(str, "    ", "ows:Title", layer.getName(), null);
    } else {
      appendTag(str, "    ", "ows:Title", layerMeta.getTitle(), null);
      appendTag(str, "    ", "ows:Abstract", layerMeta.getDescription(), null);
    }

    layerWGS84BoundingBox(str, layer);
    appendTag(str, "    ", "ows:Identifier", layer.getName(), null);

    // We need the filters for styles and dimensions
    List<ParameterFilter> filters = layer.getParameterFilters();

    layerStyles(str, layer, filters);

    layerFormats(str, layer);

    layerInfoFormats(str, layer);

    if (filters != null) {
      layerDimensions(str, layer, filters);
    }

    layerGridSubSets(str, layer);
    // TODO REST
    // str.append("    <ResourceURL format=\"image/png\" resourceType=\"tile\"
    // template=\"http://www.maps.cat/wmts/BlueMarbleNextGeneration/default/BigWorldPixel/{TileMatrix}/{TileRow}/{TileCol}.png\"/>\n");
    str.append("  </Layer>\n");
  }
Пример #2
0
  private void capabilityVendorSpecificTileset(
      StringBuilder str, TileLayer layer, GridSubset grid, String formatStr, String styleName)
      throws GeoWebCacheException {

    String srsStr = grid.getSRS().toString();
    StringBuilder resolutionsStr = new StringBuilder();
    double[] res = grid.getResolutions();
    for (int i = 0; i < res.length; i++) {
      resolutionsStr.append(Double.toString(res[i]) + " ");
    }

    String[] bs = boundsPrep(grid.getCoverageBestFitBounds());

    str.append("    <TileSet>\n");
    str.append("      <SRS>" + srsStr + "</SRS>\n");
    str.append(
        "      <BoundingBox SRS=\""
            + srsStr
            + "\" minx=\""
            + bs[0]
            + "\" miny=\""
            + bs[1]
            + "\"  maxx=\""
            + bs[2]
            + "\"  maxy=\""
            + bs[3]
            + "\" />\n");
    str.append("      <Resolutions>" + resolutionsStr.toString() + "</Resolutions>\n");
    str.append("      <Width>" + grid.getTileWidth() + "</Width>\n");
    str.append("      <Height>" + grid.getTileHeight() + "</Height>\n");
    str.append("      <Format>" + formatStr + "</Format>\n");
    str.append("      <Layers>" + layer.getName() + "</Layers>\n");
    str.append("      <Styles>").append(ServletUtils.URLEncode(styleName)).append("</Styles>\n");
    str.append("    </TileSet>\n");
  }
  private void vendorSpecificTileset(
      final Translator tx, final TileLayer layer, final GridSubset grid, final String format) {

    String srsStr = grid.getSRS().toString();
    StringBuilder resolutionsStr = new StringBuilder();
    double[] res = grid.getResolutions();
    for (int i = 0; i < res.length; i++) {
      resolutionsStr.append(Double.toString(res[i]) + " ");
    }

    String[] bs = boundsPrep(grid.getCoverageBestFitBounds());

    tx.start("TileSet");

    tx.start("SRS");
    tx.chars(srsStr);
    tx.end("SRS");

    AttributesImpl atts;
    atts = new AttributesImpl();
    atts.addAttribute("", "SRS", "SRS", "", srsStr);
    atts.addAttribute("", "minx", "minx", "", bs[0]);
    atts.addAttribute("", "miny", "miny", "", bs[1]);
    atts.addAttribute("", "maxx", "maxx", "", bs[2]);
    atts.addAttribute("", "maxy", "maxy", "", bs[3]);

    tx.start("BoundingBox", atts);
    tx.end("BoundingBox");

    tx.start("Resolutions");
    tx.chars(resolutionsStr.toString());
    tx.end("Resolutions");

    tx.start("Width");
    tx.chars(String.valueOf(grid.getTileWidth()));
    tx.end("Width");

    tx.start("Height");
    tx.chars(String.valueOf(grid.getTileHeight()));
    tx.end("Height");

    tx.start("Format");
    tx.chars(format);
    tx.end("Format");

    tx.start("Layers");
    tx.chars(layer.getName());
    tx.end("Layers");

    // TODO ignoring styles for now
    tx.start("Styles");
    tx.end("Styles");

    tx.end("TileSet");
  }
Пример #4
0
  private void capabilityLayerInner(StringBuilder str, TileLayer layer)
      throws GeoWebCacheException {
    if (layer.isQueryable()) {
      str.append("    <Layer queryable=\"1\">\n");
    } else {
      str.append("    <Layer>\n");
    }

    str.append("      <Name>" + layer.getName() + "</Name>\n");

    if (layer.getMetaInformation() != null) {
      LayerMetaInformation metaInfo = layer.getMetaInformation();
      str.append("      <Title>" + metaInfo.getTitle() + "</Title>\n");
      str.append("      <Abstract>" + metaInfo.getDescription() + "</Abstract>\n");
    } else {
      str.append("      <Title>" + layer.getName() + "</Title>\n");
    }

    TreeSet<SRS> srsSet = new TreeSet<SRS>();
    StringBuilder boundingBoxStr = new StringBuilder();
    for (String gridSetId : layer.getGridSubsets()) {
      GridSubset curGridSubSet = layer.getGridSubset(gridSetId);
      SRS curSRS = curGridSubSet.getSRS();
      if (!srsSet.contains(curSRS)) {
        str.append("      <SRS>" + curSRS.toString() + "</SRS>\n");

        // Save bounding boxes for later
        String[] bs = boundsPrep(curGridSubSet.getCoverageBestFitBounds());
        boundingBoxStr.append(
            "      <BoundingBox SRS=\""
                + curGridSubSet.getSRS().toString()
                + "\" minx=\""
                + bs[0]
                + "\" miny=\""
                + bs[1]
                + "\" maxx=\""
                + bs[2]
                + "\" maxy=\""
                + bs[3]
                + "\"/>\n");

        srsSet.add(curSRS);
      }
    }

    GridSubset epsg4326GridSubSet = layer.getGridSubsetForSRS(SRS.getEPSG4326());
    if (null != epsg4326GridSubSet) {
      String[] bs = boundsPrep(epsg4326GridSubSet.getCoverageBestFitBounds());
      str.append(
          "      <LatLonBoundingBox minx=\""
              + bs[0]
              + "\" miny=\""
              + bs[1]
              + "\" maxx=\""
              + bs[2]
              + "\" maxy=\""
              + bs[3]
              + "\"/>\n");
    }

    // Bounding boxes gathered earlier
    str.append(boundingBoxStr);

    // WMS 1.1 Dimensions
    if (layer.getParameterFilters() != null) {
      StringBuilder dims = new StringBuilder();
      StringBuilder extents = new StringBuilder();
      for (ParameterFilter parameterFilter : layer.getParameterFilters()) {
        if (parameterFilter instanceof WMSDimensionProvider) {
          ((WMSDimensionProvider) parameterFilter).appendDimensionElement(dims, "      ");
          ((WMSDimensionProvider) parameterFilter).appendExtentElement(extents, "      ");
        }
      }

      if (dims.length() > 0 && extents.length() > 0) {
        str.append(dims);
        str.append(extents);
      }
    }

    // TODO style?
    str.append("    </Layer>\n");
  }
Пример #5
0
  private static String generateHTML(
      TileLayer layer, String gridSetStr, String formatStr, boolean asPlugin)
      throws GeoWebCacheException {
    String layerName = layer.getName();

    GridSubset gridSubset = layer.getGridSubset(gridSetStr);

    BoundingBox bbox = gridSubset.getGridSetBounds();
    BoundingBox zoomBounds = gridSubset.getOriginalExtent();

    String res = "resolutions: " + Arrays.toString(gridSubset.getResolutions()) + ",\n";

    String units = "units: \"" + gridSubset.getGridSet().guessMapUnits() + "\",\n";

    String openLayersPath;
    if (asPlugin) {
      openLayersPath = "../openlayers/OpenLayers.js";
    } else {
      openLayersPath = "../openlayers/OpenLayers.js";
    }

    String page =
        "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head>\n"
            + "<meta http-equiv=\"imagetoolbar\" content=\"no\">\n"
            + "<title>"
            + layerName
            + " "
            + gridSubset.getName()
            + " "
            + formatStr
            + "</title>\n"
            + "<style type=\"text/css\">\n"
            + "body { font-family: sans-serif; font-weight: bold; font-size: .8em; }\n"
            + "body { border: 0px; margin: 0px; padding: 0px; }\n"
            + "#map { width: 85%; height: 85%; border: 0px; padding: 0px; }\n"
            + "</style>\n"
            + "<script src=\""
            + openLayersPath
            + "\"></script>    \n"
            + "<script type=\"text/javascript\">               \n"
            + "var map, demolayer;                               \n"
            + "  // sets the chosen modifiable parameter        \n"
            + "  function setParam(name, value){                \n"
            + "   str = \"demolayer.mergeNewParams({\" + name + \": '\" + value + \"'})\" \n"
            + "   // alert(str);                                   \n"
            + "   eval(str);                                    \n"
            + "  }                                              \n"
            + "OpenLayers.DOTS_PER_INCH = "
            + gridSubset.getDotsPerInch()
            + ";\n"
            + "OpenLayers.Util.onImageLoadErrorColor = 'transparent';\n"
            + "function init(){\n"
            + "var mapOptions = { \n"
            + res
            + "projection: new OpenLayers.Projection('"
            + gridSubset.getSRS().toString()
            + "'),\n"
            + "maxExtent: new OpenLayers.Bounds("
            + bbox.toString()
            + "),\n"
            + units
            + "controls: []\n"
            + "};\n"
            + "map = new OpenLayers.Map('map', mapOptions );\n"
            + "map.addControl(new OpenLayers.Control.PanZoomBar({\n"
            + "		position: new OpenLayers.Pixel(2, 15)\n"
            + "}));\n"
            + "map.addControl(new OpenLayers.Control.Navigation());\n"
            + "map.addControl(new OpenLayers.Control.Scale($('scale')));\n"
            + "map.addControl(new OpenLayers.Control.MousePosition({element: $('location')}));\n"
            + "demolayer = new OpenLayers.Layer.WMS(\n"
            + "\""
            + layerName
            + "\",\"../service/wms\",\n"
            + "{layers: '"
            + layerName
            + "', format: '"
            + formatStr
            + "' },\n"
            + "{ tileSize: new OpenLayers.Size("
            + gridSubset.getTileWidth()
            + ","
            + gridSubset.getTileHeight()
            + ")";

    /*
     * If the gridset has a top left tile origin, lets tell that to open layers. Otherwise it'll
     * calculate tile bounds based on the bbox bottom left corner, leading to misaligned
     * requests.
     */
    GridSet gridSet = gridSubset.getGridSet();
    if (gridSet.isTopLeftAligned()) {
      page +=
          ",\n tileOrigin: new OpenLayers.LonLat(" + bbox.getMinX() + ", " + bbox.getMaxY() + ")";
    }

    page +=
        "});\n"
            + "map.addLayer(demolayer);\n"
            + "map.zoomToExtent(new OpenLayers.Bounds("
            + zoomBounds.toString()
            + "));\n"
            + "// The following is just for GetFeatureInfo, which is not cached. Most people do not need this \n"
            + "map.events.register('click', map, function (e) {\n"
            + "  document.getElementById('nodelist').innerHTML = \"Loading... please wait...\";\n"
            + "  var params = {\n"
            + "    REQUEST: \"GetFeatureInfo\",\n"
            + "    EXCEPTIONS: \"application/vnd.ogc.se_xml\",\n"
            + "    BBOX: map.getExtent().toBBOX(),\n"
            + "    X: e.xy.x,\n"
            + "    Y: e.xy.y,\n"
            + "    INFO_FORMAT: 'text/html',\n"
            + "    QUERY_LAYERS: map.layers[0].params.LAYERS,\n"
            + "    FEATURE_COUNT: 50,\n"
            + "    Layers: '"
            + layerName
            + "',\n"
            + "    Styles: '',\n"
            + "    Srs: '"
            + gridSubset.getSRS().toString()
            + "',\n"
            + "    WIDTH: map.size.w,\n"
            + "    HEIGHT: map.size.h,\n"
            + "    format: \""
            + formatStr
            + "\" };\n"
            + "  OpenLayers.loadURL(\"../service/wms\", params, this, setHTML, setHTML);\n"
            + "  OpenLayers.Event.stop(e);\n"
            + "  });\n"
            + "}\n"
            + "function setHTML(response){\n"
            + "    document.getElementById('nodelist').innerHTML = response.responseText;\n"
            + "};\n"
            + "</script>\n"
            + "</head>\n"
            + "<body onload=\"init()\">\n"
            + "<div id=\"params\">"
            + makeModifiableParameters(layer)
            + "</div>\n"
            + "<div id=\"map\"></div>\n"
            + "<div id=\"nodelist\"></div>\n"
            + "</body>\n"
            + "</html>";
    return page;
  }
Пример #6
0
  private static String tableRows(
      TileLayerDispatcher tileLayerDispatcher, GridSetBroker gridSetBroker)
      throws GeoWebCacheException {
    StringBuffer buf = new StringBuffer();

    Set<String> layerList = new TreeSet<String>(tileLayerDispatcher.getLayerNames());
    for (String layerName : layerList) {
      TileLayer layer = tileLayerDispatcher.getTileLayer(layerName);
      buf.append(
          "<tr><td style=\"min-width: 100px;\"><strong>" + layer.getName() + "</strong><br />\n");
      buf.append("<a href=\"rest/seed/" + layer.getName() + "\">Seed this layer</a>\n");
      buf.append("</td><td>" + layer.isEnabled() + "</td>");
      buf.append("<td><table width=\"100%\">");

      int count = 0;
      for (String gridSetId : layer.getGridSubsets()) {
        GridSubset gridSubset = layer.getGridSubset(gridSetId);
        String gridSetName = gridSubset.getName();
        if (gridSetName.length() > 20) {
          gridSetName = gridSetName.substring(0, 20) + "...";
        }
        buf.append("<tr><td style=\"width: 170px;\">").append(gridSetName);

        buf.append("</td><td>OpenLayers: [");
        Iterator<MimeType> mimeIter = layer.getMimeTypes().iterator();
        boolean prependComma = false;
        while (mimeIter.hasNext()) {
          MimeType mime = mimeIter.next();
          if (mime instanceof ImageMime) {
            if (prependComma) {
              buf.append(", ");
            } else {
              prependComma = true;
            }
            buf.append(generateDemoUrl(layer.getName(), gridSubset.getName(), (ImageMime) mime));
          }
        }
        buf.append("]</td><td>\n");

        if (gridSubset.getName().equals(gridSetBroker.WORLD_EPSG4326.getName())) {
          buf.append(" &nbsp; KML: [");
          String prefix = "";
          prependComma = false;
          Iterator<MimeType> kmlIter = layer.getMimeTypes().iterator();
          while (kmlIter.hasNext()) {
            MimeType mime = kmlIter.next();
            if (mime instanceof ImageMime || mime == XMLMime.kml) {
              if (prependComma) {
                buf.append(", ");
              } else {
                prependComma = true;
              }
              buf.append(
                  "<a href=\""
                      + prefix
                      + "service/kml/"
                      + layer.getName()
                      + "."
                      + mime.getFileExtension()
                      + ".kml\">"
                      + mime.getFileExtension()
                      + "</a>");
            } else if (mime == XMLMime.kmz) {
              if (prependComma) {
                buf.append(", ");
              } else {
                prependComma = true;
              }
              buf.append(
                  "<a href=\"" + prefix + "service/kml/" + layer.getName() + ".kml.kmz\">kmz</a>");
            }
          }
          buf.append("]");
        } else {
          // No Google Earth support
        }
        buf.append("</td></tr>");
        count++;
      }

      // if(count == 0) {
      // buf.append("<tr><td colspan=\"2\"><i>None</i></td></tr>\n");
      // }

      buf.append("</table></td>\n");
      buf.append("</tr>\n");
    }

    return buf.toString();
  }
Пример #7
0
  protected void renderCanvas() throws OutsideCoverageException, GeoWebCacheException, IOException {
    // Now we loop over all the relevant tiles and write them to the canvas,
    // Starting at the bottom, moving to the right and up

    // Bottom row of tiles, in tile coordinates
    long starty = srcRectangle[1];

    // gridy is the tile row index
    for (long gridy = starty; gridy <= srcRectangle[3]; gridy++) {

      int tiley = 0;
      int canvasy = (int) (srcRectangle[3] - gridy) * gridSubset.getTileHeight();
      int tileHeight = gridSubset.getTileHeight();

      if (canvOfs.top > 0) {
        // Add padding
        canvasy += canvOfs.top;
      } else {
        // Top tile is cut off
        if (gridy == srcRectangle[3]) {
          // This one starts at the top, so canvasy remains 0
          tileHeight = tileHeight + canvOfs.top;
          tiley = -canvOfs.top;
        } else {
          // Offset that the first tile contributed,
          // rather, we subtract what it did not contribute
          canvasy += canvOfs.top;
        }
      }

      if (gridy == srcRectangle[1] && canvOfs.bottom < 0) {
        // Check whether we only use part of the first tiles (bottom row)
        // Offset is negative, slice the bottom off the tile
        tileHeight += canvOfs.bottom;
      }

      long startx = srcRectangle[0];
      for (long gridx = startx; gridx <= srcRectangle[2]; gridx++) {

        long[] gridLoc = {gridx, gridy, srcIdx};

        ConveyorTile tile =
            new ConveyorTile(
                sb,
                layer.getName(),
                gridSubset.getName(),
                gridLoc,
                ImageMime.png,
                fullParameters,
                null,
                null);

        // Check whether this tile is to be rendered at all
        try {
          layer.applyRequestFilters(tile);
        } catch (RequestFilterException e) {
          log.debug(e.getMessage());
          continue;
        }

        layer.getTile(tile);

        BufferedImage tileImg = ImageIO.read(tile.getBlob().getInputStream());

        int tilex = 0;
        int canvasx = (int) (gridx - startx) * gridSubset.getTileWidth();
        int tileWidth = gridSubset.getTileWidth();

        if (canvOfs.left > 0) {
          // Add padding
          canvasx += canvOfs.left;
        } else {
          // Leftmost tile is cut off
          if (gridx == srcRectangle[0]) {
            // This one starts to the left top, so canvasx remains 0
            tileWidth = tileWidth + canvOfs.left;
            tilex = -canvOfs.left;
          } else {
            // Offset that the first tile contributed,
            // rather, we subtract what it did not contribute
            canvasx += canvOfs.left;
          }
        }

        if (gridx == srcRectangle[2] && canvOfs.right < 0) {
          // Check whether we only use part of the first tiles (bottom row)
          // Offset is negative, slice the bottom off the tile
          tileWidth = tileWidth + canvOfs.right;
        }

        // TODO We should really ensure we can never get here
        if (tileWidth == 0 || tileHeight == 0) {
          log.debug("tileWidth: " + tileWidth + " tileHeight: " + tileHeight);
          continue;
        }

        // Cut down the tile to the part we want
        if (tileWidth != gridSubset.getTileWidth() || tileHeight != gridSubset.getTileHeight()) {
          log.debug(
              "tileImg.getSubimage("
                  + tilex
                  + ","
                  + tiley
                  + ","
                  + tileWidth
                  + ","
                  + tileHeight
                  + ")");
          tileImg = tileImg.getSubimage(tilex, tiley, tileWidth, tileHeight);
        }

        // Render the tile on the big canvas
        log.debug(
            "drawImage(subtile," + canvasx + "," + canvasy + ",null) " + Arrays.toString(gridLoc));
        gfx.drawImage(tileImg, canvasx, canvasy, null); // imageObserver
      }
    }

    gfx.dispose();
  }