WmsLayer implements RasterLayer, LayerFeatureInfoSupport, ProxyLayerSupport { public List<RasterTile> paint(CoordinateReferenceSystem targetCrs, Envelope bounds, double scale) throws GeomajasException { Envelope layerBounds = bounds; double layerScale = scale; CrsTransform layerToMap = null; boolean needTransform = !crs.equals(targetCrs); try { if (needTransform) { layerToMap = geoService.getCrsTransform(crs, targetCrs); CrsTransform mapToLayer = geoService.getCrsTransform(targetCrs, crs); layerBounds = geoService.transform(bounds, mapToLayer); layerScale = bounds.getWidth() * scale / layerBounds.getWidth(); } } catch (MismatchedDimensionException e) { throw new GeomajasException(e, ExceptionCode.RENDER_DIMENSION_MISMATCH); } layerBounds = clipBounds(layerBounds); if (layerBounds.isNull()) { return new ArrayList<RasterTile>(0); } Resolution bestResolution = getResolutionForScale(layerScale); RasterGrid grid = getRasterGrid(layerBounds, bestResolution.getTileWidth(), bestResolution.getTileHeight()); List<RasterTile> result = new ArrayList<RasterTile>(); for (int i = grid.getXmin(); i < grid.getXmax(); i++) { for (int j = grid.getYmin(); j < grid.getYmax(); j++) { double x = grid.getLowerLeft().x + (i - grid.getXmin()) * grid.getTileWidth(); double y = grid.getLowerLeft().y + (j - grid.getYmin()) * grid.getTileHeight(); Bbox worldBox; Bbox layerBox; if (needTransform) { layerBox = new Bbox(x, y, grid.getTileWidth(), grid.getTileHeight()); worldBox = geoService.transform(layerBox, layerToMap); } else { worldBox = new Bbox(x, y, grid.getTileWidth(), grid.getTileHeight()); layerBox = worldBox; } Bbox screenBox = new Bbox(Math.round(scale * worldBox.getX()), -Math.round(scale * worldBox.getMaxY()), Math.round(scale * worldBox.getMaxX()) - Math.round(scale * worldBox.getX()), Math.round(scale * worldBox.getMaxY()) - Math.round(scale * worldBox.getY())); RasterTile image = new RasterTile(screenBox, getId() + "." + bestResolution.getLevel() + "." + i + "," + j); image.setCode(new TileCode(bestResolution.getLevel(), i, j)); String url = formatUrl(bestResolution.getTileWidthPx(), bestResolution.getTileHeightPx(), layerBox); image.setUrl(url); result.add(image); } } return result; }  String getId(); void setId(String id); RasterLayerInfo getLayerInfo(); @Deprecated CoordinateReferenceSystem getCrs(); @Api WmsFeatureInfoFormat getFeatureInfoFormat(); @Api void setFeatureInfoFormat(WmsFeatureInfoFormat featureInfoFormat); @Api void setLayerInfo(RasterLayerInfo layerInfo); List<Feature> getFeaturesByLocation(Coordinate layerCoordinate, double layerScale, int pixelTolerance); List<RasterTile> paint(CoordinateReferenceSystem targetCrs, Envelope bounds, double scale); String getBaseWmsUrl(); @Api void setBaseWmsUrl(String baseWmsUrl); String getFormat(); @Api void setFormat(String format); @Api void setVersion(String version); @Api void setStyles(String styles); @Api void setParameters(List<Parameter> parameters); @Deprecated WmsAuthentication getAuthentication(); @Api @Deprecated void setAuthentication(WmsAuthentication authentication); ProxyAuthentication getProxyAuthentication(); @Api void setLayerAuthentication(LayerAuthentication layerAuthentication); @Api void setUseProxy(boolean useProxy); @Api void setUseCache(boolean useCache); @Api boolean isUseCache(); @Api void setEnableFeatureInfoSupport(boolean enableFeatureInfoSupport); boolean isEnableFeatureInfoSupport();  }
@Test public void testLevels() throws Exception { Crs latlon = geoService.getCrs2(LONLAT); Envelope latlonEnvelope = null; for (int level = 0; level < 32; level++) { double latlonScale = Math.pow(2, level); latlonEnvelope = new Envelope(-180, -180 + 1.0 / latlonScale, -412, -412 + 1.0 / latlonScale); List<RasterTile> tiles = wms.paint(latlon, latlonEnvelope, latlonScale); Assert.assertEquals(1, tiles.size()); Assert.assertEquals(level, tiles.get(0).getCode().getTileLevel()); Assert.assertEquals(512, tiles.get(0).getBounds().getHeight(), DELTA); Assert.assertEquals(512, tiles.get(0).getBounds().getWidth(), DELTA); } }
@Test public void testNormalOne() throws Exception { Envelope googleEnvelope = new Envelope(10000, 10010, 5000, 5010); Crs google = geoService.getCrs2(MERCATOR); Crs latlon = geoService.getCrs2(LONLAT); Envelope latlonEnvelope = geoService.transform(JTS.toGeometry(googleEnvelope), google, latlon) .getEnvelopeInternal(); double latlonScale = ZOOMED_IN_SCALE * googleEnvelope.getWidth() / latlonEnvelope.getWidth(); List<RasterTile> tiles = wms.paint(latlon, latlonEnvelope, latlonScale); Assert.assertEquals(1, tiles.size()); RasterTile tile = tiles.get(0); Assert.assertEquals("http: + "WIDTH=512&HEIGHT=512&bbox=-20,-28,12,4&format=image/jpeg&version=1.1.1&srs=EPSG%3A4326&" + "styles=&request=GetMap", tile.getUrl()); Assert.assertEquals(4, tile.getCode().getTileLevel()); Assert.assertEquals(5, tile.getCode().getX()); Assert.assertEquals(12, tile.getCode().getY()); Assert.assertEquals(-223.0, tile.getBounds().getX(), DELTA); Assert.assertEquals(-45.0, tile.getBounds().getY(), DELTA); Assert.assertEquals(357.0, tile.getBounds().getHeight(), DELTA); Assert.assertEquals(357.0, tile.getBounds().getWidth(), DELTA); }
@Test public void testNormalEncoded() throws Exception { Envelope googleEnvelope = new Envelope(10000, 10010, 5000, 5010); Crs google = geoService.getCrs2(MERCATOR); Crs latlon = geoService.getCrs2(LONLAT); Envelope latlonEnvelope = geoService.transform(JTS.toGeometry(googleEnvelope), google, latlon) .getEnvelopeInternal(); double latlonScale = ZOOMED_IN_SCALE * googleEnvelope.getWidth() / latlonEnvelope.getWidth(); List<RasterTile> tiles = escapeBlue.paint(latlon, latlonEnvelope, latlonScale); Assert.assertEquals(1, tiles.size()); RasterTile tile = tiles.get(0); assertThat(tile.getUrl()).isEqualTo("http: "layers=geomajas%3Abluemarble&WIDTH=512&HEIGHT=512&bbox=0,0,45,45&format=image/png&version=1.1.1&" + "srs=EPSG%3A4326&styles=&what%3F=value%2Bmore%21&request=GetMap"); }
@Test public void testNormalSeveral() throws Exception { Envelope googleEnvelope = new Envelope(10000, 11000, 6005000, 6006000); Crs google = geoService.getCrs2(MERCATOR); Crs latlon = geoService.getCrs2(LONLAT); Envelope latlonEnvelope = geoService.transform(JTS.toGeometry(googleEnvelope), google, latlon) .getEnvelopeInternal(); double latlonScale = MAX_LEVEL_SCALE * googleEnvelope.getWidth() / latlonEnvelope.getWidth(); List<RasterTile> tiles = wms.paint(latlon, latlonEnvelope, latlonScale); Assert.assertEquals(2, tiles.size()); Assert.assertEquals("http: + "HEIGHT=512&bbox=0.0859375,47.3828125,0.09375,47.390625&format=image/jpeg&version=1.1.1&" + "srs=EPSG%3A4326&styles=&request=GetMap", tiles.get(0).getUrl()); Assert.assertEquals("http: + "HEIGHT=512&bbox=0.09375,47.3828125,0.1015625,47.390625&format=image/jpeg&version=1.1.1&" + "srs=EPSG%3A4326&styles=&request=GetMap", tiles.get(1).getUrl()); RasterTile tile = tiles.get(1); Assert.assertEquals(16, tile.getCode().getTileLevel()); Assert.assertEquals(23052, tile.getCode().getX()); Assert.assertEquals(58801, tile.getCode().getY()); Assert.assertEquals(4174.0, tile.getBounds().getX(), DELTA); Assert.assertEquals(-2110200.0, tile.getBounds().getY(), DELTA); Assert.assertEquals(348.0, tile.getBounds().getHeight(), DELTA); Assert.assertEquals(348.0, tile.getBounds().getWidth(), DELTA); }
@Test public void testReprojectOne() throws Exception { Envelope googleEnvelope = new Envelope(10000, 10010, 5000, 5010); Crs google = geoService.getCrs2(MERCATOR); List<RasterTile> tiles = wms.paint(google, googleEnvelope, ZOOMED_IN_SCALE); Assert.assertEquals(1, tiles.size()); RasterTile tile = tiles.get(0); Assert.assertEquals("http: + "HEIGHT=512&bbox=-20,-28,12,4&format=image/jpeg&version=1.1.1&srs=EPSG%3A4326&" + "styles=&request=GetMap", tile.getUrl()); Assert.assertEquals(4, tile.getCode().getTileLevel()); Assert.assertEquals(5, tile.getCode().getX()); Assert.assertEquals(12, tile.getCode().getY()); }
@Test public void testReprojectSeveral() throws Exception { Envelope googleEnvelope = new Envelope(10000, 11000, 6005000, 6006000); Crs google = geoService.getCrs2(MERCATOR); List<RasterTile> tiles = wms.paint(google, googleEnvelope, MAX_LEVEL_SCALE); Assert.assertEquals(2, tiles.size()); Assert.assertEquals("http: + "HEIGHT=512&bbox=0.0859375,47.3828125,0.09375,47.390625&format=image/jpeg&version=1.1.1&" + "srs=EPSG%3A4326&styles=&request=GetMap", tiles.get(0).getUrl()); Assert.assertEquals("http: + "HEIGHT=512&bbox=0.09375,47.3828125,0.1015625,47.390625&format=image/jpeg&version=1.1.1&" + "srs=EPSG%3A4326&styles=&request=GetMap", tiles.get(1).getUrl()); RasterTile tile = tiles.get(1); Assert.assertEquals(16, tile.getCode().getTileLevel()); Assert.assertEquals(23052, tile.getCode().getX()); Assert.assertEquals(58801, tile.getCode().getY()); Assert.assertEquals(4174.0, tile.getBounds().getX(), DELTA); Assert.assertEquals(-2402427.0, tile.getBounds().getY(), DELTA); Assert.assertEquals(513.0, tile.getBounds().getHeight(), DELTA); Assert.assertEquals(348.0, tile.getBounds().getWidth(), DELTA); }
@Test public void testProxyOne() throws Exception { Envelope googleEnvelope = new Envelope(10000, 10010, 5000, 5010); Crs google = geoService.getCrs2(MERCATOR); Crs latlon = geoService.getCrs2(LONLAT); Envelope latlonEnvelope = geoService.transform(JTS.toGeometry(googleEnvelope), google, latlon) .getEnvelopeInternal(); double latlonScale = ZOOMED_IN_SCALE * googleEnvelope.getWidth() / latlonEnvelope.getWidth(); List<RasterTile> tiles = proxyWms.paint(latlon, latlonEnvelope, latlonScale); Assert.assertEquals(1, tiles.size()); RasterTile tile = tiles.get(0); Assert.assertEquals("./d/wms/proxyBlue/?SERVICE=WMS&layers=bluemarble&WIDTH=512&HEIGHT=512&bbox" + "=-20,-28,12,4&format=image/jpeg&version=1.3.0&crs=EPSG%3A4326&styles=&request=GetMap", tile.getUrl()); Assert.assertEquals(4, tile.getCode().getTileLevel()); Assert.assertEquals(5, tile.getCode().getX()); Assert.assertEquals(12, tile.getCode().getY()); Assert.assertEquals(-223.0, tile.getBounds().getX(), DELTA); Assert.assertEquals(-45.0, tile.getBounds().getY(), DELTA); Assert.assertEquals(357.0, tile.getBounds().getHeight(), DELTA); Assert.assertEquals(357.0, tile.getBounds().getWidth(), DELTA); }
@Test public void testDefaultsOne() throws Exception { Envelope googleEnvelope = new Envelope(10000, 10010, 5000, 5010); Crs google = geoService.getCrs2(MERCATOR); Crs latlon = geoService.getCrs2(LONLAT); Envelope latlonEnvelope = geoService.transform(JTS.toGeometry(googleEnvelope), google, latlon) .getEnvelopeInternal(); double latlonScale = ZOOMED_IN_SCALE * googleEnvelope.getWidth() / latlonEnvelope.getWidth(); List<RasterTile> tiles = defaultWms.paint(latlon, latlonEnvelope, latlonScale); Assert.assertEquals(1, tiles.size()); RasterTile tile = tiles.get(0); Assert.assertEquals("http: + "=512&bbox=-20,-28,12,4&format=image/png&version=1.1.1&srs=EPSG%3A4326&styles=&request=GetMap", tile.getUrl()); Assert.assertEquals(4, tile.getCode().getTileLevel()); Assert.assertEquals(5, tile.getCode().getX()); Assert.assertEquals(12, tile.getCode().getY()); Assert.assertEquals(-223.0, tile.getBounds().getX(), DELTA); Assert.assertEquals(-45.0, tile.getBounds().getY(), DELTA); Assert.assertEquals(357.0, tile.getBounds().getHeight(), DELTA); Assert.assertEquals(357.0, tile.getBounds().getWidth(), DELTA); }