From: Varun Date: Thu, 15 Sep 2016 23:45:58 +0000 (-0400) Subject: Add custom images to marker X-Git-Tag: submit/tizen_3.0/20161108.012559~25 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5d0c4e70675c26f4fbd3fcbc90c64183e78299d7;p=platform%2Fcore%2Flocation%2Fmaps-plugin-mapzen.git Add custom images to marker Updated libtangram libraries for marker image set Change-Id: I98b9065a53c445268a299f107f6ba246cafd7ef7 --- diff --git a/lib/arm/libtangram.so b/lib/arm/libtangram.so index 5e4a73d..9354afa 100755 Binary files a/lib/arm/libtangram.so and b/lib/arm/libtangram.so differ diff --git a/lib/i586/libtangram.so b/lib/i586/libtangram.so index 7608951..3f4dd36 100755 Binary files a/lib/i586/libtangram.so and b/lib/i586/libtangram.so differ diff --git a/src/mapzen/tangram/tangram.h b/src/mapzen/tangram/tangram.h index 8477f04..ab0c619 100644 --- a/src/mapzen/tangram/tangram.h +++ b/src/mapzen/tangram/tangram.h @@ -162,6 +162,8 @@ public: // updated, otherwise returns false. bool markerSetStyling(MarkerID _marker, const char* _styling); + bool markerSetBitmap(MarkerID _marker, int _width, int _height, const unsigned int* _data); + // Set the geometry of a marker to a point at the given coordinates; markers can have their // geometry set multiple times with possibly different geometry types; returns true if the // marker ID was found and successfully updated, otherwise returns false. diff --git a/src/mapzen/tangram_view.cpp b/src/mapzen/tangram_view.cpp index 12472c9..fe7686e 100644 --- a/src/mapzen/tangram_view.cpp +++ b/src/mapzen/tangram_view.cpp @@ -539,6 +539,59 @@ mapzen_error_e TangramView::updateObject(maps_view_object_h object, Tangram::Mar break; } + return error; +} + +mapzen_error_e TangramView::getBitmapMarkerImage(maps_view_object_h object, unsigned char *&imgData, int &imgWidth, int &imgHeight) { + char *imgPath = nullptr; + Evas_Object *img = nullptr; + int imgSize = 0; + int error = MAPS_ERROR_NONE; + + do { + error = maps_view_object_marker_get_image_file(object, &imgPath); + if (error != MAPS_ERROR_NONE || !imgPath) { break; } + + img = evas_object_image_add(evas_object_evas_get(m_image)); + evas_object_image_file_set(img, imgPath, nullptr); + int err = evas_object_image_load_error_get(img); + if (err != EVAS_LOAD_ERROR_NONE) { + MAPS_LOGE("Failed to load marker image file: %s", imgPath); + free(imgPath); + break; + } + free(imgPath); + + evas_object_image_size_get(img, &imgWidth, &imgHeight); + imgSize = imgWidth * imgHeight * 4; + + // Get Raw data pointer to the image + const unsigned char *srcData = (unsigned char *)evas_object_image_data_get(img, EINA_FALSE); + if (!srcData || imgSize <= 0) { + MAPS_LOGE("Failed to get image data from the evas image for the marker"); + error = MAPS_ERROR_OUT_OF_MEMORY; + break; + } + + imgData = (unsigned char *)malloc(imgSize); + if (!imgData) { + MAPS_LOGE("Failed to malloc!! for image data"); + error = MAPS_ERROR_OUT_OF_MEMORY; + break; + } + + // convert data from rgba to bgra + for (int i = 0; i < imgHeight; i++) { + for (int j = 0; j < imgWidth; j++) { + int offset = ((i * imgWidth) + j) * 4; + *(imgData + offset) = *(srcData + offset + 2); + *(imgData + offset + 1) = *(srcData + offset + 1); + *(imgData + offset + 2) = *(srcData + offset); + *(imgData + offset + 3) = *(srcData + offset + 3); + } + } + } while (0); + return (mapzen_error_e)convert_maps_error_to_mapzen_error(error); } @@ -548,9 +601,13 @@ mapzen_error_e TangramView::updateMarker(maps_view_object_h object, Tangram::Mar maps_coordinates_h mapsCoord = nullptr; double lat = 0.0, lng = 0.0; int markerWidth = 0, markerHeight = 0; + int imgWidth = 0, imgHeight = 0; int error = MAPS_ERROR_NONE; + unsigned char *imgData = nullptr; + + const char* styleFormat = "{ style: 'points', color: white, size: [%fpx, %fpx], collide: false, anchor: %s, transition: { [show, hide]: { time: 0s } } }"; + static std::string anchor; - const char* styleFormat = "{ style: 'ux-icons-overlay', sprite: 'ux-search-active', size: [%dpx, %dpx], collide: false, anchor: %s, transition: { [show, hide]: { time: 0s } } }"; maps_view_marker_type_e type; error = maps_view_object_marker_get_type(object, &type); @@ -558,17 +615,30 @@ mapzen_error_e TangramView::updateMarker(maps_view_object_h object, Tangram::Mar do { if (error != MAPS_ERROR_NONE || type < MAPS_VIEW_MARKER_PIN || type > MAPS_VIEW_MARKER_STICKER) { break; } + error = getBitmapMarkerImage(object, imgData, imgWidth, imgHeight); + + if (error != MAPS_ERROR_NONE || !imgData) { + MAPS_LOGE("Failed getting image data from marker object, with error code: %d", error); + break; + } + m_map->markerSetBitmap(tvMarker, imgWidth, imgHeight, reinterpret_cast(imgData)); + free(imgData); + anchor = "center"; if (type == MAPS_VIEW_MARKER_PIN) { anchor = "top"; } + float scaleFactor = 1.0/elm_config_scale_get(); 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, anchor.c_str()); + float scaledWidth = scaleFactor * markerWidth; + float scaledHeight = scaleFactor * markerHeight; + + int sz = std::snprintf(nullptr, 0, styleFormat, scaledWidth, scaledHeight, anchor.c_str()); styleString.resize(sz+1); - std::snprintf(&styleString[0], styleString.size(), styleFormat, markerWidth, markerHeight, anchor.c_str()); + std::snprintf(&styleString[0], styleString.size(), styleFormat, scaledWidth, scaledHeight, anchor.c_str()); m_map->markerSetStyling(tvMarker, styleString.c_str()); diff --git a/src/mapzen/tangram_view.hpp b/src/mapzen/tangram_view.hpp index c3a9103..1e439f9 100644 --- a/src/mapzen/tangram_view.hpp +++ b/src/mapzen/tangram_view.hpp @@ -64,6 +64,7 @@ private: mapzen_error_e addObject(maps_view_object_h object); mapzen_error_e setObjectVisible(maps_view_object_h object, Tangram::MarkerID tvMarker); + mapzen_error_e getBitmapMarkerImage(maps_view_object_h object, unsigned char *&imgData, int &imgWidth, int &imgHeight); mapzen_error_e updateObject(maps_view_object_h object, Tangram::MarkerID tvMarker); mapzen_error_e updateMarker(maps_view_object_h object, Tangram::MarkerID tvMarker); mapzen_error_e updatePolyline(maps_view_object_h object, Tangram::MarkerID tvMarker);