4#include <rapidjson/document.h>
5#include <rapidjson/stringbuffer.h>
6#include <rapidjson/writer.h>
11inline std::string withAircraftStyle(
const std::string& style) {
12 rapidjson::Document document;
13 document.Parse(style.c_str());
14 if (document.HasParseError() || !document.IsObject() ||
15 !document.HasMember(
"sources") || !document[
"sources"].IsObject() ||
16 !document.HasMember(
"layers") || !document[
"layers"].IsArray()) {
17 throw std::runtime_error(
"map style has invalid sources or layers");
19 rapidjson::Document additions;
21 "source":{"type":"geojson","data":{"type":"FeatureCollection","features":[]}},
23 {"id":"aircraft-points","type":"circle","source":"aircraft",
24 "paint":{"circle-radius":7,"circle-color":"#27d4ed",
25 "circle-stroke-color":"#10202b","circle-stroke-width":2}},
26 {"id":"aircraft-headings","type":"symbol","source":"aircraft",
27 "layout":{"text-field":"▲","text-size":16,
28 "text-font":["KlokanTech Noto Sans CJK Regular"],
29 "text-rotate":["coalesce",["get","heading_deg"],0],
30 "text-rotation-alignment":"map",
31 "text-allow-overlap":true},
32 "paint":{"text-color":"#ffffff","text-halo-color":"#10202b","text-halo-width":1}},
33 {"id":"aircraft-labels","type":"symbol","source":"aircraft",
34 "layout":{"text-field":["coalesce",["get","callsign"],["get","icao"]],
35 "text-size":11,"text-font":["KlokanTech Noto Sans CJK Regular"],
36 "text-anchor":"top","text-offset":[0,1.2]},
37 "paint":{"text-color":"#ffffff","text-halo-color":"#10202b","text-halo-width":2}}
39 auto& allocator = document.GetAllocator();
40 if (!document[
"sources"].HasMember(
"aircraft")) {
41 rapidjson::Value source;
42 source.CopyFrom(additions[
"source"], allocator);
43 document[
"sources"].AddMember(
"aircraft", source, allocator);
44 for (
const auto& layer : additions[
"layers"].GetArray()) {
45 rapidjson::Value copy;
46 copy.CopyFrom(layer, allocator);
47 document[
"layers"].PushBack(copy, allocator);
50 rapidjson::StringBuffer buffer;
51 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
52 document.Accept(writer);
53 return buffer.GetString();