Bridges-C++ 3.5.0
Bridges(C++ API)
WorldMap.h
Go to the documentation of this file.
1#ifndef WORLD_MAP_H
2
3#define WORLD_MAP_H
4
5#include <math.h>
6#include <cmath>
7
8#include <algorithm>
9
10#include <string>
11#include <vector>
12
13using std::string;
14using std::vector;
15
16#include "DataStructure.h"
17#include "Map.h"
18#include "./data_src/Country.h"
19#include <JSONutil.h>
20
21namespace bridges {
22 namespace datastructure {
23
24 using namespace bridges::datastructure;
26
51 class WorldMap : public Map, public DataStructure {
52 private:
53 vector<string> country_names;
54 vector<Country> country_data;
55 bool all;
56
57 virtual const string getDataStructureRepresentation ()
58 const override {
60 return JSONencode("mapdummy") + COLON + JSONencode(true) +
62 }
63 public:
68 const string getProjection() const override {
69 return "equirectangular";
70 }
76 const bool getOverlay() const override {
77 return true;
78 }
79
85 virtual const string getMapRepresentation () const override {
86 if (this->all)
87 return "[\"all\"]";
88 // generates a JSON of the country information
89 string map_str = OPEN_BOX;
91 for (auto& cntry : country_data) {
92 map_str += OPEN_CURLY +
93 QUOTE + "_country_name" + QUOTE + COLON +
94 JSONencode(cntry.getCountryName()) + COMMA +
95 QUOTE + "_alpha2" + QUOTE + COLON +
96 JSONencode(cntry.getAlpha2Id()) + COMMA +
97 QUOTE + "_alpha3" + QUOTE + COLON +
98 JSONencode(cntry.getAlpha3Id()) + COMMA +
99 QUOTE + "_numeric" + QUOTE + COLON +
100 JSONencode(cntry.getNumeric3Id()) + COMMA +
101 QUOTE + "_fill_color" + QUOTE + COLON +
102 cntry.getFillColor().getCSSRepresentation() + COMMA +
103 QUOTE + "_stroke_color" + QUOTE + COLON +
104 cntry.getStrokeColor().getCSSRepresentation() + COMMA +
105 QUOTE + "_stroke_width" + QUOTE + COLON +
106 JSONencode(cntry.getStrokeWidth()) + CLOSE_CURLY + COMMA;
107
108
109 }
110 // remove last comma
111 if (country_data.size())
112 map_str = map_str.substr(0, map_str.size() - 1);
113 // close the countries array
114 map_str = map_str + CLOSE_BOX;
115 //cout << map_str << endl;
116 return map_str;
117 }
118 public:
119 // constructors
120
121 /* this is useful when you simply need the world map as an overlay
122 * using a default fill and boundary colors for the map
123 */
125 all = true;
126 }
127 /*
128 * @brief Constructs a World Map object with map data
129 *
130 * This constructor is useful for mapping data attributes to specific
131 * countries
132 *
133 * @param country_data data containg country information
134 */
135 WorldMap(vector<Country> cntry_data) {
136 all = false;
137 country_data = cntry_data;
138 }
139
140 /*
141 * @brief This function returns the current country data
142 * in the World map object.
143 *
144 * @return list of country information
145 */
146 vector<Country>& getMapData() {
147 return country_data;
148 }
149
150 /*
151 * @brief This function sets the country data
152 * in the US map object.
153 *
154 * @param list of country data
155 */
156 void setCountryData(vector<Country> cntry_data) {
157 all = false;
158 country_data = cntry_data;
159 }
160
161 /*
162 *
163 * @brief This function gets the data structure type for
164 * the US map,
165 *
166 */
167 virtual const string getDStype() const override {
168 return "world_map";
169 }
170 };
171 }
172}
173#endif
Definition: Country.h:25
This is the superclass of all data structure types in BRIDGES.
Definition: DataStructure.h:74
Abstract class for Map API.
Definition: Map.h:16
This class provides an API to building, displaying and manipulating World maps and countries in BRIDG...
Definition: WorldMap.h:51
void setCountryData(vector< Country > cntry_data)
Definition: WorldMap.h:156
const bool getOverlay() const override
Gets the map overlay flag.
Definition: WorldMap.h:76
const string getProjection() const override
Gets the type of map projection. For US map we currently use albersusa.
Definition: WorldMap.h:68
virtual const string getMapRepresentation() const override
Generates the JSON representation of the World map.
Definition: WorldMap.h:85
WorldMap(vector< Country > cntry_data)
Definition: WorldMap.h:135
vector< Country > & getMapData()
Definition: WorldMap.h:146
WorldMap()
Definition: WorldMap.h:124
virtual const string getDStype() const override
Definition: WorldMap.h:167
std::string JSONencode(const T &d)
Definition: JSONutil.h:38
Definition: Array.h:9
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
const string COLON
Definition: DataStructure.h:52
const string OPEN_BOX
Definition: DataStructure.h:55
const string COMMA
Definition: DataStructure.h:51
const string OPEN_CURLY
Definition: DataStructure.h:53
const string CLOSE_BOX
Definition: DataStructure.h:56
const string CLOSE_CURLY
Definition: DataStructure.h:54
const string QUOTE
Definition: DataStructure.h:50