Class Mapnik

java.lang.Object
dev.avelar.mapnik.Mapnik

public final class Mapnik extends Object
Global Mapnik setup.
  • Method Details

    • version

      public static String version()
      Version of the Mapnik library the native shim is loaded against.
    • versionNumber

      public static int versionNumber()
      Numeric Mapnik version: major * 100000 + minor * 100 + patch, for example 400302 for 4.3.2.
    • datasourcePlugins

      public static List<String> datasourcePlugins()
      Names of the registered input plugins, for example geojson and shape.
    • scaleDenominator

      public static double scaleDenominator(double mapUnitsPerPixel, boolean geographic)
      The scale denominator for a map scale in projection units per pixel. Pass geographic true for degrees. This is the number layers and rules compare against their scale ranges.
    • isBundled

      public static boolean isBundled()
      True if the native libraries came from a mapnik-java-natives-* bundle on the class path, so this Mapnik, its dependencies, input plugins, fonts and PROJ data all ship with the program.
    • bundledDirectory

      public static Path bundledDirectory()
      The directory the bundle was unpacked to, or null if the natives are not bundled.
    • hasCairo

      public static boolean hasCairo()
      True if Mapnik was built with Cairo, which PDF, SVG and PostScript output needs.
    • capabilities

      public static Set<Capability> capabilities()
      What this Mapnik was built with.
    • supports

      public static boolean supports(Capability capability)
    • fontFaces

      public static List<String> fontFaces()
      Names of every font face registered in this process, sorted, for use as face-name.
    • fontFile

      public static Optional<String> fontFile(String faceName)
      The font file that provides a face, or empty if no registered face has that name.
    • registerFontFile

      public static void registerFontFile(Path file)
      Register one font file. Throws MapnikException if Mapnik cannot read it as a font.
    • registerDatasource

      public static void registerDatasource(Path pluginFile)
      Register one input plugin file. Throws MapnikException if it cannot be loaded.
    • isDatasourceRegistered

      public static boolean isDatasourceRegistered(String name)
      True if an input plugin with this name, such as geojson, is registered.
    • datasourcePluginDirectories

      public static String datasourcePluginDirectories()
      The directories plugins were registered from, separated by colons.
    • setTrustedCertificates

      public static void setTrustedCertificates(Path pemFile)
      Trust the certificates in a PEM file for HTTPS tile sources (see Datasource.tilesFromUrl(java.lang.String, java.lang.String)), instead of the bundled list or the system's. Use it for a server with a private certificate authority. Applies to datasources created afterwards. The same can be done with the SSL_CERT_FILE environment variable. It also sets CURL_CA_BUNDLE, which PROJ's downloader reads. The setting is for the whole process, so it also applies to PROJ's downloads (see enableProjNetwork(boolean)) and anything else in the process that reads SSL_CERT_FILE.
    • enableProjNetwork

      public static void enableProjNetwork(boolean enable)
      Let PROJ download the datum-shift grids it needs but does not have (for example to convert NAD27 to NAD83 exactly) from its content network, and keep them in its cache. Off by default, because it makes network requests. Call it before the first projection is used on a thread: PROJ reads the setting when it first starts on that thread. The same can be done with the PROJ_NETWORK=ON environment variable.
    • clearCaches

      public static void clearCaches()
      Drop cached marker images and memory-mapped files. Call it after changing files Mapnik has already read.
    • expectedVersion

      public static String expectedVersion()
      Version of Mapnik this wrapper release was built and tested against.
    • isCompatible

      public static boolean isCompatible()
      True when the loaded Mapnik has the same major.minor version as expectedVersion().
    • registerDatasources

      public static void registerDatasources(String dir)
      Load input plugins (postgis, shape, gdal...) from dir. Call once at startup.
    • registerFonts

      public static void registerFonts(String dir)
      Register fonts from dir. Call once at startup.
    • leakedHandles

      public static long leakedHandles()
      How many native objects (maps, images, layers and so on) have been garbage collected without being closed since the JVM started. Each one is a native memory leak. The first few are logged as warnings; set -Dmapnik.leakTrace=true to include where they were created.