org.geoserver.wms.GetLegendGraphicRequest.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(13.0k)|赞(0)|评价(0)|浏览(91)

本文整理了Java中org.geoserver.wms.GetLegendGraphicRequest.<init>()方法的一些代码示例,展示了GetLegendGraphicRequest.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GetLegendGraphicRequest.<init>()方法的具体详情如下:
包路径:org.geoserver.wms.GetLegendGraphicRequest
类名称:GetLegendGraphicRequest
方法名:<init>

GetLegendGraphicRequest.<init>介绍

[英]Creates a new GetLegendGraphicRequest object.
[中]创建新的GetLegendGraphicRequest对象。

代码示例

代码示例来源:origin: org.geoserver/gs-wms

@Before
public void setup() {
  request = new GetLegendGraphicRequest();
}

代码示例来源:origin: org.geoserver/gs-wms

@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);
}

代码示例来源:origin: org.geoserver/gs-wms

@org.junit.Test
public void testRulesForLayerGroup() throws Exception {
  GetLegendGraphicRequest request;
  requiredParameters.put("LAYER", NATURE_GROUP);
  requiredParameters.put("RULE", "rule1,rule2");
  request =
      requestReader.read(
          new GetLegendGraphicRequest(), requiredParameters, requiredParameters);
  assertTrue(request.getRules().size() == 2);
}

代码示例来源:origin: org.geoserver/gs-wms

@org.junit.Test
public void testLayerGroup() throws Exception {
  GetLegendGraphicRequest request;
  request =
      requestReader.read(
          new GetLegendGraphicRequest(), requiredParameters, requiredParameters);
  assertTrue(request.getLayers().size() == 1);
  requiredParameters.put("LAYER", NATURE_GROUP);
  request =
      requestReader.read(
          new GetLegendGraphicRequest(), requiredParameters, requiredParameters);
  assertTrue(request.getLayers().size() > 1);
}

代码示例来源:origin: org.geoserver/gs-wms

@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());
}

代码示例来源:origin: org.geoserver/gs-wms

@org.junit.Test
public void testLanguage() throws Exception {
  GetLegendGraphicRequest request;
  request =
      requestReader.read(
          new GetLegendGraphicRequest(), requiredParameters, requiredParameters);
  assertNull(request.getLocale());
  request = requestReader.read(new GetLegendGraphicRequest(), allParameters, allParameters);
  assertEquals(Locale.ENGLISH, request.getLocale());
}

代码示例来源:origin: org.geoserver.extension/monitor-core

@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));
}

代码示例来源:origin: org.geoserver/gs-wms

@org.junit.Test
  public void testLabelsForLayerGroup() throws Exception {
    GetLegendGraphicRequest request;

    requiredParameters.put("LAYER", NATURE_GROUP);
    request =
        requestReader.read(
            new GetLegendGraphicRequest(), requiredParameters, requiredParameters);
    assertNotNull(request.getTitle(new NameImpl("http://www.opengis.net/cite", "Lakes")));
  }
}

代码示例来源:origin: org.geoserver.extension/gs-monitor-core

@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));
}

代码示例来源:origin: org.geoserver/gs-wms

@org.junit.Test
public void testMissingLayerParameter() throws Exception {
  requiredParameters.remove("LAYER");
  try {
    requestReader.read(
        new GetLegendGraphicRequest(), requiredParameters, requiredParameters);
    fail("Expected ServiceException");
  } catch (ServiceException e) {
    assertEquals("LayerNotDefined", e.getCode());
  }
}

代码示例来源:origin: org.geoserver/gs-wms

@org.junit.Test
public void testMissingFormatParameter() throws Exception {
  requiredParameters.remove("FORMAT");
  try {
    requestReader.read(
        new GetLegendGraphicRequest(), requiredParameters, requiredParameters);
    fail("Expected ServiceException");
  } catch (ServiceException e) {
    assertEquals("MissingFormat", e.getCode());
  }
}

代码示例来源:origin: org.geoserver/gs-wms

/** Tests that symbols relative sizes are proportional. */
@org.junit.Test
public void testProportionalSymbolsLine() throws Exception {
  GetLegendGraphicRequest req = new GetLegendGraphicRequest();
  FeatureTypeInfo ftInfo =
      getCatalog()
          .getFeatureTypeByName(
              MockData.MPOINTS.getNamespaceURI(),
              MockData.MPOINTS.getLocalPart());
  req.setLayer(ftInfo.getFeatureType());
  req.setStyle(readSLD("ProportionalSymbolsLine.sld"));
  BufferedImage image = this.legendProducer.buildLegendGraphic(req);
  assertNotBlank("ProportionalSymbolsLine", image, LegendUtils.DEFAULT_BG_COLOR);
  // biggest symbol, thick border
  assertPixel(image, 1, 1, new Color(255, 255, 255)); // outside
  assertPixel(image, 5, 5, new Color(0, 0, 0)); // border
  assertPixel(image, 7, 12, new Color(255, 0, 0)); // inside
  // second symbol, small, no border
  assertPixel(image, 1, 21, new Color(255, 255, 255)); // outside
  assertPixel(image, 5, 25, new Color(255, 255, 255)); // small, still outside
  assertPixel(image, 10, 30, new Color(255, 0, 0)); // inside
}

