Search in sources :

Example 31 with MapLayers

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);
}
Also used : MapLayer(org.apache.sis.portrayal.MapLayer) Dimension(java.awt.Dimension) MapLayers(org.apache.sis.portrayal.MapLayers) Test(org.junit.Test)

Example 32 with MapLayers

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);
}
Also used : BasicStroke(java.awt.BasicStroke) DefaultBackgroundTemplate(org.geotoolkit.display2d.ext.DefaultBackgroundTemplate) Insets(java.awt.Insets) FontMetrics(java.awt.FontMetrics) MapLayer(org.apache.sis.portrayal.MapLayer) Dimension(java.awt.Dimension) BufferedImage(java.awt.image.BufferedImage) MapLayers(org.apache.sis.portrayal.MapLayers) Graphics2D(java.awt.Graphics2D) Test(org.junit.Test)

Example 33 with MapLayers

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);
}
Also used : MapLayer(org.apache.sis.portrayal.MapLayer) Dimension(java.awt.Dimension) MapLayers(org.apache.sis.portrayal.MapLayers) Test(org.junit.Test)

Example 34 with MapLayers

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);
}
Also used : MapLayer(org.apache.sis.portrayal.MapLayer) Dimension(java.awt.Dimension) Symbolizer(org.opengis.style.Symbolizer) MapLayers(org.apache.sis.portrayal.MapLayers) Test(org.junit.Test)

Example 35 with MapLayers

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;
}
Also used : MapItem(org.apache.sis.portrayal.MapItem) MapLayers(org.apache.sis.portrayal.MapLayers)

Aggregations

MapLayers (org.apache.sis.portrayal.MapLayers)104 Dimension (java.awt.Dimension)61 BufferedImage (java.awt.image.BufferedImage)57 Test (org.junit.Test)57 MapLayer (org.apache.sis.portrayal.MapLayer)51 GeneralEnvelope (org.apache.sis.geometry.GeneralEnvelope)47 Rectangle (java.awt.Rectangle)26 CanvasDef (org.geotoolkit.display2d.service.CanvasDef)26 SceneDef (org.geotoolkit.display2d.service.SceneDef)26 GridGeometry (org.apache.sis.coverage.grid.GridGeometry)22 Coordinate (org.locationtech.jts.geom.Coordinate)17 GridCoverage (org.apache.sis.coverage.grid.GridCoverage)16 MutableStyle (org.geotoolkit.style.MutableStyle)16 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)16 Graphics2D (java.awt.Graphics2D)15 SampleDimension (org.apache.sis.coverage.SampleDimension)15 Feature (org.opengis.feature.Feature)14 FeatureType (org.opengis.feature.FeatureType)14 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)13 FeatureSet (org.apache.sis.storage.FeatureSet)13