-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
88 lines (78 loc) · 3.05 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "mapget/service/service.h"
#include "mapget/log.h"
using namespace mapget;
class MyLocalDataSource : public mapget::DataSource
{
public:
DataSourceInfo info() override {
return DataSourceInfo::fromJson(R"(
{
"mapId": "Tropico",
"layers": {
"WayLayer": {
"featureTypes":
[
{
"name": "Way",
"uniqueIdCompositions":
[
[
{
"partId": "areaId",
"description": "String which identifies the map area.",
"datatype": "STR"
},
{
"partId": "wayId",
"description": "Globally Unique 32b integer.",
"datatype": "U32"
}
]
]
}
]
}
}
}
)"_json);
}
void fill(TileFeatureLayer::Ptr const& tile) override {
// Add some ID parts that are shared by all features in the tile.
tile->setIdPrefix({{"areaId", "BestArea"}});
// Create a feature with line geometry
auto feature1 = tile->newFeature("Way", {{"wayId", 42}});
auto line = feature1->geom()->newGeometry(GeomType::Line, 2);
line->append({41., 10.});
line->append({43., 11.});
// Use high-level geometry API
feature1->addPoint(tile->tileId().center());
feature1->addPoints({tile->tileId().ne(), tile->tileId().sw()});
feature1->addLine({{41.5, 10.5, 0}, {41.6, 10.7}});
feature1->addMesh({{41.5, 10.5, 0}, {41.6, 10.7}, {41.5, 10.3}});
feature1->addPoly({{41.5, 10.5, 0}, {41.6, 10.7}, {41.5, 10.3}, {41.8, 10.9}});
// Add a fixed attribute
feature1->attributes()->addField("main_ingredient", "Pepper");
// Add an attribute layer
auto attrLayer = feature1->attributeLayers()->newLayer("cheese");
auto attr = attrLayer->newAttribute("mozzarella");
attr->setDirection(Attribute::Direction::Positive);
attr->addField("smell", "neutral");
}
};
int main(int argc, char** argv)
{
// Create a local mapget service instance
mapget::Service service;
// Add a local datasource
service.add(std::make_shared<MyLocalDataSource>());
// Create a request. The request will immediately start to be worked on.
auto r = std::make_shared<LayerTilesRequest>(
"Tropico",
"WayLayer",
std::vector<TileId>{TileId(12345), TileId(67689)},
[](auto&& result)
{ log().info("Got {}", MapTileKey(*result).toString()); });
service.request({r});
r->wait();
return 0;
}