Esempio n. 1
0
  /**
   * Creates the {@link RenderedImage} corresponding to the tile at index {@code tileIdx} and uses a
   * {@link RenderedImageMapResponse} to encode it into the {@link #getResponseFormat() response
   * format}.
   *
   * @see org.geowebcache.layer.MetaTile#writeTileToStream(int, org.geowebcache.io.Resource)
   * @see RenderedImageMapResponse#write
   */
  @Override
  public boolean writeTileToStream(final int tileIdx, Resource target) throws IOException {

    checkNotNull(metaTileMap, "webMap is not set");
    if (!(metaTileMap instanceof RenderedImageMap)) {
      throw new IllegalArgumentException(
          "Only RenderedImageMaps are supported so far: " + metaTileMap.getClass().getName());
    }
    final RenderedImageMapResponse mapEncoder;
    {
      final GWC mediator = GWC.get();
      final Response responseEncoder = mediator.getResponseEncoder(responseFormat, metaTileMap);
      mapEncoder = (RenderedImageMapResponse) responseEncoder;
    }

    RenderedImage tile = metaTileMap.getImage();
    WMSMapContent tileContext = metaTileMap.getMapContext();

    if (this.tiles.length > 1 || (this.tiles.length == 1 && metaHasGutter())) {
      final Rectangle tileDim = this.tiles[tileIdx];
      tile = createTile(tileDim.x, tileDim.y, tileDim.width, tileDim.height);
      disposeLater(tile);
      {
        final WMSMapContent metaTileContext = metaTileMap.getMapContext();
        // do not create tileContext with metaTileContext.getLayers() as the layer list.
        // It is not needed at this stage and the constructor would force a
        // MapLayer.getBounds() that might fail
        tileContext = new WMSMapContent();
        tileContext.setRequest(metaTileContext.getRequest());
        tileContext.setBgColor(metaTileContext.getBgColor());
        tileContext.setMapWidth(tileDim.width);
        tileContext.setMapHeight(tileDim.height);
        tileContext.setPalette(metaTileContext.getPalette());
        tileContext.setTransparent(tileContext.isTransparent());
        long[][] tileIndexes = getTilesGridPositions();
        BoundingBox tileBounds = gridSubset.boundsFromIndex(tileIndexes[tileIdx]);
        ReferencedEnvelope tilebbox =
            new ReferencedEnvelope(metaTileContext.getCoordinateReferenceSystem());
        tilebbox.init(
            tileBounds.getMinX(), tileBounds.getMaxX(), tileBounds.getMinY(), tileBounds.getMaxY());
        tileContext.getViewport().setBounds(tilebbox);
      }
    }

    OutputStream outStream = target.getOutputStream();
    try {
      // call formatImageOuputStream instead of write to avoid disposition of rendered images
      // when processing a tile from a metatile and instead defer it to this class' dispose()
      // method
      mapEncoder.formatImageOutputStream(tile, outStream, tileContext);
      return true;
    } finally {
      outStream.close();
    }
  }
Esempio n. 2
0
  WMSMapContent createMapContext(QName layer, String style) throws Exception {

    // create a map context
    WMSMapContent mapContent = new WMSMapContent();
    mapContent.addLayer(createMapLayer(layer, style));
    mapContent.setMapHeight(256);
    mapContent.setMapWidth(256);

    GetMapRequest getMapRequest = createGetMapRequest(new QName[] {layer});
    getMapRequest.setWidth(256);
    getMapRequest.setHeight(256);

    mapContent.setRequest(getMapRequest);
    mapContent
        .getViewport()
        .setBounds(new ReferencedEnvelope(-180, 180, -90, 90, DefaultGeographicCRS.WGS84));
    return mapContent;
  }
Esempio n. 3
0
  @Test
  public void testExternalImageSize() throws Exception {
    GetMapRequest req = createGetMapRequest(MockData.STREAMS);
    req.setWidth(256);
    req.setHeight(256);

    WMSMapContent mapContent = new WMSMapContent(req);
    mapContent.addLayer(createMapLayer(MockData.STREAMS, "big-local-image"));

    mapContent
        .getViewport()
        .setBounds(new ReferencedEnvelope(-180, 0, -90, 90, DefaultGeographicCRS.WGS84));
    mapContent.setMapHeight(256);
    mapContent.setMapWidth(256);

    KMLMapOutputFormat of = new KMLMapOutputFormat(getWMS());
    KMLMap map = of.produceMap(mapContent);

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    new KMLEncoder().encode(map.getKml(), bout, null);

    Document document = dom(new ByteArrayInputStream(bout.toByteArray()));

    assertEquals("kml", document.getDocumentElement().getNodeName());
    assertEquals(1, document.getElementsByTagName("Style").getLength());

    XMLAssert.assertXpathExists("//kml:IconStyle/kml:scale", document);

    XPath xPath = XPathFactory.newInstance().newXPath();
    initXPath(xPath);

    Double scale =
        (Double)
            xPath.evaluate(
                "//kml:IconStyle/kml:scale", document.getDocumentElement(), XPathConstants.NUMBER);
    assertEquals(42d / 16d, scale, 0.01);
  }