Package org.mapfish.print.attribute.ScalebarAttribute

Examples of org.mapfish.print.attribute.ScalebarAttribute.ScalebarAttributeValues


    public void testGetSize() {
        // horizontal
        ScalebarAttribute attribute = new ScalebarAttribute();
        attribute.setWidth(180);
        attribute.setHeight(40);
        ScalebarAttributeValues params = attribute.createValue(null);
        params.labelDistance = 3;
        params.barSize = 8;
        ScaleBarRenderSettings settings = new ScaleBarRenderSettings();
        settings.setParams(params);
        settings.setDpiRatio(1.0);
View Full Code Here


        mapParams.postConstruct();

        ScalebarAttribute scalebarAttibute = new ScalebarAttribute();
        scalebarAttibute.setWidth(300);
        scalebarAttibute.setHeight(40);
        ScalebarAttributeValues scalebarParams = scalebarAttibute.createValue(null);
        scalebarParams.verticalAlign = VerticalAlign.TOP.getLabel();

        ScalebarGraphic scalebar = new ScalebarGraphic();
        URI file = scalebar.render(mapParams, scalebarParams, folder.getRoot(), this.template);
//      Files.copy(new File(file), new File("/tmp/" + getClass().getSimpleName() + "expected-scalebar-graphic.tiff"));
View Full Code Here

        mapParams.postConstruct();

        ScalebarAttribute scalebarAttibute = new ScalebarAttribute();
        scalebarAttibute.setWidth(300);
        scalebarAttibute.setHeight(40);
        ScalebarAttributeValues scalebarParams = scalebarAttibute.createValue(null);

        ScalebarGraphic scalebar = new ScalebarGraphic();
        URI file = scalebar.render(mapParams, scalebarParams, folder.getRoot(), this.template);
//      Files.copy(new File(file), new File("/tmp/" + getClass().getSimpleName() + "expected-scalebar-graphic-dpi.tiff"));
        new ImageSimilarity(new File(file), 4).assertSimilarity(getFile("expected-scalebar-graphic-dpi.tiff"), 15);
View Full Code Here

        mapParams.postConstruct();

        ScalebarAttribute scalebarAttibute = new ScalebarAttribute();
        scalebarAttibute.setWidth(300);
        scalebarAttibute.setHeight(40);
        ScalebarAttributeValues scalebarParams = scalebarAttibute.createValue(null);
        scalebarParams.verticalAlign = VerticalAlign.TOP.getLabel();
        scalebarParams.renderAsSvg = true;

        ScalebarGraphic scalebar = new ScalebarGraphic();
        URI file = scalebar.render(mapParams, scalebarParams, folder.getRoot(), this.template);
View Full Code Here

    private ScaleBarRenderSettings getSettings(final Graphics2D graphics2d, int numSubIntervals) {
        ScalebarAttribute attribute = new ScalebarAttribute();
        attribute.setWidth(180);
        attribute.setHeight(40);
        ScalebarAttributeValues params = attribute.createValue(null);
        params.labelDistance = 4;
        params.barSize = 10;
        ScaleBarRenderSettings settings = new ScaleBarRenderSettings();
        settings.setParams(params);
View Full Code Here

            LOGGER.error("layouting the scalebar failed (unit: " + scaleUnit.toString()
                    + ", scale: " + scale.getDenominator() + ")");
            return;
        }

        final ScalebarAttributeValues scalebarParams = settings.getParams();
        final DistanceUnit intervalUnit = bestUnit(scaleUnit, intervalLengthInWorldUnits, scalebarParams.lockUnits);
        final float intervalLengthInPixels = (float) scaleUnit.convertTo(
                intervalLengthInWorldUnits / scale.getDenominator(), DistanceUnit.PX);

        //compute the label positions
        final List<Label> labels = new ArrayList<Label>(scalebarParams.intervals + 1);
        final float leftLabelMargin;
        final float rightLabelMargin;
        final float topLabelMargin;
        final float bottomLabelMargin;

        final Font font = new Font(scalebarParams.font, Font.PLAIN, getFontSize(settings));
        final FontRenderContext frc = new FontRenderContext(null, true, true);

        if (scalebarParams.intervals > 1 || scalebarParams.subIntervals) {
            //the label will be centered under each tick mark
            for (int i = 0; i <= scalebarParams.intervals; i++) {
                String labelText = createLabelText(scaleUnit, intervalLengthInWorldUnits * i, intervalUnit);
                if (i == scalebarParams.intervals) {
                    // only show unit for the last label
                    labelText += intervalUnit;
                }
                TextLayout labelLayout = new TextLayout(labelText, font, frc);
                labels.add(new Label(intervalLengthInPixels * i, labelLayout, scalebarParams.getOrientation()));
            }
            leftLabelMargin = labels.get(0).getWidth() / 2.0f;
            rightLabelMargin = labels.get(labels.size() - 1).getWidth() / 2.0f;
            topLabelMargin = labels.get(0).getHeight() / 2.0f;
            bottomLabelMargin = labels.get(labels.size() - 1).getHeight() / 2.0f;
        } else {
            //if there is only one interval, place the label centered between the two tick marks
            String labelText = createLabelText(scaleUnit, intervalLengthInWorldUnits, intervalUnit) + intervalUnit;
            TextLayout labelLayout = new TextLayout(labelText, font, frc);
            final Label label = new Label(intervalLengthInPixels / 2.0f,
                    labelLayout, scalebarParams.getOrientation());
            labels.add(label);
            rightLabelMargin = Math.max(0.0f, label.getWidth() - intervalLengthInPixels) / 2.0f;
            leftLabelMargin = rightLabelMargin;
            topLabelMargin = Math.max(0.0f, label.getHeight() - intervalLengthInPixels) / 2.0f;
            bottomLabelMargin = topLabelMargin;
View Full Code Here

        assertEquals(2, validationErrors.size());
    }

    @Test
    public void testCreateValue() throws Exception {
        ScalebarAttributeValues values = getValues();
        assertEquals(new Dimension(300, 120), values.getSize());
    }
View Full Code Here

        assertEquals(new Dimension(300, 120), values.getSize());
    }

    @Test
    public void testPostConstruct() throws Exception {
        ScalebarAttributeValues values = getValues();
        values.postConstruct();
        // passes.. ok
    }
View Full Code Here

        // passes.. ok
    }

    @Test(expected=IllegalArgumentException.class)
    public void testPostConstructInvalidColor() throws Exception {
        ScalebarAttributeValues values = getValues();

        values.backgroundColor = "sun-yellow";
        values.postConstruct();
    }
View Full Code Here

        values.postConstruct();
    }

    @Test(expected=IllegalArgumentException.class)
    public void testPostConstructInvalidUnit() throws Exception {
        ScalebarAttributeValues values = getValues();

        values.unit = "light-years";
        values.postConstruct();
    }
View Full Code Here

TOP

Related Classes of org.mapfish.print.attribute.ScalebarAttribute.ScalebarAttributeValues

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.