Skip to content

Commit

Permalink
Mapnik API v4.0.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
rnorris committed Jul 2, 2024
1 parent 7067dff commit 443fe78
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,8 @@ case $ac_cv_enable_mapnik in
# C++
AC_LANG_PUSH([C++])
AC_PROG_CXX
# Mapnik3 requires C++11. Viking will use C++11 as well.
CXXFLAGS="$CXXFLAGS -std=c++11"
# Mapnik4 requires C++17. Viking will use C++17 as well.
CXXFLAGS="$CXXFLAGS -std=c++17"
# Too difficult to get check working under Windows (extra dependencies needed probably Boost)- so just skip it
if test "x$ac_cv_enable_windows" = "xno"; then
AC_CHECK_HEADER([mapnik/map.hpp],[],[AC_MSG_ERROR([mapnik/map.hpp is needed but not found - you will need to install package 'libmapnik-dev' or similar. The feature can be disabled with --disable-mapnik])])
Expand Down
27 changes: 18 additions & 9 deletions src/mapnik_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,20 @@
#include "globals.h"
#include "settings.h"

#if MAPNIK_VERSION < 200000
#include <mapnik/envelope.hpp>
#define image_32 Image32
#define image_data_32 ImageData32
#define box2d Envelope
#define zoom_to_box zoomToBox
#else
#if MAPNIK_VERSION < 400000
#include <mapnik/box2d.hpp>
#endif
#if MAPNIK_VERSION >= 300000
// In Mapnik3 'image_32' has changed names once again
#define image_32 image_rgba8
#define raw_data data
#endif
#if MAPNIK_VERSION < 200000
#include <mapnik/envelope.hpp>
#define image_32 Image32
#define image_data_32 ImageData32
#define box2d Envelope
#define zoom_to_box zoomToBox
#endif

#define MAPNIK_INTERFACE_TYPE (mapnik_interface_get_type ())
Expand Down Expand Up @@ -93,7 +94,11 @@ struct _MapnikInterface {
G_DEFINE_TYPE (MapnikInterface, mapnik_interface, G_TYPE_OBJECT)

// Can't change prj after init - but ATM only support drawing in Spherical Mercator
#if MAPNIK_VERSION < 400000
static mapnik::projection prj( mapnik::MAPNIK_GMERC_PROJ );
#else
static mapnik::projection prj( mapnik::MAPNIK_WEBMERCATOR_PROJ );
#endif

MapnikInterface* mapnik_interface_new ()
{
Expand Down Expand Up @@ -184,8 +189,12 @@ gchar* mapnik_interface_load_map_file ( MapnikInterface* mi,
mapnik::load_map(*mi->myMap, filename);

mi->myMap->resize(width,height);
mi->myMap->set_srs ( mapnik::MAPNIK_GMERC_PROJ ); // ONLY WEB MERCATOR output supported ATM

// ONLY WEB MERCATOR output supported ATM
#if MAPNIK_VERSION < 400000
mi->myMap->set_srs ( mapnik::MAPNIK_GMERC_PROJ );
#else
mi->myMap->set_srs ( mapnik::MAPNIK_WEBMERCATOR_PROJ );
#endif
// IIRC This size is the number of pixels outside the tile to be considered so stuff is shown (i.e. particularly labels)
// Only set buffer size if the buffer size isn't explicitly set in the mapnik stylesheet.
// Alternatively render a bigger 'virtual' tile and then only use the appropriate subset
Expand Down

0 comments on commit 443fe78

Please sign in to comment.