Set the marker dimension to maintain aspect ratio of the marker when one of the marke... 81/91681/1
authorVarun <tallytalwar@gmail.com>
Mon, 10 Oct 2016 15:09:31 +0000 (11:09 -0400)
committerVarun <tallytalwar@gmail.com>
Mon, 10 Oct 2016 15:30:21 +0000 (11:30 -0400)
Change-Id: Ic05e3a01fab3b9cb79a9fc12d16a9d4a99af4817

src/mapzen/tangram_view.cpp

index 038cec7..f87dbf3 100644 (file)
@@ -637,9 +637,18 @@ mapzen_error_e TangramView::updateMarker(maps_view_object_h object, Tangram::Mar
                error = maps_view_object_marker_get_size(object, &markerWidth, &markerHeight);
                if (error != MAPS_ERROR_NONE) { break; }
 
-               if (markerWidth == 0 || markerHeight == 0) {
+               /*
+                * - Sets the marker dimension to be image dimension if both the specified marker dimensions are zero
+                * - Sets the marker dimension such that aspect ratio is maintained when one of the marker dimensions is
+                *   zero
+                */
+               if (markerWidth == 0 && markerHeight == 0) {
                        markerWidth = imgWidth;
                        markerHeight = imgHeight;
+               } else if (markerWidth == 0 && markerHeight > 0) {
+                       markerWidth = (float)markerHeight * (float)imgWidth / (float)imgHeight;
+               } else if (markerWidth > 0 && markerHeight == 0) {
+                       markerHeight = (float)markerWidth * (float)imgHeight / (float)imgWidth;
                }
 
                float scaledWidth = scaleFactor * markerWidth;