Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AER-1298 Add support for min/max layer scale and add tile grid extent #47

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@
import ol.geom.LineString;
import ol.geom.Point;
import ol.geom.Polygon;
import ol.proj.Projection;

import nl.overheid.aerius.geo.shared.BBox;

public final class OL3GeometryUtil {

public static final int WKT_DECIMALS = 2;

/**
* Magic constant extracted from the OpenLayers source code
*/
private static final double PIXEL_SIZE_IN_METERS = 0.28e-3;
wtenbosch marked this conversation as resolved.
Show resolved Hide resolved

private static final Wkt WKT = new Wkt();

private OL3GeometryUtil() {}
Expand Down Expand Up @@ -162,4 +168,13 @@ private static Coordinate offsetCoordinate(final Coordinate original, final doub
-Math.cos(direction) * distance + original.getY());
}

/**
* Convert a number denoting the scale to the resolution number used by OL3
* @param scale scale to convert
* @param projection projecten to return meters per unit
* @return resolution
*/
public static double scaleToResolution(final double scale, final Projection projection) {
return (scale * OL3GeometryUtil.PIXEL_SIZE_IN_METERS) / projection.getMetersPerUnit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ public IsLayer<Layer> prepareLayer(final LayerProps c) {
layer.getInfo().setName(c.getName());
layer.getInfo().setBundle(c.getBundleName());

final Projection projection = layer.asLayer().getSource().getProjection();
if (c.getMinScale() != null && projection != null) {
layer.asLayer().setMinResolution(OL3GeometryUtil.scaleToResolution(c.getMinScale(), projection));
}
if (c.getMaxScale() != null && projection != null) {
layer.asLayer().setMaxResolution(OL3GeometryUtil.scaleToResolution(c.getMaxScale(), projection));
}
return layer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,42 @@
import java.util.List;

import ol.Coordinate;
import ol.Extent;
import ol.OLFactory;
import ol.proj.Projection;
import ol.tilegrid.WmtsTileGrid;
import ol.tilegrid.WmtsTileGridOptions;

public final class OL3WmtsTileGridUtil {

/**
* Magic constant extracted from the OpenLayers source code
*/
private static final double PIXEL_SIZE_IN_METERS = 0.28e-3;

private OL3WmtsTileGridUtil() {
}

/**
* Constructs a WmtsTileGrid from a resolutions list, origin and projection
* Constructs a WmtsTileGrid from a scale list, origin and projection
*
* @param resolutionList resolutions list (size determines number of zoomlevels)
* @param scaleList scale list (size determines number of zoomlevels)
* @param origin origin of the tile grid
* @param projection projection of the tile grid
* @param extent extent of the tile grid
* @return constructed WmtsTileGrid
*/
public static WmtsTileGrid createWmtsTileGrid(final List<Double> resolutionList, final Coordinate origin,
final Projection projection) {
public static WmtsTileGrid createWmtsTileGrid(final List<Double> scaleList, final Coordinate origin,
final Projection projection, final Extent extent) {
final WmtsTileGridOptions wmtsTileGridOptions = OLFactory.createOptions();

final double[] resolutions = new double[resolutionList.size()];
final String[] matrixIds = new String[resolutionList.size()];
final double[] resolutions = new double[scaleList.size()];
final String[] matrixIds = new String[scaleList.size()];

for (int i = 0; i < resolutionList.size(); i++) {
for (int i = 0; i < scaleList.size(); i++) {
matrixIds[i] = String.valueOf(i);
resolutions[i] = (resolutionList.get(i) * PIXEL_SIZE_IN_METERS) / projection.getMetersPerUnit();
resolutions[i] = OL3GeometryUtil.scaleToResolution(scaleList.get(i), projection);
}

wmtsTileGridOptions.setOrigin(origin);
wmtsTileGridOptions.setResolutions(resolutions);
wmtsTileGridOptions.setMatrixIds(matrixIds);
wmtsTileGridOptions.setExtent(extent);

return new WmtsTileGrid(wmtsTileGridOptions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
import java.util.List;

import ol.Coordinate;
import ol.Extent;
import ol.proj.Projection;
import ol.tilegrid.WmtsTileGrid;

public final class RDNewWmtsTileGrid {

private static final List<Double> RESOLUTIONS = Arrays.asList(
private static final List<Double> SCALES = Arrays.asList(
12288000.0,
6144000.0,
3072000.0,
Expand All @@ -46,10 +47,12 @@ public final class RDNewWmtsTileGrid {

public static final List<String> PROJECTIONS = Arrays.asList("EPSG:28992");

private static final Extent EXTENT = Extent.create(482.06, 306602.42, 284182.97, 637049.52);

private RDNewWmtsTileGrid() {
}

public static WmtsTileGrid getTileGrid() {
return OL3WmtsTileGridUtil.createWmtsTileGrid(RESOLUTIONS, ORIGIN, Projection.get(PROJECTIONS.get(0)));
return OL3WmtsTileGridUtil.createWmtsTileGrid(SCALES, ORIGIN, Projection.get(PROJECTIONS.get(0)), EXTENT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
import java.util.List;

import ol.Coordinate;
import ol.Extent;
import ol.proj.Projection;
import ol.tilegrid.WmtsTileGrid;

public final class TM75WmtsTileGrid {

private static final List<Double> RESOLUTIONS = Arrays.asList(
private static final List<Double> SCALES = Arrays.asList(
1889884.7321501793,
1417413.5491126343,
1039436.6026825986,
Expand All @@ -49,10 +50,12 @@ public final class TM75WmtsTileGrid {
*/
public static final List<String> PROJECTION = Arrays.asList("EPSG:29902", "EPSG:29903");

private static final Extent EXTENT = Extent.create(180000.0, 290000.0, 380000.0, 470000.0);

private TM75WmtsTileGrid() {
}

public static WmtsTileGrid getTileGrid() {
return OL3WmtsTileGridUtil.createWmtsTileGrid(RESOLUTIONS, ORIGIN, Projection.get(PROJECTION.get(0)));
return OL3WmtsTileGridUtil.createWmtsTileGrid(SCALES, ORIGIN, Projection.get(PROJECTION.get(0)), EXTENT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ public class LayerProps implements Serializable {
private String name;

/**
* The minimum scale at which data will be visible. If scale becomes larger nothing will be shown. If the value is < 0 it means there is no min
* The minimum scale at which data will be visible. If scale becomes larger nothing will be shown. If the value is null it means there is no min
* scale.
*/
private float minScale;
private Double minScale;

/**
* The maximum scale for which data is available. If scale comes below this value nothing will be shown. If the value is < 0 it means there is no
* The maximum scale for which data is available. If scale comes below this value nothing will be shown. If the value is null it means there is no
* max scale.
*/
private float maxScale;
private Double maxScale;

/**
* The begin year at which data starts becoming visible. If not set, but end year is, everything &lt;= end year is allowed.
Expand Down Expand Up @@ -110,11 +110,11 @@ public String getName() {
return name;
}

public float getMinScale() {
public Double getMinScale() {
return minScale;
}

public float getMaxScale() {
public Double getMaxScale() {
return maxScale;
}

Expand Down Expand Up @@ -162,11 +162,11 @@ public void setName(final String name) {
this.name = name;
}

public void setMinScale(final float minScale) {
public void setMinScale(final Double minScale) {
this.minScale = minScale;
}

public void setMaxScale(final float maxScale) {
public void setMaxScale(final Double maxScale) {
this.maxScale = maxScale;
}

Expand Down
Loading