return MAPZEN_ERROR_SERVICE_NOT_AVAILABLE;
}
- return processViewObject(view, object, operation);
-}
-
-mapzen_error_e TangramView::processViewObject(maps_view_h view, const maps_view_object_h object, maps_view_object_operation_e operation)
-{
mapzen_error_e error = MAPZEN_ERROR_NONE;
TangramView *tv = nullptr;
MapViewObjects::iterator iter;
MapViewObjects::iterator end;
- switch(type) {
- case MAPS_VIEW_OBJECT_MARKER:
- case MAPS_VIEW_OBJECT_POLYGON:
- case MAPS_VIEW_OBJECT_POLYLINE:
- {
+ {
+ std::lock_guard<std::mutex> lock(m_viewObjectMutex);
+ iter = m_mapViewObjs.find(object);
+ end = m_mapViewObjs.end();
+ }
+ if (iter == end) {
+ tvMarker = m_map->markerAdd();
+ if (tvMarker) {
+ error = updateObject(object, tvMarker);
+ if (error == MAPZEN_ERROR_NONE) {
std::lock_guard<std::mutex> lock(m_viewObjectMutex);
- iter = m_mapViewObjs.find(object);
- end = m_mapViewObjs.end();
+ m_mapViewObjs.insert(std::make_pair(object, tvMarker));
+ } else {
+ m_map->markerRemove(tvMarker);
+ tvMarker = 0;
}
- if (iter == end) {
- tvMarker = m_map->markerAdd();
- if (tvMarker) {
- error = updateObject(object, tvMarker);
- if (error == MAPZEN_ERROR_NONE) {
- std::lock_guard<std::mutex> lock(m_viewObjectMutex);
- m_mapViewObjs.insert(std::make_pair(object, tvMarker));
- } else {
- m_map->markerRemove(tvMarker);
- tvMarker = 0;
- }
- }
- }
- break;
- default:
- break;
+ }
}
return error;
{
if (!object || !tvMarker || !m_map) { return MAPZEN_ERROR_INVALID_PARAMETER; }
- int error = MAPS_ERROR_NONE;
+ mapzen_error_e error = MAPZEN_ERROR_NONE;
maps_view_object_type_e type = MAPS_VIEW_OBJECT_POLYLINE;
maps_view_object_get_type(object, &type);
- std::string styleString = "";
-
- Tangram::Coordinates coords = {};
- unsigned char r = 0, g = 0, b = 0, a = 0;
-
switch(type) {
case MAPS_VIEW_OBJECT_MARKER:
- {
- // 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: %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, anchor.c_str());
- styleString.resize(sz+1);
- std::snprintf(&styleString[0], styleString.size(), styleFormat, markerWidth, markerHeight, anchor.c_str());
-
- m_map->markerSetStyling(tvMarker, styleString.c_str());
-
- error = maps_view_object_marker_get_coordinates(object, &mapsCoord);
- if (error != MAPS_ERROR_NONE) { break; }
-
- error = maps_coordinates_get_longitude(mapsCoord, &lng);
- if (error != MAPS_ERROR_NONE) {
- maps_coordinates_destroy(mapsCoord);
- break;
- }
-
- error = maps_coordinates_get_latitude(mapsCoord, &lat);
- if (error != MAPS_ERROR_NONE) {
- maps_coordinates_destroy(mapsCoord);
- break;
- }
-
- maps_coordinates_destroy(mapsCoord);
- m_map->markerSetPoint(tvMarker, Tangram::LngLat(lng, lat));
- }
+ error = updateMarker(object, tvMarker);
break;
case MAPS_VIEW_OBJECT_POLYLINE:
- {
- int width = 0;
- const char* styleFormat = "{ style: 'ux-route-line-overlay', color: [%d, %d, %d, %d], width: %dpx, order: 500 }";
-
- error = maps_view_object_polyline_get_color(object, &r, &g, &b, &a);
- if (error != MAPS_ERROR_NONE) { break; }
+ error = updatePolyline(object, tvMarker);
+ break;
+ case MAPS_VIEW_OBJECT_POLYGON:
+ error = updatePolygon(object, tvMarker);
+ break;
+ default:
+ break;
+ }
- error = maps_view_object_polyline_get_width(object, &width);
- if (error != MAPS_ERROR_NONE) { break; }
+ return (mapzen_error_e)convert_maps_error_to_mapzen_error(error);
+}
- int sz = std::snprintf(nullptr, 0, styleFormat, r, g, b, a, width);
- styleString.resize(sz+1);
- std::snprintf(&styleString[0], styleString.size(), styleFormat, r, g, b, a, width);
+mapzen_error_e TangramView::updateMarker(maps_view_object_h object, Tangram::MarkerID tvMarker)
+{
+ std::string styleString = "";
+ maps_coordinates_h mapsCoord = nullptr;
+ double lat = 0.0, lng = 0.0;
+ int markerWidth = 0, markerHeight = 0;
+ int error = MAPS_ERROR_NONE;
+ 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 } } }";
- m_map->markerSetStyling(tvMarker, styleString.c_str());
+ maps_view_marker_type_e type;
+ error = maps_view_object_marker_get_type(object, &type);
- error = maps_view_object_polyline_foreach_point(object, emplaceCoord, &coords);
- if (error != MAPS_ERROR_NONE) { break; }
+ do {
+ if (error != MAPS_ERROR_NONE || type < MAPS_VIEW_MARKER_PIN || type > MAPS_VIEW_MARKER_STICKER) { break; }
- m_map->markerSetPolyline(tvMarker, coords.data(), static_cast<int>(coords.size()));
- }
- break;
- case MAPS_VIEW_OBJECT_POLYGON:
- {
- const char* styleFormat = "{ style: 'polygons', color: [%d, %d, %d, %d] }";
+ anchor = "center";
+ if (type == MAPS_VIEW_MARKER_PIN) {
+ anchor = "top";
+ }
- error = maps_view_object_polygon_get_fill_color(object, &r, &g, &b, &a);
- if (error != MAPS_ERROR_NONE) { break; }
+ error = maps_view_object_marker_get_size(object, &markerWidth, &markerHeight);
+ if (error != MAPS_ERROR_NONE) { break; }
- int sz = std::snprintf(nullptr, 0, styleFormat, r, g, b, a);
- styleString.resize(sz+1);
- std::snprintf(&styleString[0], styleString.size(), styleFormat, r, g, b, a);
+ 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, anchor.c_str());
- m_map->markerSetStyling(tvMarker, styleString.c_str());
+ m_map->markerSetStyling(tvMarker, styleString.c_str());
- error = maps_view_object_polygon_foreach_point(object, emplaceCoord, &coords);
- if (error != MAPS_ERROR_NONE) { break; }
+ error = maps_view_object_marker_get_coordinates(object, &mapsCoord);
+ if (error != MAPS_ERROR_NONE) { break; }
- int count = (int)coords.size();
- m_map->markerSetPolygon(tvMarker, coords.data(), &count, 1);
- }
+ error = maps_coordinates_get_longitude(mapsCoord, &lng);
+ if (error != MAPS_ERROR_NONE) {
+ maps_coordinates_destroy(mapsCoord);
break;
- default:
+ }
+
+ error = maps_coordinates_get_latitude(mapsCoord, &lat);
+ if (error != MAPS_ERROR_NONE) {
+ maps_coordinates_destroy(mapsCoord);
break;
- }
+ }
+
+ maps_coordinates_destroy(mapsCoord);
+ m_map->markerSetPoint(tvMarker, Tangram::LngLat(lng, lat));
+ } while (0);
+
+ return (mapzen_error_e)convert_maps_error_to_mapzen_error(error);
+}
+
+mapzen_error_e TangramView::updatePolyline(maps_view_object_h object, Tangram::MarkerID tvMarker)
+{
+ std::string styleString = "";
+ int error = MAPS_ERROR_NONE;
+ Tangram::Coordinates coords = {};
+ unsigned char r = 0, g = 0, b = 0, a = 0;
+ int width = 0;
+
+ const char* styleFormat = "{ style: 'ux-route-line-overlay', color: [%d, %d, %d, %d], width: %dpx, order: 500 }";
+
+ do {
+ error = maps_view_object_polyline_get_color(object, &r, &g, &b, &a);
+ if (error != MAPS_ERROR_NONE) { break; }
+
+ error = maps_view_object_polyline_get_width(object, &width);
+ if (error != MAPS_ERROR_NONE) { break; }
+
+ int sz = std::snprintf(nullptr, 0, styleFormat, r, g, b, a, width);
+ styleString.resize(sz+1);
+ std::snprintf(&styleString[0], styleString.size(), styleFormat, r, g, b, a, width);
+
+ m_map->markerSetStyling(tvMarker, styleString.c_str());
+
+ error = maps_view_object_polyline_foreach_point(object, emplaceCoord, &coords);
+ if (error != MAPS_ERROR_NONE) { break; }
+
+ m_map->markerSetPolyline(tvMarker, coords.data(), static_cast<int>(coords.size()));
+ } while (0);
+
+ return (mapzen_error_e)convert_maps_error_to_mapzen_error(error);
+}
+
+mapzen_error_e TangramView::updatePolygon(maps_view_object_h object, Tangram::MarkerID tvMarker)
+{
+ std::string styleString = "";
+ int error = MAPS_ERROR_NONE;
+ Tangram::Coordinates coords = {};
+ unsigned char r = 0, g = 0, b = 0, a = 0;
+ const char* styleFormat = "{ style: 'polygons', color: [%d, %d, %d, %d] }";
+
+ do {
+ error = maps_view_object_polygon_get_fill_color(object, &r, &g, &b, &a);
+ if (error != MAPS_ERROR_NONE) { break; }
+
+ int sz = std::snprintf(nullptr, 0, styleFormat, r, g, b, a);
+ styleString.resize(sz+1);
+ std::snprintf(&styleString[0], styleString.size(), styleFormat, r, g, b, a);
+
+ m_map->markerSetStyling(tvMarker, styleString.c_str());
+
+ error = maps_view_object_polygon_foreach_point(object, emplaceCoord, &coords);
+ if (error != MAPS_ERROR_NONE) { break; }
+
+ int count = (int)coords.size();
+ m_map->markerSetPolygon(tvMarker, coords.data(), &count, 1);
+ } while (0);
return (mapzen_error_e)convert_maps_error_to_mapzen_error(error);
}
} else {
MAPS_LOGD("tv->m_map is null, in pixelGelCb");
}
-
}
void TangramView::renderingCb(void *data) {