use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.
the class LegendSizeTest method testPolygonStyle.
@Test
public void testPolygonStyle() {
final MapLayer layer = MapBuilder.createEmptyMapLayer();
layer.setStyle(SF.style(StyleConstants.DEFAULT_POLYGON_SYMBOLIZER));
final MapLayers ctx = MapBuilder.createContext();
ctx.getComponents().add(layer);
Dimension dim = DefaultLegendService.legendPreferredSize(null, ctx);
assertEquals(30, dim.width);
assertEquals(24, dim.height);
// test with an empty template
dim = DefaultLegendService.legendPreferredSize(NO_MARGIN_TEMPLATE, ctx);
assertEquals(30, dim.width);
assertEquals(24, dim.height);
}
use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.
the class LegendSizeTest method testRecursiveStyle.
@Test
public void testRecursiveStyle() {
// Polygon layer, glyph size : w30, h24
final MapLayer leaf1 = MapBuilder.createEmptyMapLayer();
leaf1.setStyle(SF.style(StyleConstants.DEFAULT_POLYGON_SYMBOLIZER));
final MapLayer leaf2 = MapBuilder.createEmptyMapLayer();
leaf2.setStyle(SF.style(StyleConstants.DEFAULT_RASTER_SYMBOLIZER));
final MapLayers node1 = MapBuilder.createItem();
node1.setIdentifier("bouh");
node1.getComponents().add(leaf1);
node1.getComponents().add(leaf2);
final MapLayers node2 = MapBuilder.createItem();
node2.getComponents().add(leaf1);
final MapLayers context = MapBuilder.createContext();
context.getComponents().add(node1);
context.getComponents().add(node2);
Dimension dim = DefaultLegendService.legendPreferredSize(NO_MARGIN_TEMPLATE, context);
// We've got 3 glyph vertically aligned, no margin, no title and no insets between them.
final int glyphHeight = 24;
final int glyphWidth = 30;
assertEquals(glyphWidth, dim.width);
assertEquals(glyphHeight * 3, dim.height);
// A new template to test legend estimation using titles and left insets to reflect tree structure.
final int leftInset = 10;
final DefaultBackgroundTemplate backTemplate = new DefaultBackgroundTemplate(new BasicStroke(0), Color.BLACK, Color.RED, new Insets(0, leftInset, 0, 0), 0);
final LegendTemplate titleTemplate = new DefaultLegendTemplate(backTemplate, NO_MARGIN_TEMPLATE.getGapSize(), NO_MARGIN_TEMPLATE.getGlyphSize(), NO_MARGIN_TEMPLATE.getRuleFont(), true, NO_MARGIN_TEMPLATE.getLayerFont(), true);
// Same test than above, but here we've got titles and left insets.
dim = DefaultLegendService.legendPreferredSize(titleTemplate, context);
// Get text pixel size.
final BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
final Graphics2D g2d = img.createGraphics();
final FontMetrics font = g2d.getFontMetrics(titleTemplate.getLayerFont());
final int fontHeight = font.getHeight();
final int fontWidth = font.stringWidth(node1.getIdentifier());
final int gap = (int) titleTemplate.getGapSize();
final int legendHeight = // node1
// title
fontHeight + gap + glyphHeight + // leaf1
gap + glyphHeight + // leaf2
gap + // node2
glyphHeight;
/* Inset multiply 3 times because :
* <-Inset->MapContext
* <-Inset->node1
* <-Inset->leaf1
* ...
*/
final int legendWidth = leftInset * 3 + Math.max(fontWidth, glyphWidth);
assertEquals("Legend width", legendWidth, dim.width);
assertEquals("Legend height", legendHeight, dim.height);
}
use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.
the class LegendSizeTest method testNoStyle.
@Test
public void testNoStyle() {
final MapLayer layer = MapBuilder.createEmptyMapLayer();
layer.setStyle(SF.style());
final MapLayers ctx = MapBuilder.createContext();
ctx.getComponents().add(layer);
Dimension dim = DefaultLegendService.legendPreferredSize(null, ctx);
assertEquals(1, dim.width);
assertEquals(1, dim.height);
// test with an empty template
dim = DefaultLegendService.legendPreferredSize(NO_MARGIN_TEMPLATE, ctx);
assertEquals(1, dim.width);
assertEquals(1, dim.height);
}
use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.
the class LegendSizeTest method testRasterLegend.
@Test
public void testRasterLegend() {
final Symbolizer dr = StyleConstants.DEFAULT_RASTER_SYMBOLIZER;
final MapLayer layer = MapBuilder.createEmptyMapLayer();
layer.setStyle(SF.style(dr));
final MapLayers ctx = MapBuilder.createContext();
ctx.getComponents().add(layer);
Dimension dim = DefaultLegendService.legendPreferredSize(null, ctx);
assertEquals(30, dim.width);
assertEquals(24, dim.height);
// test with an empty template
dim = DefaultLegendService.legendPreferredSize(NO_MARGIN_TEMPLATE, ctx);
assertEquals(30, dim.width);
assertEquals(24, dim.height);
}
use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.
the class OwcXmlIO method findItem.
private static MapItem findItem(MapLayers parent, String name) {
for (MapItem mi : parent.getComponents()) {
if (mi.getIdentifier().equals(name)) {
return mi;
}
}
// does not exist, create it
final MapLayers np = MapBuilder.createItem();
parent.getComponents().add(np);
return np;
}
Aggregations