Add anchor for STICKER/PIN markers 69/88269/2
authorVarun <tallytalwar@gmail.com>
Wed, 14 Sep 2016 21:21:16 +0000 (17:21 -0400)
committerVarun <tallytalwar@gmail.com>
Thu, 15 Sep 2016 20:48:48 +0000 (16:48 -0400)
Change-Id: I739d6e84f23b7f100eaf09a25bc93449cd6befd3

src/mapzen/tangram_view.cpp

index 1529bbf..9cc7b2b 100644 (file)
@@ -548,20 +548,29 @@ mapzen_error_e TangramView::updateObject(maps_view_object_h object, Tangram::Mar
        switch(type) {
                case MAPS_VIEW_OBJECT_MARKER:
                        {
-                               // TODO: distinguish between MAPS_VIEW_MARKER_PIN and MAPS_VIEW_MARKER_STICKER (pin vs billboard?)
                                // TODO: use image passed with the view object, not available in tangram yet!
+                               maps_view_marker_type_e markerType;
+                               error = maps_view_object_marker_get_type(object, &markerType);
+                               if (error != MAPS_ERROR_NONE || markerType < MAPS_VIEW_MARKER_PIN || markerType > MAPS_VIEW_MARKER_STICKER) { break; }
+
                                maps_coordinates_h mapsCoord = nullptr;
                                double lat = 0.0, lng = 0.0;
                                int markerWidth = 0, markerHeight = 0;
 
-                               const char* styleFormat = "{ style: 'ux-icons-overlay', sprite: 'ux-search-active', size: [%dpx, %dpx], collide: false, anchor: top, transition: { [show, hide]: { time: 0s } } }";
+                               const char* styleFormat = "{ style: 'ux-icons-overlay', sprite: 'ux-search-active', size: [%dpx, %dpx], collide: false, anchor: %s, transition: { [show, hide]: { time: 0s } } }";
+                               static std::string anchor;
+
+                               anchor = "center";
+                               if (markerType == MAPS_VIEW_MARKER_PIN) {
+                                       anchor = "top";
+                               }
 
                                error = maps_view_object_marker_get_size(object, &markerWidth, &markerHeight);
                                if (error != MAPS_ERROR_NONE) { break; }
 
-                               int sz = std::snprintf(nullptr, 0, styleFormat, markerWidth, markerHeight);
+                               int sz = std::snprintf(nullptr, 0, styleFormat, markerWidth, markerHeight, anchor.c_str());
                                styleString.resize(sz+1);
-                               std::snprintf(&styleString[0], styleString.size(), styleFormat, markerWidth, markerHeight);
+                               std::snprintf(&styleString[0], styleString.size(), styleFormat, markerWidth, markerHeight, anchor.c_str());
 
                                m_map->markerSetStyling(tvMarker, styleString.c_str());