MapFish Print

repository·master·Indexed 41 days ago

https://github.com/mapfish/mapfish-print

A tool for generating map prints from configuration files and request specifications. It can be deployed as a standalone application, a servlet, or within a Dockerized environment, and supports generating outputs such as PDFs and images.

Tokens
4.4K
Snippets
18
Records
25
Agent score
52%

What's inside MapFish Print

  1. Identify available GeoServer sample data sets

    master

    The examples/geoserver-data directory contains a pre-packaged GeoServer data directory used for demonstrations and testing. This directory includes several distinct spatial data sets that can be used to test Mapfish Print capabilities with different data types (vector, raster, mosaics, etc.).

    Available data sets include:

    • arc_sample: Provided by GeoSolutions.
    • img_sample: Provided by GeoSolutions.
    • mosaic_sample: Provided by GeoSolutions.
    • nyc: New York City data containing giant polygons, POIs, poly landmarks, and TIGER roads.
    • sf: Spearfish data containing archsites, bugsites, restricted areas, roads, streams, and sfdem.
    • states: Simplified shapefiles derived from GeoTools sample data (Census data).
    • taz_shapes: Tasmania data containing cities, roads, state boundaries, and water bodies.
  2. File structure for acceptance tests

    master

    Acceptance tests follow a specific directory pattern for loading configuration, request data, and expected outputs. Replace <tested_application> with the specific application name being tested.

    • Application Config: src/test/resources/examples/<tested_application>/config.yaml
    • Spec Files (JSON): src/test/resources/examples/<tested_application>/requestData<postfix>.json
    • Expected Output Images: src/test/resources/examples/<tested_application>/expected_output/requestData<postfix>.png
    • Mask Images (Optional): src/test/resources/examples/<tested_application>/expected_output/mask-requestData<postfix>.png

    Note on Mask Images: Mask images must be grayscale containing only full black and full white pixel values. Avoid using indexed color modes (e.g., in Gimp) as the Java implementation may interpret pixel values incorrectly (e.g., reading 1 instead of 0 for black pixels).

  3. Run MapFish Print integration tests

    master

    To run the end-to-end (e2e) integration tests for PDF and image generation, you must first start the required services (including a GeoServer instance) using Docker Compose, and then execute the Gradle test task.

    1. Start the services:
      docker compose up -d
    2. Run the tests using Gradle (refer to the Gradle Java plugin documentation for specific test subgroups or single test execution).
    docker compose up -d
  4. Run MapFish Print in Eclipse

    master

    To run the printer directly from Eclipse, create a new Java Run Configuration with the following settings:

    • Main class: org.mapfish.print.cli.Main
    • Program arguments: Pass the -config, -spec, and -output flags (e.g., -config samples/config.yaml -spec samples/spec.json -output $HOME/print.pdf).
  5. Build MapFish Print

    master

    To build the project from source, ensure you have make and Docker installed. Running the build command generates three primary artifacts:

    • print-servlet-xxx.war (Servlet container deployment)
    • print-lib.jar (Library for integration)
    • print-standalone.jar (Standalone executable)

    Note: The build process includes tests that require the 'Liberation Sans' font to be installed on your system.

    make build
  6. Run MapFish Print examples using Docker and GeoServer

    master

    For examples that depend on GeoServer, you must run them within the provided Docker composition.

    1. Build the project and prepare the override configuration.
    2. Start the composition.
    3. Execute the print command inside the builder container.
    # Setup the environment
    make build
    cp docker-compose.override.sample.yaml docker-compose.override.yaml
    make acceptance-tests-up
    
    # Execute the print job inside the running container
    docker compose exec builder gradle print -PprintArgs="-config /src/examples/src/test/resources/examples/simple/config.yaml -spec /src/examples/src/test/resources/examples/simple/requestData.json -output /src/examples/output.pdf"
  7. Run acceptance tests via Make

    master

    In CI environments or when using the provided Makefile, you can manage the acceptance test lifecycle using the following commands:

    Standard Acceptance Tests

    • Start server: make acceptance-tests-up
    • Run tests: make acceptance-tests-run
    • Stop server: make acceptance-tests-down

    Cluster Mode (Single instance with PostgreSQL)

    Use the DOCKER_COMPOSE_ARGS environment variable to point to the cluster configuration:

    • Start: DOCKER_COMPOSE_ARGS=--file=docker-compose-cluster.yaml make acceptance-tests-up
    • Run: DOCKER_COMPOSE_ARGS=--file=docker-compose-cluster.yaml make acceptance-tests-run
    • Stop: DOCKER_COMPOSE_ARGS=--file=docker-compose-cluster.yaml make acceptance-tests-down

    Context Path Tests

    • Start: DOCKER_COMPOSE_ARGS=--file=docker-compose-context-path.yaml make acceptance-tests-up
    • Run: DOCKER_COMPOSE_ARGS=--file=docker-compose-context-path.yaml make acceptance-tests-run-context-path
    • Stop: DOCKER_COMPOSE_ARGS=--file=docker-compose-context-path.yaml make acceptance-tests-down
    # Example: Running cluster mode tests
    DOCKER_COMPOSE_ARGS=--file=docker-compose-cluster.yaml make acceptance-tests-run
  8. Run MapFish Print in non-daemon mode for IDE development

    master

    By default, the test server runs in daemon mode (background thread, shuts down when the build completes). To run the server in non-daemon mode—allowing you to manually start the server and then run tests from an IDE like Eclipse—use:

    docker compose up -d
  9. Update the online documentation on GitHub Pages

    master

    After building the documentation locally using ./gradlew buildDocs, you can update the hosted documentation by pushing the contents of docs/build/site to the gh-pages branch of the mapfish-print-doc repository.

    Follow these steps to sync and deploy:

    cd mapfish-print-doc
    git fetch origin
    git checkout gh-pages
    git merge --ff-only origin/gh-pages
    git rm --ignore-unmatch -rqf .
    cp -r ../mapfish-print/docs/build/site/. .
    git add -A .
    git commit -m 'Update docs'
    git push origin gh-pages