diff --git a/gwt-client-geo-ol3/src/main/java/nl/aerius/geo/wui/util/OL3GeometryUtil.java b/gwt-client-geo-ol3/src/main/java/nl/aerius/geo/wui/util/OL3GeometryUtil.java index c063d60..82901db 100644 --- a/gwt-client-geo-ol3/src/main/java/nl/aerius/geo/wui/util/OL3GeometryUtil.java +++ b/gwt-client-geo-ol3/src/main/java/nl/aerius/geo/wui/util/OL3GeometryUtil.java @@ -31,6 +31,7 @@ import ol.geom.LineString; import ol.geom.Point; import ol.geom.Polygon; +import ol.proj.Projection; import nl.overheid.aerius.geo.shared.BBox; @@ -38,6 +39,11 @@ 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; + private static final Wkt WKT = new Wkt(); private OL3GeometryUtil() {} @@ -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(); + } } diff --git a/gwt-client-geo-ol3/src/main/java/nl/aerius/geo/wui/util/OL3MapLayerFactory.java b/gwt-client-geo-ol3/src/main/java/nl/aerius/geo/wui/util/OL3MapLayerFactory.java index b8aa330..7c36e82 100644 --- a/gwt-client-geo-ol3/src/main/java/nl/aerius/geo/wui/util/OL3MapLayerFactory.java +++ b/gwt-client-geo-ol3/src/main/java/nl/aerius/geo/wui/util/OL3MapLayerFactory.java @@ -83,6 +83,13 @@ public IsLayer 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; } diff --git a/gwt-client-geo-ol3/src/main/java/nl/aerius/geo/wui/util/OL3WmtsTileGridUtil.java b/gwt-client-geo-ol3/src/main/java/nl/aerius/geo/wui/util/OL3WmtsTileGridUtil.java index 69535e1..9c129ff 100644 --- a/gwt-client-geo-ol3/src/main/java/nl/aerius/geo/wui/util/OL3WmtsTileGridUtil.java +++ b/gwt-client-geo-ol3/src/main/java/nl/aerius/geo/wui/util/OL3WmtsTileGridUtil.java @@ -19,6 +19,7 @@ import java.util.List; import ol.Coordinate; +import ol.Extent; import ol.OLFactory; import ol.proj.Projection; import ol.tilegrid.WmtsTileGrid; @@ -26,37 +27,34 @@ 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 resolutionList, final Coordinate origin, - final Projection projection) { + public static WmtsTileGrid createWmtsTileGrid(final List 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); } diff --git a/gwt-client-geo-ol3/src/main/java/nl/aerius/geo/wui/util/RDNewWmtsTileGrid.java b/gwt-client-geo-ol3/src/main/java/nl/aerius/geo/wui/util/RDNewWmtsTileGrid.java index bd7dbf6..e87baa7 100644 --- a/gwt-client-geo-ol3/src/main/java/nl/aerius/geo/wui/util/RDNewWmtsTileGrid.java +++ b/gwt-client-geo-ol3/src/main/java/nl/aerius/geo/wui/util/RDNewWmtsTileGrid.java @@ -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 RESOLUTIONS = Arrays.asList( + private static final List SCALES = Arrays.asList( 12288000.0, 6144000.0, 3072000.0, @@ -46,10 +47,12 @@ public final class RDNewWmtsTileGrid { public static final List 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); } } diff --git a/gwt-client-geo-ol3/src/main/java/nl/aerius/geo/wui/util/TM75WmtsTileGrid.java b/gwt-client-geo-ol3/src/main/java/nl/aerius/geo/wui/util/TM75WmtsTileGrid.java index ab2854c..4627868 100644 --- a/gwt-client-geo-ol3/src/main/java/nl/aerius/geo/wui/util/TM75WmtsTileGrid.java +++ b/gwt-client-geo-ol3/src/main/java/nl/aerius/geo/wui/util/TM75WmtsTileGrid.java @@ -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 RESOLUTIONS = Arrays.asList( + private static final List SCALES = Arrays.asList( 1889884.7321501793, 1417413.5491126343, 1039436.6026825986, @@ -49,10 +50,12 @@ public final class TM75WmtsTileGrid { */ public static final List 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); } } diff --git a/gwt-shared-geo-common/src/main/java/nl/aerius/geo/shared/LayerProps.java b/gwt-shared-geo-common/src/main/java/nl/aerius/geo/shared/LayerProps.java index f1a5e3d..9ca97bb 100644 --- a/gwt-shared-geo-common/src/main/java/nl/aerius/geo/shared/LayerProps.java +++ b/gwt-shared-geo-common/src/main/java/nl/aerius/geo/shared/LayerProps.java @@ -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 <= end year is allowed. @@ -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; } @@ -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; }