Package org.mapfish.print.attribute.map.MapAttribute

Examples of org.mapfish.print.attribute.map.MapAttribute.MapAttributeValues


                if (map == null) {
                    throw new UnsupportedOperationException("Template '" + name + "' contains "
                                                            + "no map configuration.");
                }
               
                MapAttributeValues mapValues = map.createValue(template);
                json.key("map");
                json.object();
                {
                    json.key("width").value(mapValues.getMapSize().width);
                    json.key("height").value(mapValues.getMapSize().height);
                }
                json.endObject();
               
                // get the zoom levels and dpi values from the first template
                if (maxDpi == null) {
                    maxDpi = map.getMaxDpi();
                    dpiSuggestions = map.getDpiSuggestions();
                }
                if (zoomLevels == null) {
                    zoomLevels = mapValues.getZoomLevels();
                }
            }
            json.endObject();
        }
        json.endArray();
View Full Code Here


    @SuppressWarnings("unchecked")
    @Override
    public final Output execute(final Input values, final ExecutionContext context) throws Exception {

        final MapAttributeValues map = values.map;
        final PagingAttribute.PagingProcessorValues paging = values.paging;
        CoordinateReferenceSystem projection = map.getMapBounds().getProjection();
        final Rectangle paintArea = new Rectangle(map.getMapSize());
        final double dpi = map.getRequestorDPI();
        final DistanceUnit projectionUnit = DistanceUnit.fromProjection(projection);

        AreaOfInterest areaOfInterest = map.areaOfInterest;
        if (areaOfInterest == null) {
            areaOfInterest = new AreaOfInterest();
            areaOfInterest.display = AreaOfInterest.AoiDisplay.NONE;
            ReferencedEnvelope mapBBox = map.getMapBounds().toReferencedEnvelope(paintArea, dpi);

            areaOfInterest.setPolygon((Polygon) this.geometryFactory.toGeometry(mapBBox));
        }

        Envelope aoiBBox = areaOfInterest.getArea().getEnvelopeInternal();

        final double paintAreaWidthIn = paintArea.getWidth() * paging.scale / dpi;
        final double paintAreaHeightIn = paintArea.getHeight() * paging.scale / dpi;

        final double paintAreaWidth = DistanceUnit.IN.convertTo(paintAreaWidthIn, projectionUnit);
        final double paintAreaHeight = DistanceUnit.IN.convertTo(paintAreaHeightIn, projectionUnit);

        final int nbWidth = (int) Math.ceil(aoiBBox.getWidth() / (paintAreaWidth - paging.overlap));
        final int nbHeight = (int) Math.ceil(aoiBBox.getHeight() / (paintAreaHeight - paging.overlap));

        final double marginWidth = (paintAreaWidth * nbWidth - aoiBBox.getWidth()) / 2;
        final double marginHeight = (paintAreaHeight * nbHeight - aoiBBox.getHeight()) / 2;

        final double minX = aoiBBox.getMinX() - marginWidth - paging.overlap / 2;
        final double minY = aoiBBox.getMinY() - marginHeight - paging.overlap / 2;

        LOGGER.info("Paging generate a grid of " + nbWidth + "x" + nbHeight + " potential maps.");
        final int[][] mapIndexes = new int[nbWidth][nbHeight];
        final Envelope[][] mapsBounds = new Envelope[nbWidth][nbHeight];
        int mapIndex = 0;

        for (int j = 0; j < nbHeight; j++) {
            for (int i = 0; i < nbWidth; i++) {
                final double x1 = minX + i * (paintAreaWidth - paging.overlap);
                final double x2 = x1 + paintAreaWidth;
                final double y1 = minY + j * (paintAreaHeight - paging.overlap);
                final double y2 = y1 + paintAreaHeight;
                Coordinate[] coords  = new Coordinate[] {
                        new Coordinate(x1, y1),
                        new Coordinate(x1, y2),
                        new Coordinate(x2, y2),
                        new Coordinate(x2, y1),
                        new Coordinate(x1, y1)
                };

                LinearRing ring = this.geometryFactory.createLinearRing(coords);
                final Polygon bbox = this.geometryFactory.createPolygon(ring);

                if (areaOfInterest.getArea().intersects(bbox)) {
                    mapsBounds[i][j] = bbox.getEnvelopeInternal();
                    mapIndexes[i][j] = mapIndex;
                    mapIndex++;
                } else {
                    mapIndexes[i][j] = DO_NOT_RENDER_BBOX_INDEX;
                }
            }
        }

        final List<Map<String, Object>> mapList = Lists.newArrayList();

        for (int j = 0; j < nbHeight; j++) {
            for (int i = 0; i < nbWidth; i++) {
                if (mapIndexes[i][j] != DO_NOT_RENDER_BBOX_INDEX) {
                    Map<String, Object> mapValues = new HashMap<String, Object>();
                    mapValues.put("name", mapIndexes[i][j]);
                    mapValues.put("left", i != 0 ? mapIndexes[i - 1][j] : DO_NOT_RENDER_BBOX_INDEX);
                    mapValues.put("bottom", j != 0 ? mapIndexes[i][j - 1] : DO_NOT_RENDER_BBOX_INDEX);
                    mapValues.put("right", i != nbWidth - 1 ? mapIndexes[i + 1][j] : DO_NOT_RENDER_BBOX_INDEX);
                    mapValues.put("top", j != nbHeight - 1 ? mapIndexes[i][j + 1] : DO_NOT_RENDER_BBOX_INDEX);

                    final Coordinate center = mapsBounds[i][j].centre();
                    MapAttributeValues theMap = map.copy(map.getMapSize(), new Function<MapAttributeValues, Void>() {
                        @Nullable
                        @Override
                        public Void apply(@Nonnull final MapAttributeValues input) {
                            input.center = new double[]{center.x, center.y};
                            input.scale = paging.scale;
View Full Code Here

    public void testRender() throws Exception {
        MapAttribute mapAttribute = new MapAttribute();
        mapAttribute.setWidth(780);
        mapAttribute.setHeight(330);
        mapAttribute.setMaxDpi(600.0);
        MapAttributeValues mapParams = mapAttribute.createValue(null);
        mapParams.dpi = 72;
        mapParams.center = new double[]{-8235878.4938425, 4979784.7605681};
        mapParams.scale = 26000.0;
        mapParams.layers = new PJsonArray(null, new JSONArray(), "");
        mapParams.postConstruct();

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

    public void testRenderDoubleDpi() throws Exception {
        MapAttribute mapAttribute = new MapAttribute();
        mapAttribute.setWidth(780);
        mapAttribute.setHeight(330);
        mapAttribute.setMaxDpi(600.0);
        MapAttributeValues mapParams = mapAttribute.createValue(null);
        // use a dpi of 144, this will create a scale bar graphic of 600x80 px
        mapParams.dpi = 144;
        mapParams.center = new double[]{-8235878.4938425, 4979784.7605681};
        mapParams.scale = 26000.0;
        mapParams.layers = new PJsonArray(null, new JSONArray(), "");
        mapParams.postConstruct();

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

    public void testRenderSvg() throws Exception {
        MapAttribute mapAttribute = new MapAttribute();
        mapAttribute.setWidth(780);
        mapAttribute.setHeight(330);
        mapAttribute.setMaxDpi(600.0);
        MapAttributeValues mapParams = mapAttribute.createValue(null);
        mapParams.dpi = 72;
        mapParams.center = new double[]{-8235878.4938425, 4979784.7605681};
        mapParams.scale = 26000.0;
        mapParams.layers = new PJsonArray(null, new JSONArray(), "");
        mapParams.postConstruct();

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

TOP

Related Classes of org.mapfish.print.attribute.map.MapAttribute.MapAttributeValues

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.