Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include "DisplayDB.h"
00009 #include "../sqllib/sqllib.h"
00010 #include "ToShowEdgesSelector.h"
00011
00012 namespace osmdb
00013 {
00014
00015 DisplayDB::DisplayDB(OsmDatabase& db, std::string const& path_base, int min_zoom, int max_zoom)
00016 : db(db),
00017 pdb(db),
00018 minz(min_zoom),
00019 maxz(max_zoom),
00020 coll(path_base, db.get_db(), min_zoom, max_zoom),
00021 get_bounds(sqllib::get_select_bounds(db.get_db()))
00022 {
00023 get_bounds.execute();
00024 if (get_bounds.row_count() == 0)
00025 {
00026 clat = clon = 0;
00027 }
00028 else
00029 {
00030 auto tpl = get_bounds.get_row(0);
00031 clon = (std::get<0>(tpl) + std::get<1>(tpl)) / 2;
00032 clat = (std::get<2>(tpl) + std::get<3>(tpl)) / 2;
00033 }
00034 }
00035
00036 DisplayDB::~DisplayDB()
00037 {
00038 }
00039
00040 OsmDatabase& DisplayDB::get_db()
00041 {
00042 return db;
00043 }
00044
00045 std::vector<std::unique_ptr<display::DisplayElement> > const& DisplayDB::get_display_elements()
00046 {
00047 return display_elements;
00048 }
00049
00050 void DisplayDB::set_bounds(const geo::Point& p1, const geo::Point& p2, int zoom)
00051 {
00052 display_elements.clear();
00053 double left = std::min(p1.lon, p2.lon);
00054 double right = std::max(p1.lon, p2.lon);
00055 double lower = std::min(p1.lat, p2.lat);
00056 double higher = std::max(p1.lat, p2.lat);
00057 auto& stmt = coll.get_edges_for_zoom(zoom);
00058 std::vector<std::unique_ptr<display::DisplayElement> > edges = std::move(ToShowEdgesSelector::get_edges(stmt, left, lower, right, higher));
00059 for (unsigned int i = 0; i < edges.size(); ++i)
00060 {
00061 display_elements.push_back(std::unique_ptr<display::DisplayElement>(std::move(edges[i])));
00062 }
00063 }
00064
00065 std::vector<std::unique_ptr<osm::Element> > DisplayDB::get_selected(const geo::Point& p1, const geo::Point& p2, int zoom)
00066 {
00067 double left = std::min(p1.lon, p2.lon);
00068 double right = std::max(p1.lon, p2.lon);
00069 double lower = std::min(p1.lat, p2.lat);
00070 double higher = std::max(p1.lat, p2.lat);
00071
00072 std::vector<std::unique_ptr<osm::Element> > ret;
00073 auto& stmt = coll.get_select_edges(zoom);
00074 stmt.execute(left, lower, right, higher);
00075 for (int i = 0; i < stmt.row_count(); ++i)
00076 {
00077 int64_t id;
00078 double r, g, b, a, t;
00079 int attr, p;
00080 std::tie(id, r, g, b, a, t, attr, p) = stmt.get_row(i);
00081 ret.push_back(std::unique_ptr<osm::Element>(new osm::Way(id)));
00082 }
00083
00084 for (unsigned int i = 0; i < ret.size(); ++i)
00085 {
00086 ret[i]->fill(pdb);
00087 }
00088
00089 return ret;
00090 }
00091
00092 double DisplayDB::center_lat()
00093 {
00094 return clat;
00095 }
00096
00097 double DisplayDB::center_lon()
00098 {
00099 return clon;
00100 }
00101
00102 }