diff --git a/backend-mapnik/metatilehandler.cc b/backend-mapnik/metatilehandler.cc index aa60413..83683c0 100644 --- a/backend-mapnik/metatilehandler.cc +++ b/backend-mapnik/metatilehandler.cc @@ -35,7 +35,7 @@ #define MERCATOR_WIDTH 40075016.685578488 #define MERCATOR_OFFSET 20037508.342789244 -MetatileHandler::MetatileHandler(const std::string& tiledir, const std::string& stylefile, unsigned int tilesize, double scalefactor, int buffersize, unsigned int mtrowcol, const std::string& imagetype) : +MetatileHandler::MetatileHandler(const std::string& tiledir, const std::map& stylefiles, unsigned int tilesize, double scalefactor, int buffersize, unsigned int mtrowcol, const std::string& imagetype) : mTileWidth(tilesize), mTileHeight(tilesize), mMetaTileRows(mtrowcol), @@ -45,7 +45,35 @@ MetatileHandler::MetatileHandler(const std::string& tiledir, const std::string& mScaleFactor(scalefactor), mTileDir(tiledir) { - load_map(mMap, stylefile); + for (unsigned int i=0; i<=MAXZOOM; i++) + { + mPerZoomMap[i]=NULL; + } + + for (auto itr = stylefiles.begin(); itr != stylefiles.end(); itr++) + { + if (itr->first == "") + { + load_map(mMap, itr->second); + debug("load %s without zoom restrictions", itr->second.c_str()); + } + else if (itr->first.at(0) != '.') + { + throw std::invalid_argument("malformed mapfile config postfix '" + itr->first + "'"); + } + else + { + char *endptr; + long int num = strtol(itr->first.c_str()+1, &endptr, 10); + if (*endptr || (num<0) || (num>MAXZOOM)) + { + throw std::invalid_argument("malformed mapfile config postfix '" + itr->first + "'"); + } + mPerZoomMap[num] = new mapnik::Map; + debug("load %s for zoom %d", itr->second.c_str(), num); + load_map(*(mPerZoomMap[num]), itr->second); + } + } fourpow[0] = 1; twopow[0] = 1; @@ -99,6 +127,7 @@ const NetworkResponse *MetatileHandler::handleRequest(const NetworkRequest *requ rr.south = (twopow[z] - y - mtr) * MERCATOR_WIDTH / twopow[z] - MERCATOR_OFFSET; rr.scale_factor = mScaleFactor; rr.buffer_size = mBufferSize; + rr.zoom = z; // we specify the bbox in epsg:3857, and we also want our image returned // in this projection. @@ -250,6 +279,7 @@ const RenderResponse *MetatileHandler::render(const RenderRequest *rr) { debug(">> MetatileHandler::render"); char init[255]; + mapnik::Map *map = mPerZoomMap[rr->zoom] ? mPerZoomMap[rr->zoom] : &mMap; sprintf(init, "+init=epsg:%d", rr->srs); // commented out - rely on proper SRS specification in map.xml @@ -281,21 +311,21 @@ const RenderResponse *MetatileHandler::render(const RenderRequest *rr) } mapnik::box2d bbox(west, south, east, north); - mMap.resize(rr->width, rr->height); - mMap.zoom_to_box(bbox); + map->resize(rr->width, rr->height); + map->zoom_to_box(bbox); if (rr->buffer_size > -1) { - mMap.set_buffer_size(rr->buffer_size); + map->set_buffer_size(rr->buffer_size); } - else if (mMap.buffer_size() < 128) + else if (map->buffer_size() < 128) { - mMap.set_buffer_size(128); + map->set_buffer_size(128); } debug("width: %d, height:%d", rr->width, rr->height); RenderResponse *resp = new RenderResponse(); resp->image = new mapnik::image_32(rr->width, rr->height); - mapnik::agg_renderer renderer(mMap, *(resp->image), rr->scale_factor, 0u, 0u); + mapnik::agg_renderer renderer(*map, *(resp->image), rr->scale_factor, 0u, 0u); try { renderer.apply(); diff --git a/backend-mapnik/metatilehandler.h b/backend-mapnik/metatilehandler.h index 6868a99..2955b11 100644 --- a/backend-mapnik/metatilehandler.h +++ b/backend-mapnik/metatilehandler.h @@ -45,7 +45,7 @@ class MetatileHandler : public RequestHandler { public: - MetatileHandler(const std::string& tiledir, const std::string& stylefile, unsigned int tilesize, double scalefactor, int buffersize, unsigned int mtrowcol, const std::string & imagetype); + MetatileHandler(const std::string& tiledir, const std::map& stylefiles, unsigned int tilesize, double scalefactor, int buffersize, unsigned int mtrowcol, const std::string & imagetype); ~MetatileHandler(); const NetworkResponse *handleRequest(const NetworkRequest *request); void xyz_to_meta(char *path, size_t len, const char *tile_dir, int x, int y, int z) const; @@ -67,6 +67,7 @@ class MetatileHandler : public RequestHandler double mScaleFactor; std::string mTileDir; mapnik::Map mMap; + mapnik::Map *mPerZoomMap[MAXZOOM+1]; }; #endif diff --git a/backend-mapnik/renderd.cc b/backend-mapnik/renderd.cc index 404cebe..68c3df4 100644 --- a/backend-mapnik/renderd.cc +++ b/backend-mapnik/renderd.cc @@ -54,7 +54,7 @@ bool RenderDaemon::loadMapnikWrapper(const char *configfile) char linebuf[255]; std::string tiledir; - std::string mapfile; + std::map mapfiles; std::string stylename; unsigned int tilesize = 256; unsigned int mtrowcol = 8; @@ -85,9 +85,9 @@ bool RenderDaemon::loadMapnikWrapper(const char *configfile) { tiledir.assign(eq); } - else if (!strcmp(line, "mapfile")) + else if (!strncmp(line, "mapfile", 7)) { - mapfile.assign(eq); + mapfiles.insert(std::pair(line+7, eq)); } else if (!strcmp(line, "scalefactor")) { @@ -137,18 +137,12 @@ bool RenderDaemon::loadMapnikWrapper(const char *configfile) } fclose(f); - if (mapfile.empty()) + if (mapfiles.empty()) { warning("cannot add %s: missing mapfile option", configfile); return rv; } - if (access(mapfile.c_str(), R_OK) == -1) - { - warning("cannot add %s: map file '%s' not accessible", configfile, mapfile.c_str()); - return rv; - } - if (tiledir.empty()) { warning("cannot add %s: missing tiledir option", configfile); @@ -169,7 +163,7 @@ bool RenderDaemon::loadMapnikWrapper(const char *configfile) try { - mHandlerMap[stylename] = new MetatileHandler(tiledir, mapfile, tilesize, + mHandlerMap[stylename] = new MetatileHandler(tiledir, mapfiles, tilesize, scalefactor, buffersize, mtrowcol, imagetype); mHandlerMap[stylename]->setStatusReceiver(this); debug("added style '%s' from map %s", stylename.c_str(), configfile); diff --git a/backend-mapnik/renderrequest.h b/backend-mapnik/renderrequest.h index 9b7457a..3342500 100644 --- a/backend-mapnik/renderrequest.h +++ b/backend-mapnik/renderrequest.h @@ -30,6 +30,7 @@ class RenderRequest int buffer_size; unsigned int srs; unsigned int bbox_srs; + unsigned int zoom; }; #endif diff --git a/debian/changelog b/debian/changelog index e1d7959..e3059b7 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +tirex (0.6.4) focal; urgency=medium + + * allow adding a dot and zoom level after mapfile parameter to override map file for specific zoom levels + + -- Frederik Ramm Fri, 13 Aug 2021 11:55:10 +0200 + tirex (0.6.3) bionic; urgency=medium * modify TMS backend to take template URL parameter