/** Tests horizontal layout for vector */ @org.junit.Test public void testVectorLayersHorizontal() throws Exception { GetLegendGraphicRequest req = new GetLegendGraphicRequest(); FeatureTypeInfo ftInfo = getCatalog() .getFeatureTypeByName( MockData.ROAD_SEGMENTS.getNamespaceURI(), MockData.ROAD_SEGMENTS.getLocalPart()); req.setLayer(ftInfo.getFeatureType()); req.setStyle(getCatalog().getStyleByName(MockData.ROAD_SEGMENTS.getLocalPart()).getStyle()); final int HEIGHT_HINT = 20; req.setHeight(HEIGHT_HINT); HashMap legendOptions = new HashMap(); legendOptions.put("layout", "horizontal"); legendOptions.put("forceLabels", "off"); req.setLegendOptions(legendOptions); this.legendProducer.buildLegendGraphic(req); BufferedImage image = this.legendProducer.buildLegendGraphic(req); assertEquals(HEIGHT_HINT, image.getHeight()); assertPixel(image, 10, HEIGHT_HINT / 2, new Color(192, 160, 0)); assertPixel(image, 50, HEIGHT_HINT / 2, new Color(224, 64, 0)); }
request.setRawKvp(rawKvp); request.setKvp(kvp); request.setWms(wms); if (request.getVersion() == null || request.getVersion().length() == 0) { String version = (String) rawKvp.get("WMTVER"); if (version == null) { version = wms.getVersion(); request.setVersion(version); request.setLocale(new Locale(language)); rawKvp.containsKey("STRICT") ? Boolean.valueOf((String) rawKvp.get("STRICT")) : request.isStrict(); request.setStrict(strict); if (strict && layer == null) { throw new ServiceException( "LAYER parameter not present for GetLegendGraphic", "LayerNotDefined"); if (strict && request.getFormat() == null) { throw new ServiceException( "Missing FORMAT parameter for GetLegendGraphic", "MissingFormat"); request.getLegends().addAll(layers); if (request.getFormat() == null) { request.setFormat(GetLegendGraphicRequest.DEFAULT_FORMAT);
List<LegendRequest> layers = request.getLegends(); if (request.getLegendOptions().get("forceLabels") instanceof String) { String forceLabelsOpt = (String) request.getLegendOptions().get("forceLabels"); if (forceLabelsOpt.equalsIgnoreCase("on")) { forceLabelsOn = true; if (request.getLegendOptions().get("forceTitles") instanceof String) { String forceTitlesOpt = (String) request.getLegendOptions().get("forceTitles"); if (forceTitlesOpt.equalsIgnoreCase("off")) { forceTitlesOff = true; request.getLegendOption( GetLegendGraphicRequest.COUNT_MATCHED_KEY, Boolean.class))) { countProcessor = new FeatureCountProcessor(request); int w = request.getWidth(); int h = request.getHeight(); double dpi = RendererUtilities.getDpi(request.getLegendOptions()); double standardDpi = RendererUtilities.getDpi(Collections.emptyMap()); if (dpi != standardDpi) { if (request.getScale() > 0) { double pixelsPerMeters = RendererUtilities.calculatePixelsPerMeterRatio( request.getScale(), request.getLegendOptions()); UomRescaleStyleVisitor rescaleVisitor = new UomRescaleStyleVisitor(pixelsPerMeters); rescaleVisitor.visit(gt2Style);
protected int getTitleHeight(GetLegendGraphicRequest req) { final BufferedImage image = ImageUtils.createImage( req.getWidth(), req.getHeight(), (IndexColorModel) null, req.isTransparent()); return getRenderedLabel(image, "TESTTITLE", req).getHeight(); }
GetLegendGraphicRequest legendGraphicRequest = new GetLegendGraphicRequest(); Resource sampleLegendFolder = getSamplesFolder(); legendGraphicRequest.setStrict(false); legendGraphicRequest.setLayer((FeatureType) null); legendGraphicRequest.setStyle(style.getStyle()); legendGraphicRequest.setFormat(pngOutputFormat.getContentType()); Object legendGraphic = pngOutputFormat.produceLegendGraphic(legendGraphicRequest); if (legendGraphic instanceof BufferedImageLegendGraphic) {
/** Tests that symbols relative sizes are proportional. */ @org.junit.Test public void testSimpleLine() throws Exception { GetLegendGraphicRequest req = new GetLegendGraphicRequest(); req.setWidth(20); req.setHeight(20); FeatureTypeInfo ftInfo = getCatalog() .getFeatureTypeByName( MockData.MPOINTS.getNamespaceURI(), MockData.MPOINTS.getLocalPart()); req.setLayer(ftInfo.getFeatureType()); req.setStyle(readSLD("line.sld")); BufferedImage image = this.legendProducer.buildLegendGraphic(req); assertNotBlank("line", image, LegendUtils.DEFAULT_BG_COLOR); // line in the middle, but off the middle, it's white Color colorCenter = getPixelColor(image, 10, 10); assertColorSimilar(Color.BLUE, colorCenter, 20); Color colorOutsideCenter = getPixelColor(image, 6, 6); assertColorSimilar(Color.WHITE, colorOutsideCenter, 20); }
/** Tests that symbols are not bigger than the requested icon size. */ @org.junit.Test public void testSymbolContainedInIcon() throws Exception { GetLegendGraphicRequest req = new GetLegendGraphicRequest(); FeatureTypeInfo ftInfo = getCatalog() .getFeatureTypeByName( MockData.MPOINTS.getNamespaceURI(), MockData.MPOINTS.getLocalPart()); req.setLayer(ftInfo.getFeatureType()); req.setStyle(readSLD("BigSymbol.sld")); BufferedImage image = this.legendProducer.buildLegendGraphic(req); assertNotBlank("testSymbolSize", image, LegendUtils.DEFAULT_BG_COLOR); // background at borders assertPixel(image, 1, 1, new Color(255, 255, 255)); // symbol in the center assertPixel(image, 10, 10, new Color(255, 0, 0)); }
GetLegendGraphicRequest request = new GetLegendGraphicRequest(); request.setLayer(layer.getFeatureSource().getSchema()); request.setTransparent(true); request.setScale(scaleDenominator); request.setStyle(layer.getStyle()); request.setWms(wms); final Request dispatcherRequest = Dispatcher.REQUEST.get(); if (dispatcherRequest != null) { request.setKvp(dispatcherRequest.getKvp()); request.setRawKvp(dispatcherRequest.getRawKvp()); legendOptions.putAll((Map) dispatcherRequest.getKvp().get("legend_options")); request.setLegendOptions(legendOptions);
@Test public void testLayerGroupLabels() throws Exception { GetLegendGraphicRequest req = new GetLegendGraphicRequest(); StyleInfo roadsStyle = getCatalog().getStyleByName(MockData.ROAD_SEGMENTS.getLocalPart()); req.setLayers( Arrays.asList( lakesFt.getFeatureType(), placesFt.getFeatureType(), roadsFt.getFeatureType())); req.setStyles( Arrays.asList( lakesStyle.getStyle(), placesStyle.getStyle(), roadsStyle.getStyle())); req.setHeight(HEIGHT_HINT); req.setLegendOptions(legendOptions); req.setLegendOptions(legendOptions);
/** * Tests that the legend graphic is still produced when the request's strict parameter is set to * false and a layer is not specified */ @org.junit.Test public void testNoLayerProvidedAndNonStrictRequest() throws Exception { Style style = getCatalog().getStyleByName("rainfall").getStyle(); assertNotNull(style); GetLegendGraphicRequest req = new GetLegendGraphicRequest(); req.setStrict(false); req.setLayer(null); req.setStyle(style); final int HEIGHT_HINT = 30; req.setHeight(HEIGHT_HINT); // use default values for the rest of parameters this.legendProducer.buildLegendGraphic(req); BufferedImage image = this.legendProducer.buildLegendGraphic(req); // was the legend painted? assertNotBlank("testRainfall", image, LegendUtils.DEFAULT_BG_COLOR); // was the legend painted? assertNotBlank("testRainfall", image, LegendUtils.DEFAULT_BG_COLOR); } /** Tests that the legend graphic is produced for multiple layers */
GetLegendGraphicRequest request = new GetLegendGraphicRequest(); request.setWidth(legendOptionData.getImageWidth()); request.setHeight(legendOptionData.getImageHeight()); request.setTransparent(legendOptionData.isTransparent()); request.setStrict(false); "imageSizeFactor", String.valueOf(legendOptionData.getImageSize() / 100.0)); request.setLegendOptions(legendOptions);
/** * Tests that symbols relative sizes are proportional also if using uoms in some Symbolizer and * not using them in others. */ @org.junit.Test public void testProportionalSymbolSizePartialUOM() throws Exception { GetLegendGraphicRequest req = new GetLegendGraphicRequest(); req.setScale(RendererUtilities.calculatePixelsPerMeterRatio(10, Collections.EMPTY_MAP)); FeatureTypeInfo ftInfo = getCatalog() .getFeatureTypeByName( MockData.MPOINTS.getNamespaceURI(), MockData.MPOINTS.getLocalPart()); req.setLayer(ftInfo.getFeatureType()); req.setStyle(readSLD("ProportionalSymbolsPartialUOM.sld")); BufferedImage image = this.legendProducer.buildLegendGraphic(req); assertNotBlank("testProportionalSymbolSize", image, LegendUtils.DEFAULT_BG_COLOR); // UOM symbol assertPixel(image, 1, 1, new Color(255, 255, 255)); assertPixel(image, 5, 5, new Color(255, 0, 0)); assertPixel(image, 10, 10, new Color(255, 0, 0)); // non UOM symbol assertPixel(image, 1, 1, new Color(255, 255, 255)); assertPixel(image, 5, 5, new Color(255, 0, 0)); assertPixel(image, 10, 10, new Color(255, 0, 0)); }
GetLegendGraphicRequest req = new GetLegendGraphicRequest(); CoverageInfo cInfo = getCatalog().getCoverageByName("world"); assertNotNull(cInfo); legend.setStyle(externalGraphicStyle); req.getLegends().add(legend); req.setScale(1.0); req.setHeight(HEIGHT_HINT);
GetLegendGraphicRequest req = new GetLegendGraphicRequest(); layers.add(ftInfo.getFeatureType()); layers.add(ftInfo.getFeatureType()); req.setLayers(layers); req.setStyles(styles);
@Test public void testWMSGetLegendGraphic() throws Exception { WMS wms = new WMS(createMock(GeoServer.class)); GetLegendGraphicRequest glg = new GetLegendGraphicRequest(); FeatureType type = createMock(FeatureType.class); expect(type.getName()).andReturn(new NameImpl("http://acme.org", "foo")).anyTimes(); replay(type); glg.setLayer(type); callback.operationDispatched(new Request(), op("GetFeatureInfo", "WMS", "1.1.1", glg)); assertEquals("http://acme.org:foo", data.getResources().get(0)); }
GetLegendGraphicRequest req = new GetLegendGraphicRequest(); req.setScale(1000); int titleHeight = getTitleHeight(req); layers.add(ftInfo.getFeatureType()); layers.add(ftInfo.getFeatureType()); req.setLayers(layers); styles.add(readSLD("InvisibleLine.sld")); req.setStyles(styles);
final double scaleDenominator = request.getScale(); width = request.getWidth(); height = request.getHeight(); if (width <= 0 || height <= 0) throw new IllegalArgumentException( transparent = request.isTransparent(); cmapLegendBuilder.setAdditionalOptions(request.getLegendOptions());
@org.junit.Test public void testStrictParameter() throws Exception { GetLegendGraphicRequest request; // default value request = requestReader.read(new GetLegendGraphicRequest(), allParameters, allParameters); assertTrue(request.isStrict()); allParameters.put("STRICT", "false"); allParameters.remove("LAYER"); request = requestReader.read(new GetLegendGraphicRequest(), allParameters, allParameters); assertFalse(request.isStrict()); }
@org.junit.Test public void testStylesForLayerGroup() throws Exception { GetLegendGraphicRequest request; requiredParameters.put("LAYER", NATURE_GROUP); requiredParameters.put("STYLE", "style1,style2"); request = requestReader.read( new GetLegendGraphicRequest(), requiredParameters, requiredParameters); assertTrue(request.getStyles().size() == 2); }
params.put("FORMAT", "image/png"); GetLegendGraphicRequest getLegendGraphics = requestReader.read(new GetLegendGraphicRequest(), params, params); Style style = getLegendGraphics.getLegends().get(0).getStyle(); FeatureTypeStyle fts = style.featureTypeStyles().get(0); assertNull(fts.getTransformation());