summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbsudekum <bobby@mapbox.com>2016-08-10 13:37:04 -0700
committerbsudekum <bobby@mapbox.com>2016-08-10 13:37:04 -0700
commit92e9adda2c3b3e958f2a3c2a93ca7658ce9dde14 (patch)
tree43c8922d2697d76624dbe98f373870a21c443175
parent532c659b22c73eac04c7d643aff6ac5f1cc9f55a (diff)
downloadqtlocation-mapboxgl-92e9adda2c3b3e958f2a3c2a93ca7658ce9dde14.tar.gz
[node] add annotationsupstream/node-annotation
-rw-r--r--platform/node/src/node_map.cpp49
-rw-r--r--platform/node/src/node_map.hpp2
2 files changed, 50 insertions, 1 deletions
diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp
index 3eb9d8e539..ecdd9226c8 100644
--- a/platform/node/src/node_map.cpp
+++ b/platform/node/src/node_map.cpp
@@ -9,6 +9,8 @@
#include <mbgl/style/conversion/source.hpp>
#include <mbgl/style/conversion/layer.hpp>
#include <mbgl/style/conversion/filter.hpp>
+#include <mbgl/annotation/annotation.hpp>
+#include <mbgl/sprite/sprite_image.hpp>
#include <unistd.h>
@@ -19,6 +21,12 @@
#endif
namespace node_mbgl {
+
+struct AnnotationOptions {
+ double latitude = 0;
+ double longitude = 0;
+ std::string image;
+};
struct NodeMap::RenderOptions {
double zoom = 0;
@@ -29,9 +37,11 @@ struct NodeMap::RenderOptions {
unsigned int width = 512;
unsigned int height = 512;
std::vector<std::string> classes;
+ std::vector<AnnotationOptions> annotations;
mbgl::MapDebugOptions debugOptions = mbgl::MapDebugOptions::NoDebug;
};
+
Nan::Persistent<v8::Function> NodeMap::constructor;
static std::shared_ptr<mbgl::HeadlessDisplay> sharedDisplay() {
@@ -243,6 +253,23 @@ NodeMap::RenderOptions NodeMap::ParseOptions(v8::Local<v8::Object> obj) {
if (Nan::Has(obj, Nan::New("pitch").ToLocalChecked()).FromJust()) {
options.pitch = Nan::Get(obj, Nan::New("pitch").ToLocalChecked()).ToLocalChecked()->NumberValue();
}
+
+ if (Nan::Has(obj, Nan::New("annotations").ToLocalChecked()).FromJust()) {
+ auto annotationsArray = Nan::Get(obj, Nan::New("annotations").ToLocalChecked()).ToLocalChecked();
+ if (annotationsArray->IsArray()) {
+ auto annotations = annotationsArray.As<v8::Array>();
+ const int length = annotations->Length();
+ for (int i = 0; i < length; i++) {
+ auto annotationObj = annotations->Get(i).As<v8::Object>();
+ double latitude = Nan::Get(annotationObj, Nan::New("latitude").ToLocalChecked()).ToLocalChecked()->NumberValue();
+ double longitude = Nan::Get(annotationObj, Nan::New("longitude").ToLocalChecked()).ToLocalChecked()->NumberValue();
+ std::string image = "foo";
+ options.annotations.push_back({
+ latitude, longitude, image
+ });
+ }
+ }
+ }
if (Nan::Has(obj, Nan::New("center").ToLocalChecked()).FromJust()) {
auto centerObj = Nan::Get(obj, Nan::New("center").ToLocalChecked()).ToLocalChecked();
@@ -361,6 +388,26 @@ void NodeMap::startRender(NodeMap::RenderOptions options) {
map->setBearing(options.bearing);
map->setPitch(options.pitch);
map->setDebug(options.debugOptions);
+
+ for(auto id: annotationIDs) {
+ map->removeAnnotation(id);
+ }
+ annotationIDs.clear();
+
+ for(auto annotationIconString: annotationIconNames) {
+ map->removeAnnotationIcon(annotationIconString);
+ }
+ annotationIconNames.clear();
+
+ for(auto annotation: options.annotations) {
+ std::string iconName = "marker1";
+ annotationIconNames.push_back(iconName);
+
+ mbgl::PremultipliedImage cPremultipliedImage(1, 1);
+ auto cSpriteImage = std::make_shared<mbgl::SpriteImage>(std::move(cPremultipliedImage), 1);
+ map->addAnnotationIcon(iconName, cSpriteImage);
+ annotationIDs.push_back(map->addAnnotation(mbgl::SymbolAnnotation {{ annotation.longitude, annotation.latitude }, iconName }));
+ }
map->renderStill([this](const std::exception_ptr eptr, mbgl::PremultipliedImage&& result) {
if (eptr) {
@@ -467,7 +514,7 @@ void NodeMap::release() {
uv_close(reinterpret_cast<uv_handle_t *>(async), [] (uv_handle_t *h) {
delete reinterpret_cast<uv_async_t *>(h);
});
-
+
map.reset();
}
diff --git a/platform/node/src/node_map.hpp b/platform/node/src/node_map.hpp
index 3673b5f2ba..0fd56cadd4 100644
--- a/platform/node/src/node_map.hpp
+++ b/platform/node/src/node_map.hpp
@@ -51,6 +51,8 @@ public:
mbgl::HeadlessView view;
std::unique_ptr<mbgl::Map> map;
+ std::vector<mbgl::AnnotationID> annotationIDs;
+ std::vector<std::string> annotationIconNames;
std::exception_ptr error;
mbgl::PremultipliedImage image;