/* Copyright (C) 2021 Nicole Faerber based on: DrawMap - a demo program for libosmscout Copyright (C) 2009 Tim Teulings This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include /* Example for the nordrhein-westfalen.osm (to be executed in meson build directory): Demos/DrawMapCairo ../maps/nordrhein-westfalen ../stylesheets/standard.oss 800 480 51.51241 7.46525 70000 test.png */ static osmscout::DatabaseParameter databaseParameter; static osmscout::DatabaseRef database; static osmscout::MapServiceRef mapService; static osmscout::StyleConfigRef styleConfig; static osmscout::BasemapDatabaseRef basemapDatabase; static osmscout::MercatorProjection projection; static osmscout::MapParameter drawParameter; static osmscout::AreaSearchParameter searchParameter; static osmscout::MapData data; static std::list tiles; static osmscout::MapPainterCairo *cairoMapPainter{nullptr}; int DrawMapCairoInit(int argc, char* argv[]) { std::list iconPaths; database=std::make_shared(databaseParameter); if (!database->Open("data/nordrhein-westfalen-latest/")) { std::cerr << "Cannot open database" << std::endl; return -1; } mapService=std::make_shared(database); styleConfig = std::make_shared(database->GetTypeConfig()); if (!styleConfig->Load("data/standard.oss")) { std::cerr << "Cannot open style" << std::endl; return -1; } drawParameter.SetFontName("/usr/share/fonts/TTF/LiberationSans-Regular.ttf"); drawParameter.SetFontSize(3.0); drawParameter.SetRenderSeaLand(true); drawParameter.SetRenderUnknowns(false); drawParameter.SetRenderBackground(false); drawParameter.SetRenderContourLines(false); drawParameter.SetRenderHillShading(false); drawParameter.SetIconMode(osmscout::MapParameter::IconMode::Scalable); iconPaths.push_back("data/icons/svg/standard/"); drawParameter.SetIconPaths(iconPaths); drawParameter.SetPatternMode(osmscout::MapParameter::PatternMode::Scalable); drawParameter.SetPatternPaths(iconPaths); drawParameter.SetDebugData(false); drawParameter.SetDebugPerformance(false); drawParameter.SetLabelLineMinCharCount(15); drawParameter.SetLabelLineMaxCharCount(30); drawParameter.SetLabelLineFitToArea(true); //LoadBaseMapTiles(data.baseMapTiles); assert(database); assert(database->IsOpen()); assert(mapService); assert(styleConfig); cairoMapPainter = new osmscout::MapPainterCairo(styleConfig); return 0; } int DrawMapCairo(cairo_surface_t *surface, double lat, double lon, unsigned int zoomlevel, double direction) { osmscout::GeoCoord center(lat, lon); osmscout::Magnification zoom; /*{osmscout::Magnification::magClose};*/ osmscout::GeoBox boundingBox; cairo_t *cairo=cairo_create(surface); assert(database); assert(database->IsOpen()); assert(mapService); assert(styleConfig); zoom.SetMagnification(zoomlevel); projection.Set(center, direction, zoom, 96, 800, 600); projection.GetDimensions(boundingBox); mapService->GetGroundTiles(projection, data.groundTiles); mapService->LookupTiles(projection, tiles); mapService->LoadMissingTileData(searchParameter,*styleConfig, tiles); mapService->AddTileDataToMapData(tiles, data); if (!cairoMapPainter->DrawMap(projection, drawParameter, data, cairo)) std::cerr << "Cannot paint" << std::endl;; cairo_destroy(cairo); return 0; }