@Test public void testDispatchGetMapDoesntMatchTileCache() throws Exception { GetMapRequest request = new GetMapRequest(); @SuppressWarnings("unchecked") Map<String, String> rawKvp = new CaseInsensitiveMap(new HashMap<String, String>()); request.setRawKvp(rawKvp); rawKvp.put("layers", "more,than,one,layer"); assertDispatchMismatch(request, "more than one layer requested"); rawKvp.put("layers", "SomeNonCachedLayer"); when(tld.getTileLayer(eq("SomeNonCachedLayer"))) .thenThrow(new GeoWebCacheException("layer not found")); assertDispatchMismatch(request, "not a tile layer"); rawKvp.put("layers", tileLayer.getName()); request.setFormat("badFormat"); assertDispatchMismatch(request, "not a GWC supported format"); request.setFormat("image/gif"); assertDispatchMismatch(request, "no tile cache for requested format"); request.setFormat(tileLayer.getMimeTypes().get(0).getMimeType()); request.setSRS("EPSG:4326"); request.setBbox(new Envelope(10, 10, 20, 20)); assertDispatchMismatch(request, "request does not align to grid"); request.setSRS("EPSG:23036"); assertDispatchMismatch(request, "no cache exists for requested CRS"); request.setSRS("badCRS"); assertDispatchMismatch(request, "exception occurred"); request.setSRS("EPSG:4326"); request.setWidth(128); request.setHeight(256); assertDispatchMismatch(request, "request does not align to grid"); request.setWidth(256); request.setHeight(128); assertDispatchMismatch(request, "request does not align to grid"); request.setSRS("EPSG:4326"); request.setWidth(256); request.setHeight(256); assertDispatchMismatch(request, "request does not align to grid"); }
@Test public void testWMSGetFeatureInfo() throws Exception { GetFeatureInfoRequest gfi = new GetFeatureInfoRequest(); GetMapRequest gm = new GetMapRequest(); gm.setHeight(330); gm.setWidth(780); Envelope env = new ReferencedEnvelope(-126.81851, -115.818992, 44.852958, 49.5066, null); CoordinateReferenceSystem crs = CRS.decode("EPSG:4326", true); CoordinateReferenceSystem logCrs = CRS.decode("EPSG:4326", false); gm.setBbox(env); gm.setCrs(crs); gfi.setGetMapRequest(gm); gfi.setXPixel(260); gfi.setYPixel(63); gfi.setVersion("1.1.1"); gfi.setQueryLayers(Arrays.asList(createMapLayer("foo", "acme"), createMapLayer("bar", "acme"))); callback.operationDispatched(new Request(), op("GetFeatureInfo", "WMS", "1.1.1", gfi)); assertEquals("acme:foo", data.getResources().get(0)); assertEquals("acme:bar", data.getResources().get(1)); BBoxAsserts.assertEqualsBbox( new ReferencedEnvelope(48.62, 48.62, -123.15, -123.15, logCrs), data.getBbox(), 0.01); }
@Test public void testWMSGetFeatureInfoDifferentCrs() throws Exception { /* * BBOX 3833170.221556,1841755.690829, 4083455.358596,2048534.231783 * EXCEPTIONS application/vnd.ogc.se_xml * FEATURE_COUNT 50 * HEIGHT 423 * INFO_FORMAT text/html * Layers monitor-test:prov3348 * QUERY_LAYERS monitor-test:prov3348 * REQUEST GetFeatureInfo * SERVICE WMS * WIDTH 512 * format image/png * srs EPSG:3348 * styles * version 1.1.1 * x 259 * y 241 */ /* * -123.34927,48.44669,3960017.648,1933344.872 */ GetFeatureInfoRequest gfi = new GetFeatureInfoRequest(); GetMapRequest gm = new GetMapRequest(); gm.setHeight(423); gm.setWidth(512); Envelope env = new ReferencedEnvelope( 3833170.221556, 4083455.358596, 1841755.690829, 2048534.231783, null); CoordinateReferenceSystem crs = CRS.decode("EPSG:3348", true); CoordinateReferenceSystem logCrs = CRS.decode("EPSG:4326", false); gm.setBbox(env); gm.setCrs(crs); gfi.setGetMapRequest(gm); gfi.setXPixel(259); gfi.setYPixel(241); gfi.setVersion("1.1.1"); gfi.setQueryLayers(Arrays.asList(createMapLayer("foo", "acme"), createMapLayer("bar", "acme"))); callback.operationDispatched(new Request(), op("GetFeatureInfo", "WMS", "1.1.1", gfi)); assertEquals("acme:foo", data.getResources().get(0)); assertEquals("acme:bar", data.getResources().get(1)); BBoxAsserts.assertEqualsBbox( new ReferencedEnvelope(48.4, 48.4, -123.3, -123.3, logCrs), data.getBbox(), 0.1); }
private void testMultipleCrsMatchingGridSubsets( final String srs, final String expectedGridset, long[] tileIndex) throws Exception { GetMapRequest request = new GetMapRequest(); @SuppressWarnings("unchecked") Map<String, String> rawKvp = new CaseInsensitiveMap(new HashMap<String, String>()); request.setRawKvp(rawKvp); request.setFormat("image/png"); request.setSRS(srs); request.setWidth(256); request.setHeight(256); rawKvp.put("layers", "mockLayer"); List<String> gridSetNames = Arrays.asList("GlobalCRS84Pixel", "GlobalCRS84Scale", "EPSG:4326"); tileLayer = mockTileLayer("mockLayer", gridSetNames); // make the request match a tile in the expected gridset BoundingBox bounds; bounds = tileLayer.getGridSubset(expectedGridset).boundsFromIndex(tileIndex); Envelope reqBbox = new Envelope(bounds.getMinX(), bounds.getMaxX(), bounds.getMinY(), bounds.getMaxY()); request.setBbox(reqBbox); ArgumentCaptor<ConveyorTile> captor = ArgumentCaptor.forClass(ConveyorTile.class); StringBuilder errors = new StringBuilder(); mediator.dispatch(request, errors); assertTrue(errors.toString(), errors.length() == 0); verify(tileLayer, times(1)).getTile(captor.capture()); ConveyorTile tileRequest = captor.getValue(); assertEquals(expectedGridset, tileRequest.getGridSetId()); assertEquals("image/png", tileRequest.getMimeType().getMimeType()); assertTrue( "Expected " + Arrays.toString(tileIndex) + " got " + Arrays.toString(tileRequest.getTileIndex()), Arrays.equals(tileIndex, tileRequest.getTileIndex())); }
@Test public void testDispatchGetMapWithMatchingParameterFilters() throws Exception { GetMapRequest request = new GetMapRequest(); @SuppressWarnings("unchecked") Map<String, String> rawKvp = new CaseInsensitiveMap(new HashMap<String, String>()); request.setRawKvp(rawKvp); request.setFormat("image/png"); request.setSRS("EPSG:900913"); request.setWidth(256); request.setHeight(256); rawKvp.put("layers", tileLayer.getName()); // tileLayer = mockTileLayer("mockLayer", ImmutableList.of("EPSG:900913", "EPSG:4326")); // make the request match a tile in the expected gridset BoundingBox bounds; bounds = tileLayer.getGridSubset("EPSG:900913").boundsFromIndex(new long[] {0, 0, 1}); Envelope reqBbox = new Envelope(bounds.getMinX(), bounds.getMaxX(), bounds.getMinY(), bounds.getMaxY()); request.setBbox(reqBbox); assertTrue(tileLayer.getInfo().cachedStyles().size() > 0); for (String style : tileLayer.getInfo().cachedStyles()) { String rawKvpParamName = "styles"; String rawKvpParamValue = style; testParameterFilter(request, rawKvp, rawKvpParamName, rawKvpParamValue); } request.setEnv(ImmutableMap.of("envKey", "envValue")); updateStringParameterFilter( tileLayerInfo, "ENV", true, "def:devVal", "envKey:envValue", "envKey2:envValue2"); testParameterFilter(request, rawKvp, "env", "envKey:envValue"); updateAcceptAllFloatParameterFilter(tileLayerInfo, "ANGLE", true); request.setAngle(60); testParameterFilter(request, rawKvp, "angle", "60.0"); request.setAngle(61.1); testParameterFilter(request, rawKvp, "angle", "61.1"); }
WMSMapContent createMapContext(QName layer, String style) throws Exception { // create a map context WMSMapContent mapContent = new WMSMapContent(); mapContent.addLayer(createMapLayer(layer, style)); mapContent.setMapHeight(256); mapContent.setMapWidth(256); GetMapRequest getMapRequest = createGetMapRequest(new QName[] {layer}); getMapRequest.setWidth(256); getMapRequest.setHeight(256); mapContent.setRequest(getMapRequest); mapContent .getViewport() .setBounds(new ReferencedEnvelope(-180, 180, -90, 90, DefaultGeographicCRS.WGS84)); return mapContent; }
@Test public void testExternalImageSize() throws Exception { GetMapRequest req = createGetMapRequest(MockData.STREAMS); req.setWidth(256); req.setHeight(256); WMSMapContent mapContent = new WMSMapContent(req); mapContent.addLayer(createMapLayer(MockData.STREAMS, "big-local-image")); mapContent .getViewport() .setBounds(new ReferencedEnvelope(-180, 0, -90, 90, DefaultGeographicCRS.WGS84)); mapContent.setMapHeight(256); mapContent.setMapWidth(256); KMLMapOutputFormat of = new KMLMapOutputFormat(getWMS()); KMLMap map = of.produceMap(mapContent); ByteArrayOutputStream bout = new ByteArrayOutputStream(); new KMLEncoder().encode(map.getKml(), bout, null); Document document = dom(new ByteArrayInputStream(bout.toByteArray())); assertEquals("kml", document.getDocumentElement().getNodeName()); assertEquals(1, document.getElementsByTagName("Style").getLength()); XMLAssert.assertXpathExists("//kml:IconStyle/kml:scale", document); XPath xPath = XPathFactory.newInstance().newXPath(); initXPath(xPath); Double scale = (Double) xPath.evaluate( "//kml:IconStyle/kml:scale", document.getDocumentElement(), XPathConstants.NUMBER); assertEquals(42d / 16d, scale, 0.01); }
void addTileLayers(GeoPackage geopkg, List<MapLayerInfo> mapLayers, WMSMapContent map) throws IOException { if (mapLayers.isEmpty()) { return; } // figure out a name for the file entry String tileEntryName = null; Map formatOpts = map.getRequest().getFormatOptions(); if (formatOpts.containsKey("tileset_name")) { tileEntryName = (String) formatOpts.get("tileset_name"); } if (tileEntryName == null) { tileEntryName = map.getTitle(); } if (tileEntryName == null && mapLayers.size() == 1) { Iterator<MapLayerInfo> it = mapLayers.iterator(); tileEntryName = it.next().getLayerInfo().getName(); } GridSubset gridSubset = findBestGridSubset(map); int[] minmax = findMinMaxZoom(gridSubset, map); BoundingBox bbox = bbox(map); TileEntry e = new TileEntry(); e.setTableName(tileEntryName); if (mapLayers.size() == 1) { ResourceInfo r = mapLayers.get(0).getResource(); e.setIdentifier(r.getTitle()); e.setDescription(r.getAbstract()); } e.setBounds( new ReferencedEnvelope( findTileBounds(gridSubset, bbox, minmax[0]), map.getCoordinateReferenceSystem())); e.setSrid(srid(map)); GridSet gridSet = gridSubset.getGridSet(); for (int z = minmax[0]; z < minmax[1]; z++) { Grid g = gridSet.getGrid(z); TileMatrix m = new TileMatrix(); m.setZoomLevel(z); m.setMatrixWidth((int) g.getNumTilesWide()); m.setMatrixHeight((int) g.getNumTilesHigh()); m.setTileWidth(gridSubset.getTileWidth()); m.setTileHeight(gridSubset.getTileHeight()); // TODO: not sure about this m.setXPixelSize(g.getResolution()); m.setYPixelSize(g.getResolution()); // m.setXPixelSize(gridSet.getPixelSize()); // m.setYPixelSize(gridSet.getPixelSize()); e.getTileMatricies().add(m); } // figure out the actual bounds of the tiles to be renderered LOGGER.fine("Creating tile entry" + e.getTableName()); geopkg.create(e); // create a prototype getmap request GetMapRequest req = new GetMapRequest(); OwsUtils.copy(map.getRequest(), req, GetMapRequest.class); req.setLayers(mapLayers); String imageFormat = formatOpts.containsKey("format") ? parseFormatFromOpts(formatOpts) : findBestFormat(map); req.setFormat(imageFormat); req.setWidth(gridSubset.getTileWidth()); req.setHeight(gridSubset.getTileHeight()); // count tiles as we generate them int ntiles = 0; // flag determining if tile row indexes we store in database should be inverted boolean flipy = Boolean.valueOf((String) formatOpts.get("flipy")); for (int z = minmax[0]; z < minmax[1]; z++) { long[] intersect = gridSubset.getCoverageIntersection(z, bbox); for (long x = intersect[0]; x <= intersect[2]; x++) { for (long y = intersect[1]; y <= intersect[3]; y++) { BoundingBox box = gridSubset.boundsFromIndex(new long[] {x, y, z}); req.setBbox(new Envelope(box.getMinX(), box.getMaxX(), box.getMinY(), box.getMaxY())); Tile t = new Tile(); t.setZoom(z); t.setColumn((int) x); t.setRow((int) (flipy ? gridSubset.getNumTilesHigh(z) - (y + 1) : y)); WebMap result = webMapService.getMap(req); t.setData(toBytes(result)); geopkg.add(e, t); // images we encode are actually kept around, we need to clean them up if (ntiles++ == TILE_CLEANUP_INTERVAL) { cleanUpImages(); ntiles = 0; } } } } }