Package org.mapfish.print.attribute.map

Examples of org.mapfish.print.attribute.map.MapfishMapContext


                             final MapfishMapContext transformer,
                             final boolean isFirstLayer) {
        Rectangle paintArea = new Rectangle(transformer.getMapSize());
        MapBounds bounds = transformer.getBounds();

        MapfishMapContext layerTransformer = transformer;
        if (transformer.getRotation() != 0.0 && !this.supportsNativeRotation()) {
            // if a rotation is set and the rotation can not be handled natively
            // by the layer, we have to adjust the bounds and map size
            paintArea = new Rectangle(transformer.getRotatedMapSize());
            bounds = transformer.getRotatedBounds();
            graphics2D.setTransform(transformer.getTransform());
            Dimension mapSize = new Dimension(paintArea.width, paintArea.height);
            layerTransformer = new MapfishMapContext(bounds, mapSize, transformer.getRotation(), transformer.getDPI(),
                    transformer.getRequestorDPI(), transformer.isForceLongitudeFirst(), transformer.isDpiSensitiveStyle());
        }


        MapContent content = new MapContent();
View Full Code Here


    private List<URI> createLayerGraphics(final File printDirectory,
                                          final MfClientHttpRequestFactory clientHttpRequestFactory,
                                          final MapAttribute.MapAttributeValues mapValues,
                                          final ExecutionContext context)
            throws Exception {
        final MapfishMapContext transformer = createMapContext(mapValues);

        // reverse layer list to draw from bottom to top.  normally position 0 is top-most layer.
        final List<MapLayer> layers = Lists.reverse(Lists.newArrayList(mapValues.getLayers()));

        final AreaOfInterest areaOfInterest = addAreaOfInterestLayer(mapValues, layers);

        final String mapKey = UUID.randomUUID().toString();
        final List<URI> graphics = new ArrayList<URI>(layers.size());
        int i = 0;
        for (MapLayer layer : layers) {
            checkCancelState(context);
            boolean isFirstLayer = i == 0;

            File path = null;
            if (renderAsSvg(layer)) {
                // render layer as SVG
                final SVGGraphics2D graphics2D = getSvgGraphics(transformer.getMapSize());

                try {
                    Graphics2D clippedGraphics2D = createClippedGraphics(transformer, areaOfInterest, graphics2D);
                    layer.render(clippedGraphics2D, clientHttpRequestFactory, transformer, isFirstLayer);

                    path = new File(printDirectory, mapKey + "_layer_" + i + ".svg");
                    saveSvgFile(graphics2D, path);
                } finally {
                    graphics2D.dispose();
                }
            } else {
                // render layer as raster graphic
                final BufferedImage bufferedImage = new BufferedImage(transformer.getMapSize().width,
                        transformer.getMapSize().height, this.imageType.value);
                Graphics2D graphics2D = createClippedGraphics(transformer, areaOfInterest, bufferedImage.createGraphics());
                try {
                    layer.render(graphics2D, clientHttpRequestFactory, transformer, isFirstLayer);

                    path = new File(printDirectory, mapKey + "_layer_" + i + ".png");
View Full Code Here

        // if the DPI is higher than the PDF DPI we need to make the image larger so the image put in the PDF is large enough for the
        // higher DPI printer
        final double dpiRatio = dpi / dpiOfRequestor;
        paintArea.setBounds(0, 0, (int) (mapSize.getWidth() * dpiRatio), (int) (mapSize.getHeight() * dpiRatio));
        return new MapfishMapContext(bounds, paintArea.getSize(),
                mapValues.getRotation(), dpi, mapValues.getRequestorDPI(), mapValues.longitudeFirst, mapValues.isDpiSensitiveStyle());
    }
View Full Code Here

        Configuration config = new Configuration();
        config.setConfigurationFile(getFile(styleJsonFileName));
        final String styleJson = getSpec(styleJsonFileName);

        final CenterScaleMapBounds bounds = new CenterScaleMapBounds(CRS.decode("CRS:84"), 0, 0, new Scale(300000));
        MapfishMapContext context = new MapfishMapContext(bounds, new Dimension(500, 500), 0, 72, Constants.PDF_DPI, null, true);
        final Optional<Style> styleOptional = mapfishJsonStyleParserPlugin.parseStyle(config, httpClient, styleJson, context);

        assertTrue(styleOptional.isPresent());

        return styleOptional.get();
View Full Code Here

        Values values = new Values(requestData, template, parser, this.folder.getRoot(), this.httpClientFactory, new File("."));
        forkJoinPool.invoke(template.getProcessorGraph().createTask(values));

        final MapAttribute.MapAttributeValues map = values.getObject("mapDef", MapAttribute.MapAttributeValues.class);
        final AbstractFeatureSourceLayer layer = (AbstractFeatureSourceLayer) map.getLayers().get(0);
        final MapfishMapContext mapContext = AbstractMapfishSpringTest.createTestMapContext();
        assertEquals("Default Line",
                layer.getLayers(httpClientFactory, mapContext, true).get(0).getStyle().getDescription().getTitle().toString());
    }
View Full Code Here

        MapBounds bounds = new BBoxMapBounds(DefaultEngineeringCRS.GENERIC_2D, 100, 100, 140, 140);
        Dimension mapSize = new Dimension(400, 400);
        double rotation = 0;
        double dpi = 72;
        MapfishMapContext context = new MapfishMapContext(bounds, mapSize, rotation, dpi, Constants.PDF_DPI, null, true);
        final List<? extends Layer> layers = layer.getLayers(null, context, true);
        assertEquals(1, layers.size());

        FeatureSource<?, ?> fs = layers.get(0).getFeatureSource();
        assertNotNull(layers.get(0).getStyle());
View Full Code Here

        MapBounds bounds = new BBoxMapBounds(DefaultEngineeringCRS.GENERIC_2D, 110, 90, 150, 132);
        Dimension mapSize = new Dimension(400, 400);
        double rotation = 0;
        double dpi = 72;
        MapfishMapContext context = new MapfishMapContext(bounds, mapSize, rotation, dpi, Constants.PDF_DPI, null, true);
        final List<? extends Layer> layers = layer.getLayers(null, context, true);
        assertEquals(1, layers.size());

        FeatureSource<?, ?> fs = layers.get(0).getFeatureSource();
        assertNotNull(layers.get(0).getStyle());
View Full Code Here

    }

    private void assertRoundedScale(double actualScale, double roundedScale) {
        MapBounds bounds = new CenterScaleMapBounds(DefaultGeographicCRS.WGS84, 0, 0, new Scale(actualScale));
        Dimension paint = new Dimension(200, 200);
        MapfishMapContext transformer = new MapfishMapContext(bounds, paint, 90, Constants.PDF_DPI, Constants.PDF_DPI, null, true);
        assertEquals(roundedScale, transformer.getRoundedScale(), 0.00001);
    }
View Full Code Here

        assertEquals(roundedScale, transformer.getRoundedScale(), 0.00001);
    }

    @Test
    public void testGetRotation() {
        MapfishMapContext transformer = new MapfishMapContext(null, null, 90, Constants.PDF_DPI, Constants.PDF_DPI, null, true);
        assertEquals("converted to radians", Math.toRadians(90.0), transformer.getRotation(), 1e-9);
    }
View Full Code Here

    @Test
    public void testGetRotatedBounds_BBoxMapBounds() {
        MapBounds bounds = new BBoxMapBounds(DefaultGeographicCRS.WGS84, 5, 45, 25, 55);
       
        // rotate 90 degree
        MapfishMapContext transformer = new MapfishMapContext(bounds, null, 90, Constants.PDF_DPI, Constants.PDF_DPI, null, true);
        MapBounds rotatedBounds = new BBoxMapBounds(DefaultGeographicCRS.WGS84, 10, 40, 20, 60);
        assertEquals(rotatedBounds, transformer.getRotatedBounds());

        // rotate 180 degree
        transformer = new MapfishMapContext(bounds, null, 180, Constants.PDF_DPI, Constants.PDF_DPI, null, true);
        rotatedBounds = new BBoxMapBounds(DefaultGeographicCRS.WGS84, 5, 45, 25, 55);
        assertEquals(rotatedBounds, transformer.getRotatedBounds());

        // rotate 45 degree
        transformer = new MapfishMapContext(bounds, null, 45, Constants.PDF_DPI, Constants.PDF_DPI, null, true);
        ReferencedEnvelope rotatedEnvelope =
                transformer.getRotatedBounds().toReferencedEnvelope(new Rectangle(1, 1), 72);
        assertEquals(4.393398, rotatedEnvelope.getMinX(), 1e-6);
        assertEquals(25.606601, rotatedEnvelope.getMaxX(), 1e-6);
        assertEquals(39.393398, rotatedEnvelope.getMinY(), 1e-6);
        assertEquals(60.606601, rotatedEnvelope.getMaxY(), 1e-6);

        // rotate 45 degree
        bounds = new BBoxMapBounds(DefaultGeographicCRS.WGS84, -0.5, -0.5, 0.5, 0.5);
        transformer = new MapfishMapContext(bounds, null, 45, Constants.PDF_DPI, Constants.PDF_DPI, null, true);
        rotatedEnvelope =
                transformer.getRotatedBounds().toReferencedEnvelope(new Rectangle(1, 1), 72);
        assertEquals(-0.707106, rotatedEnvelope.getMinX(), 1e-6);
        assertEquals(0.707106, rotatedEnvelope.getMaxX(), 1e-6);
        assertEquals(-0.707106, rotatedEnvelope.getMinY(), 1e-6);
        assertEquals(0.707106, rotatedEnvelope.getMaxY(), 1e-6);
    }
View Full Code Here

TOP

Related Classes of org.mapfish.print.attribute.map.MapfishMapContext

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.