Skip to content

Commit

Permalink
Add meta tiling support (#1718)
Browse files Browse the repository at this point in the history
  • Loading branch information
ismailsunni authored Feb 12, 2021
1 parent 4bf95dc commit e1ed3c9
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Continuous integration

on:
push:
pull_request:

jobs:
build:
Expand Down
20 changes: 19 additions & 1 deletion core/src/main/java/org/mapfish/print/map/tiled/CoverageTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,25 @@ public GridCoverage2D call() {
}
Tile tile = task.call();
if (tile.getImage() != null) {
graphics.drawImage(tile.getImage(),
// crop the image here
BufferedImage noBufferTileImage;
if (this.tiledLayer.getTileBufferWidth() > 0 ||
this.tiledLayer.getTileBufferHeight() > 0) {
int noBufferWidth = Math.min(
this.tiledLayer.getTileSize().width,
tile.getImage().getWidth() - this.tiledLayer.getTileBufferWidth());
int noBufferHeight = Math.min(
this.tiledLayer.getTileSize().height,
tile.getImage().getHeight() - this.tiledLayer.getTileBufferHeight());
noBufferTileImage = tile.getImage().getSubimage(
this.tiledLayer.getTileBufferWidth(),
this.tiledLayer.getTileBufferHeight(),
noBufferWidth,
noBufferHeight);
} else {
noBufferTileImage = tile.getImage();
}
graphics.drawImage(noBufferTileImage,
tile.getxIndex() * this.tiledLayer.getTileSize().width,
tile.getyIndex() * this.tiledLayer.getTileSize().height, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@ public abstract ClientHttpRequest getTileRequest(
* Obtain the image tile size of the tiles that will be loaded from the server.
*/
public abstract Dimension getTileSize();

/**
* Obtain the buffer width for meta tiling.
*/
public int getTileBufferWidth() {
return 0;
}
/**
* Obtain the buffer height for meta tiling.
*/
public int getTileBufferHeight() {
return 0;
}

/**
* Return the full bounds of the tileCache.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,19 @@ public TilePreparationInfo call() {
final ReferencedEnvelope mapGeoBounds = this.bounds.toReferencedEnvelope(this.paintArea);
final CoordinateReferenceSystem mapProjection = mapGeoBounds.getCoordinateReferenceSystem();
Dimension tileSizeOnScreen = this.tiledLayer.getTileSize();
int tileBufferWidth = this.tiledLayer.getTileBufferWidth();
int tileBufferHeight = this.tiledLayer.getTileBufferHeight();

Dimension tileSizeOnScreenWithBuffer = new Dimension(
tileSizeOnScreen.width + 2 * tileBufferWidth,
tileSizeOnScreen.height + 2 * tileBufferHeight);

final double resolution = this.tiledLayer.getResolution();
Coordinate tileSizeInWorld = new Coordinate(tileSizeOnScreen.width * resolution,
tileSizeOnScreen.height * resolution);
Coordinate tileSizeInWorld = new Coordinate(
tileSizeOnScreen.width * resolution,
tileSizeOnScreen.height * resolution);
Coordinate bufferSizeInWorld = new Coordinate(
tileBufferWidth * resolution, tileBufferHeight * resolution);

// The minX minY of the first (minY, minY) tile
Coordinate gridCoverageOrigin =
Expand Down Expand Up @@ -122,15 +131,22 @@ public TilePreparationInfo call() {
ReferencedEnvelope tileBounds = new ReferencedEnvelope(
geoX, gridCoverageMaxX, geoY, gridCoverageMaxY, mapProjection);

ReferencedEnvelope tileBoundsWithBuffer = new ReferencedEnvelope(
geoX - bufferSizeInWorld.x,
gridCoverageMaxX + bufferSizeInWorld.x,
geoY - bufferSizeInWorld.y,
gridCoverageMaxY + bufferSizeInWorld.y,
mapProjection);

int row = (int) Math.round((tileCacheBounds.getMaxY() -
tileBounds.getMaxY()) * rowFactor);
int column = (int) Math.round((tileBounds.getMinX() -
tileCacheBounds.getMinX()) * columnFactor);

ClientHttpRequest tileRequest =
this.tiledLayer.getTileRequest(this.httpRequestFactory,
commonUrl, tileBounds,
tileSizeOnScreen, column,
commonUrl, tileBoundsWithBuffer,
tileSizeOnScreenWithBuffer, column,
row);
if (isInTileCacheBounds(tileCacheBounds, tileBounds)) {
if (isTileVisible(tileBounds)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,14 @@ public TiledWmsLayer(
*
* @param wmsLayer The source layer
* @param tileSize The size of the tiles
* @param tileBufferWidth The width of the the buffer tile for meta tile
* @param tileBufferHeight The height of the the buffer tile for meta tile
*/
public TiledWmsLayer(final WmsLayer wmsLayer, final Dimension tileSize) {
public TiledWmsLayer(final WmsLayer wmsLayer, final Dimension tileSize, final int tileBufferWidth,
final int tileBufferHeight) {
super(wmsLayer, wmsLayer.getStyleSupplier(), wmsLayer.getRegistry(), wmsLayer.getConfiguration());
this.param = new TiledWmsLayerParam(wmsLayer.getParams(), tileSize);
this.param = new TiledWmsLayerParam(
wmsLayer.getParams(), tileSize, tileBufferWidth, tileBufferHeight);
}

/**
Expand Down Expand Up @@ -161,6 +165,16 @@ public Dimension getTileSize() {
return TiledWmsLayer.this.param.getTileSize();
}

@Override
public int getTileBufferHeight() {
return TiledWmsLayer.this.param.getTileBufferHeight();
}

@Override
public int getTileBufferWidth() {
return TiledWmsLayer.this.param.getTileBufferWidth();
}

@Nonnull
@Override
protected ReferencedEnvelope getTileCacheBounds() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.mapfish.print.map.tiled.wms;

import org.locationtech.jts.util.Assert;

import org.mapfish.print.map.image.wms.WmsLayerParam;
import org.mapfish.print.parser.HasDefaultValue;

import java.awt.Dimension;
import java.net.URISyntaxException;
Expand All @@ -19,6 +21,12 @@ public final class TiledWmsLayerParam extends WmsLayerParam {
*/
public int[] tileSize;

/**
* A two element array of integers indicating the width and height tile buffer.
*/
@HasDefaultValue
public int[] tileBufferSize = new int[] {0, 0};

/**
* Constructor.
*/
Expand All @@ -31,10 +39,14 @@ public TiledWmsLayerParam() {
*
* @param params the WMS parameters to convert
* @param tileSize The size of the tiles
* @param tileBufferWidth The width of the the buffer tile for meta tile
* @param tileBufferHeight The height of the the buffer tile for meta tile
*/
public TiledWmsLayerParam(final WmsLayerParam params, final Dimension tileSize) {
public TiledWmsLayerParam(final WmsLayerParam params, final Dimension tileSize,
final int tileBufferWidth, final int tileBufferHeight) {
super(params);
this.tileSize = new int[]{tileSize.width, tileSize.height};
this.tileBufferSize = new int[]{tileBufferWidth, tileBufferHeight};
}

@Override
Expand All @@ -49,4 +61,12 @@ public Dimension getTileSize() {
return new Dimension(this.tileSize[0], this.tileSize[1]);
}

public int getTileBufferWidth() {
return this.tileBufferSize[0];
}

public int getTileBufferHeight() {
return this.tileBufferSize[1];
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ public final Void execute(final Input values, final ExecutionContext context) th
String.join(", ", wmsLayer.getParams().layers), tileSize.width,
tileSize.height);
}
values.map.replaceLayer(i, new TiledWmsLayer(wmsLayer, tileSize));
// Notes(IS): Honestly I have no idea where should I put these buffer size.
// It is needed for TiledWmsLayer (so that the values are accessible)
final int tileBufferWidth = 0;
final int tileBufferHeight = 0;

values.map.replaceLayer(i, new TiledWmsLayer(
wmsLayer, tileSize, tileBufferWidth, tileBufferHeight));
}
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"layout": "A4 landscape",
"outputFormat": "pdf",
"attributes": {
"map": {
"projection": "EPSG:4326",
"dpi": 72,
"rotation": 0,
"bbox": [
-130,
20,
-60,
50
],
"longitudeFirst": true,
"layers": [
{
"type": "tiledwms",
"layers": [
"topp:states"
],
"baseURL": "http://geoserver:8080/wms",
"imageFormat": "image/png",
"version": "1.1.1",
"customParams": {
"TRANSPARENT": "true"
},
"tileSize": [
256,
256
],
"tileBufferSize": [
60,
60
]
}
]
}
}
}

0 comments on commit e1ed3c9

Please sign in to comment.