summaryrefslogtreecommitdiff
path: root/src/mbgl/style/conversion/coordinate.cpp
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-09-26 14:14:44 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-10-23 09:56:43 -0700
commit4b2e1cddb4645fb6d2c5f9634dbeb7c21516cede (patch)
treef11bd97ea5abf17bc6956f254796f1e8cf4a96f9 /src/mbgl/style/conversion/coordinate.cpp
parentbb58ddaea8c2d9da9551601318944d9d143ee247 (diff)
downloadqtlocation-mapboxgl-4b2e1cddb4645fb6d2c5f9634dbeb7c21516cede.tar.gz
Replace compile-time polymorphism with runtime polymorphism in the conversion system
Diffstat (limited to 'src/mbgl/style/conversion/coordinate.cpp')
-rw-r--r--src/mbgl/style/conversion/coordinate.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/mbgl/style/conversion/coordinate.cpp b/src/mbgl/style/conversion/coordinate.cpp
new file mode 100644
index 0000000000..9b2be3381e
--- /dev/null
+++ b/src/mbgl/style/conversion/coordinate.cpp
@@ -0,0 +1,29 @@
+#include <mbgl/style/conversion/coordinate.hpp>
+
+namespace mbgl {
+namespace style {
+namespace conversion {
+
+optional<LatLng> Converter<LatLng>::operator() (const Convertible& value, Error& error) const {
+ if (!isArray(value) || arrayLength(value) < 2 ) {
+ error = { "coordinate array must contain numeric longitude and latitude values" };
+ return {};
+ }
+ //Style spec uses GeoJSON convention for specifying coordinates
+ optional<double> latitude = toDouble(arrayMember(value, 1));
+ optional<double> longitude = toDouble(arrayMember(value, 0));
+
+ if (!latitude || !longitude) {
+ error = { "coordinate array must contain numeric longitude and latitude values" };
+ return {};
+ }
+ if (*latitude < -90 || *latitude > 90 ){
+ error = { "coordinate latitude must be between -90 and 90" };
+ return {};
+ }
+ return LatLng(*latitude, *longitude);
+}
+
+} // namespace conversion
+} // namespace style
+} // namespace mbgl