Skip to content

Commit

Permalink
Add an option to scale the tile size.
Browse files Browse the repository at this point in the history
In ractice, only MVT is interested in this, but because
of how the paint area is set up it needed to be more
generic.
  • Loading branch information
Devon Tucker committed Oct 31, 2018
1 parent ea1acfe commit 743121f
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,32 @@ public String getMimeType() {
public MapBoxTileBuilder newBuilder(Rectangle screenSize, ReferencedEnvelope mapArea) {
return new MapBoxTileBuilder(screenSize, mapArea);
}

/**
* For Mapbox tiles, since they are rendered in screen/tile space, oversampling produces more
* consistent results when zooming. See this question here:
*
* <p>https://github.com/mapbox/vector-tiles/issues/45
*
* @return
*/
@Override
public boolean shouldOversampleScale() {
return true;
}

/**
* Use 16x oversampling to match actual Mapbox tile extent, which is 4096 for 900913 tiles
*
* @return
*/
@Override
public int getOversampleX() {
return 16;
}

@Override
public int getOversampleY() {
return 16;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,26 @@ public interface VectorTileBuilderFactory {
* @param mapArea The extent of the tile in target CRS coordinates
*/
VectorTileBuilder newBuilder(Rectangle screenSize, ReferencedEnvelope mapArea);

/**
* Whether tiles from this builder should be "oversampled", that is, "rendered" at a higher
* resolution than the tile resolution. The motivation for this is Mapbox vector tiles, which
* are rendered in screen space per tile and have inconsistent behavior while zooming at lower
* resolutions.
*
* @return whether this builder requires oversampling. defaults to false.
*/
default boolean shouldOversampleScale() {
return false;
}

/** @return the horizontal oversampling factor. default is 1, no oversampling */
default int getOversampleX() {
return 1;
}

/** @return the vertical oversampling factor. default is 1, no oversampling */
default int getOversampleY() {
return 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,16 @@ public WebMap produceMap(final WMSMapContent mapContent) throws ServiceException
checkArgument(mapContent.getMapWidth() > 0);
checkArgument(mapContent.getMapHeight() > 0);

// mapContent.setMapWidth(5 * mapContent.getMapWidth());
// mapContent.setMapHeight(5 * mapContent.getMapHeight());

final ReferencedEnvelope renderingArea = mapContent.getRenderingArea();
final Rectangle paintArea =
new Rectangle(mapContent.getMapWidth(), mapContent.getMapHeight());
int mapWidth = mapContent.getMapWidth();
int mapHeight = mapContent.getMapHeight();
Rectangle paintArea = new Rectangle(mapWidth, mapHeight);
if (this.tileBuilderFactory.shouldOversampleScale()) {
paintArea =
new Rectangle(
this.tileBuilderFactory.getOversampleX() * mapWidth,
this.tileBuilderFactory.getOversampleY() * mapHeight);
}

VectorTileBuilder vectorTileBuilder;
vectorTileBuilder = this.tileBuilderFactory.newBuilder(paintArea, renderingArea);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ public void checkSimpleMVT(String mimeType) throws Exception {
byte[] responseBytes = response.getContentAsByteArray();
VectorTileDecoder decoder = new VectorTileDecoder();
List<VectorTileDecoder.Feature> featuresList = decoder.decode(responseBytes).asList();
// MapBox encoder skips too small geometries
assertEquals(3, featuresList.size());
assertEquals(5, featuresList.size());
assertEquals(
2,
3,
featuresList
.stream()
.filter(f -> "Route 5".equals(f.getAttributes().get("NAME")))
Expand All @@ -94,6 +93,7 @@ public void checkSimpleMVT(String mimeType) throws Exception {
.stream()
.filter(f -> "Main Street".equals(f.getAttributes().get("NAME")))
.count());
assertEquals("Extent should be 12288", 12288, featuresList.get(0).getExtent());
}

@Test
Expand Down

0 comments on commit 743121f

Please sign in to comment.