代码示例来源:origin: org.geoserver/gs-wms

/** 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));
}

代码示例来源:origin: org.geoserver/gs-wms

/** Tests that symbols relative sizes are proportional. */
@org.junit.Test
public void testProportionalSymbolThickBorder() throws Exception {
  GetLegendGraphicRequest req = new GetLegendGraphicRequest();
  FeatureTypeInfo ftInfo =
      getCatalog()
          .getFeatureTypeByName(
              MockData.MPOINTS.getNamespaceURI(),
              MockData.MPOINTS.getLocalPart());
  req.setLayer(ftInfo.getFeatureType());
  req.setStyle(readSLD("ProportionalSymbolsThickBorder.sld"));
  BufferedImage image = this.legendProducer.buildLegendGraphic(req);
  assertNotBlank(
      "testProportionalSymbolSizeThickBorder", image, LegendUtils.DEFAULT_BG_COLOR);
  // biggest symbol, thick border
  assertPixel(image, 1, 1, new Color(255, 255, 255)); // outside
  assertPixel(image, 5, 5, new Color(0, 0, 0)); // border
  assertPixel(image, 10, 10, new Color(255, 0, 0)); // inside
  // second symbol, small, no border
  assertPixel(image, 1, 21, new Color(255, 255, 255)); // outside
  assertPixel(image, 5, 25, new Color(255, 255, 255)); // small, still outside
  assertPixel(image, 10, 30, new Color(255, 0, 0)); // inside
}

代码示例来源:origin: org.geoserver/gs-wms

/** 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));
}

代码示例来源:origin: org.geoserver/gs-wms

/** Tests that symbols relative sizes are proportional. */
@org.junit.Test
public void testThickPolygonBorder() 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("ThickBorder.sld"));
  BufferedImage image = this.legendProducer.buildLegendGraphic(req);
  assertNotBlank("testThickPolygonBorder", image, LegendUtils.DEFAULT_BG_COLOR);
  // thick symbol, there is padding, black thick border, and center
  assertPixel(image, 1, 1, new Color(255, 255, 255));
  assertPixel(image, 6, 6, new Color(0, 0, 0));
  assertPixel(image, 10, 10, new Color(255, 0, 0));
  // second symbol, padding, border, green center
  assertPixel(image, 1, 21, new Color(255, 255, 255));
  // assertPixel(image, 4, 25, new Color(0, 0, 0)); // unsafe, the border is thin here
  assertPixel(image, 10, 30, new Color(0, 255, 0));
}

代码示例来源:origin: org.geoserver/gs-wms

/**
 * Tests that symbols are not bigger than the requested icon size, also if an expression is used
 * for the symbol Size.
 */
@org.junit.Test
public void testSymbolContainedInIconUsingExpression() throws Exception {
  GetLegendGraphicRequest req = new GetLegendGraphicRequest();
  FeatureTypeInfo ftInfo =
      getCatalog()
          .getFeatureTypeByName(
              MockData.MPOINTS.getNamespaceURI(),
              MockData.MPOINTS.getLocalPart());
  req.setLayer(ftInfo.getFeatureType());
  req.setStyle(readSLD("SymbolExpression.sld"));
  BufferedImage image = this.legendProducer.buildLegendGraphic(req);
  assertNotBlank(
      "testSymbolContainedInIconUsingExpression", image, LegendUtils.DEFAULT_BG_COLOR);
  // background at borders
  assertPixel(image, 1, 20, new Color(255, 255, 255));
  // symbol in the center (second symbol, the first one is attribute dependent and would not
  // be drawn normally)
  assertPixel(image, 10, 30, new Color(255, 0, 0));
}

代码示例来源:origin: org.geoserver/gs-wms

/** 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);
}

代码示例来源:origin: org.geoserver/gs-wms

/** Tests that symbols relative sizes are proportional. */
@org.junit.Test
public void testLargeCirclePlacement() throws Exception {
  GetLegendGraphicRequest req = new GetLegendGraphicRequest();
  req.setWidth(48);
  req.setHeight(25);
  FeatureTypeInfo ftInfo =
      getCatalog()
          .getFeatureTypeByName(
              MockData.MPOINTS.getNamespaceURI(),
              MockData.MPOINTS.getLocalPart());
  req.setLayer(ftInfo.getFeatureType());
  req.setStyle(readSLD("largeCircle.sld"));
  BufferedImage image = this.legendProducer.buildLegendGraphic(req);
  assertNotBlank("largeCircle", image, LegendUtils.DEFAULT_BG_COLOR);
  // the border is visible both top middle and bottom middle. Different JDK
  // build wildly different colors for the border unfortunately, so the test
  // checks that pixels at top/middle bottom/middle are similar color (they used to be
  // different, significantly)
  Color colorTop = getPixelColor(image, 24, 0);
  Color colorBottom = getPixelColor(image, 24, 24);
  assertColorSimilar(colorTop, colorBottom, 20);
}

代码示例来源:origin: org.geoserver/gs-wms

/**
 * 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 */

相关文章