From 928517862fa3645108d2e203eef783c5e1ddbbba Mon Sep 17 00:00:00 2001 From: Matt Blair Date: Wed, 29 Jun 2016 19:34:10 -0400 Subject: [PATCH] Renames mapzen_api.h to mapzen_api.hpp and adds interface to TangramView Change-Id: I3a09fba697702577550beb132502c63fc16b4fa7 --- CMakeLists.txt | 2 +- src/mapzen/mapzen_api.c | 91 ----------- src/mapzen/mapzen_api.cpp | 233 ++++++++++++++++++++++++++++ src/mapzen/{mapzen_api.h => mapzen_api.hpp} | 25 +++ src/mapzen/mapzen_geocode.h | 2 +- src/mapzen/mapzen_place.h | 2 +- src/mapzen/mapzen_revgeocode.h | 2 +- src/mapzen/mapzen_route.hpp | 2 +- src/mapzen/mapzen_server_private.h | 2 +- src/mapzen/tangram_view.cpp | 5 + src/mapzen_plugin.c | 2 +- 11 files changed, 270 insertions(+), 98 deletions(-) delete mode 100644 src/mapzen/mapzen_api.c create mode 100644 src/mapzen/mapzen_api.cpp rename src/mapzen/{mapzen_api.h => mapzen_api.hpp} (73%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 676cb16..38f0f11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,7 +68,7 @@ SET(SRCS src/mapzen_plugin.c # Mapzen Engine - src/mapzen/mapzen_api.c + src/mapzen/mapzen_api.cpp src/mapzen/mapzen_geocode.c src/mapzen/mapzen_revgeocode.c src/mapzen/mapzen_route.cpp diff --git a/src/mapzen/mapzen_api.c b/src/mapzen/mapzen_api.c deleted file mode 100644 index 111ba88..0000000 --- a/src/mapzen/mapzen_api.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "mapzen_api.h" -#include "mapzen_server_private.h" -#include "mapzen_queue.h" -#include "mapzen_debug.h" - -int mapzen_init() -{ - int ret = mapzen_init_queue(); - - return ret; -} - -int mapzen_shutdown() -{ - int ret = mapzen_deinit_queue(); - - return ret; -} - -int mapzen_geocode(mapzen_geocode_req_s *req_details, mapzen_geocode_cb callback, int request_id, void *user_data) -{ - int ret = MAPZEN_ERROR_NONE; - ret = start_geocode_service(req_details, callback, request_id, user_data); - - return ret; -} - -int mapzen_cancel_request(int request_id) -{ - int ret = remove_from_request_list(request_id); - - return ret; -} - -int mapzen_reverse_geocode(mapzen_revgeocode_req_s *req_details, mapzen_reverse_geocode_cb callback, int request_id, void *user_data) -{ - int ret = MAPZEN_ERROR_NONE; - ret = start_reversegeocode_service(req_details, callback, request_id, user_data); - - return ret; -} - -int mapzen_search_place(mapzen_search_req_s *req_details, mapzen_place_search_cb callback, int request_id, void *user_data) -{ - int ret = MAPZEN_ERROR_NONE; - ret = start_place_service(req_details, callback, request_id, user_data); - - return ret; -} - -int mapzen_get_place_details(mapzen_get_details_req_s *req_details, mapzen_get_place_details_cb callback, int request_id, void *user_data) -{ - int ret = MAPZEN_ERROR_NONE; - ret = start_place_details_service(req_details, callback, request_id, user_data); - - return ret; -} - -int mapzen_search_place_list(mapzen_search_req_s *req_details, mapzen_place_list_search_cb callback, int request_id, void *user_data) -{ - int ret = MAPZEN_ERROR_NONE; - ret = start_places_list_service(req_details, callback, request_id, user_data); - - return ret; -} - -int mapzen_start_route(mapzen_route_req_s *req_details, mapzen_route_cb callback, int request_id, void *user_data) -{ - int ret = MAPZEN_ERROR_NONE; - ret = start_route_service(req_details, callback, request_id, user_data); - - return ret; -} diff --git a/src/mapzen/mapzen_api.cpp b/src/mapzen/mapzen_api.cpp new file mode 100644 index 0000000..f780231 --- /dev/null +++ b/src/mapzen/mapzen_api.cpp @@ -0,0 +1,233 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +extern "C" { +#include "mapzen_queue.h" +#include "mapzen_debug.h" +#include "mapzen_util.h" +} + +#include +#include +#include "mapzen_api.hpp" +#include "mapzen_server_private.h" +#include "tangram_view.hpp" + +int mapzen_init() +{ + int ret = mapzen_init_queue(); + + return ret; +} + +int mapzen_shutdown() +{ + int ret = mapzen_deinit_queue(); + + return ret; +} + +int mapzen_geocode(mapzen_geocode_req_s *req_details, mapzen_geocode_cb callback, int request_id, void *user_data) +{ + int ret = MAPZEN_ERROR_NONE; + ret = start_geocode_service(req_details, callback, request_id, user_data); + + return ret; +} + +int mapzen_cancel_request(int request_id) +{ + int ret = remove_from_request_list(request_id); + + return ret; +} + +int mapzen_reverse_geocode(mapzen_revgeocode_req_s *req_details, mapzen_reverse_geocode_cb callback, int request_id, void *user_data) +{ + int ret = MAPZEN_ERROR_NONE; + ret = start_reversegeocode_service(req_details, callback, request_id, user_data); + + return ret; +} + +int mapzen_search_place(mapzen_search_req_s *req_details, mapzen_place_search_cb callback, int request_id, void *user_data) +{ + int ret = MAPZEN_ERROR_NONE; + ret = start_place_service(req_details, callback, request_id, user_data); + + return ret; +} + +int mapzen_get_place_details(mapzen_get_details_req_s *req_details, mapzen_get_place_details_cb callback, int request_id, void *user_data) +{ + int ret = MAPZEN_ERROR_NONE; + ret = start_place_details_service(req_details, callback, request_id, user_data); + + return ret; +} + +int mapzen_search_place_list(mapzen_search_req_s *req_details, mapzen_place_list_search_cb callback, int request_id, void *user_data) +{ + int ret = MAPZEN_ERROR_NONE; + ret = start_places_list_service(req_details, callback, request_id, user_data); + + return ret; +} + +int mapzen_start_route(mapzen_route_req_s *req_details, mapzen_route_cb callback, int request_id, void *user_data) +{ + int ret = MAPZEN_ERROR_NONE; + ret = start_route_service(req_details, callback, request_id, user_data); + + return ret; +} + +int mapzen_create_map_view(maps_view_h hView, maps_plugin_map_view_ready_cb pCbFunc) +{ + TangramView* tv = new TangramView(); + if (!tv) { + return MAPZEN_ERROR_OUT_OF_MEMORY; + } + TangramView* old_tv = nullptr; + maps_view_get_maps_plugin_view_handle(hView, (void**)&old_tv); + maps_view_set_maps_plugin_view_handle(hView, tv); + if (old_tv) { + delete old_tv; + } + return tv->create(hView, pCbFunc); +} + +int mapzen_destroy_map_view(maps_view_h hView) +{ + TangramView* tv = nullptr; + int maps_error = maps_view_get_maps_plugin_view_handle(hView, (void**)&tv); + mapzen_error_e error = (mapzen_error_e)convert_maps_error_to_mapzen_error(maps_error); + if (error == MAPZEN_ERROR_NONE && tv) { + maps_view_set_maps_plugin_view_handle(hView, nullptr); + error = tv->destroy(hView); + } + return error; +} + +int mapzen_render_map(maps_view_h hView, const maps_coordinates_h coordinates, double zoom_factor, double rotation_angle) +{ + TangramView* tv = nullptr; + int maps_error = maps_view_get_maps_plugin_view_handle(hView, (void**)&tv); + mapzen_error_e error = (mapzen_error_e)convert_maps_error_to_mapzen_error(maps_error); + if (error == MAPZEN_ERROR_NONE && tv) { + error = tv->render(hView, coordinates, zoom_factor, rotation_angle); + } + return error; +} + +int mapzen_move_center(maps_view_h hView, int delta_x, int delta_y) +{ + TangramView* tv = nullptr; + int maps_error = maps_view_get_maps_plugin_view_handle(hView, (void**)&tv); + mapzen_error_e error = (mapzen_error_e)convert_maps_error_to_mapzen_error(maps_error); + if (error == MAPZEN_ERROR_NONE && tv) { + error = tv->moveCenter(hView, delta_x, delta_y); + } + return error; +} + +int mapzen_set_scalebar(maps_view_h hView, bool enable) +{ + TangramView* tv = nullptr; + int maps_error = maps_view_get_maps_plugin_view_handle(hView, (void**)&tv); + mapzen_error_e error = (mapzen_error_e)convert_maps_error_to_mapzen_error(maps_error); + if (error == MAPZEN_ERROR_NONE && tv) { + error = tv->setScalebarEnabled(hView, enable); + } + return error; +} + +int mapzen_get_scalebar(maps_view_h hView, bool *enabled) +{ + TangramView* tv = nullptr; + int maps_error = maps_view_get_maps_plugin_view_handle(hView, (void**)&tv); + mapzen_error_e error = (mapzen_error_e)convert_maps_error_to_mapzen_error(maps_error); + if (error == MAPZEN_ERROR_NONE && tv) { + error = tv->getScalebarEnabled(hView, enabled); + } + return error; +} + +int mapzen_on_object(maps_view_h hView, const maps_view_object_h object, maps_view_object_operation_e operation) +{ + TangramView* tv = nullptr; + int maps_error = maps_view_get_maps_plugin_view_handle(hView, (void**)&tv); + mapzen_error_e error = (mapzen_error_e)convert_maps_error_to_mapzen_error(maps_error); + if (error == MAPZEN_ERROR_NONE && tv) { + error = tv->onViewObject(hView, object, operation); + } + return error; +} + +int mapzen_screen_to_geography(maps_view_h hView, int x, int y, maps_coordinates_h *mapsCoord) +{ + TangramView* tv = nullptr; + int maps_error = maps_view_get_maps_plugin_view_handle(hView, (void**)&tv); + mapzen_error_e error = (mapzen_error_e)convert_maps_error_to_mapzen_error(maps_error); + if (error == MAPZEN_ERROR_NONE && tv) { + error = tv->convertScreenToGeolocation(hView, x, y, mapsCoord); + } + return error; +} + +int mapzen_geography_to_screen(maps_view_h hView, const maps_coordinates_h mapsCoord, int* x, int* y) +{ + TangramView* tv = nullptr; + int maps_error = maps_view_get_maps_plugin_view_handle(hView, (void**)&tv); + mapzen_error_e error = (mapzen_error_e)convert_maps_error_to_mapzen_error(maps_error); + if (error == MAPZEN_ERROR_NONE && tv) { + error = tv->convertGeolocationToScreen(hView, mapsCoord, x, y); + } + return error; +} + +int mapzen_get_min_zoom_level(maps_view_h hView, int *min_zoom_level) +{ + TangramView* tv = nullptr; + int maps_error = maps_view_get_maps_plugin_view_handle(hView, (void**)&tv); + mapzen_error_e error = (mapzen_error_e)convert_maps_error_to_mapzen_error(maps_error); + if (error == MAPZEN_ERROR_NONE && tv) { + error = tv->getMinZoomLevel(hView, min_zoom_level); + } + return error; +} + +int mapzen_get_max_zoom_level(maps_view_h hView, int *max_zoom_level) +{ + TangramView* tv = nullptr; + int maps_error = maps_view_get_maps_plugin_view_handle(hView, (void**)&tv); + mapzen_error_e error = (mapzen_error_e)convert_maps_error_to_mapzen_error(maps_error); + if (error == MAPZEN_ERROR_NONE && tv) { + error = tv->getMaxZoomLevel(hView, max_zoom_level); + } + return error; +} + +int mapzen_get_center(maps_view_h hView, maps_coordinates_h *center) +{ + TangramView* tv = nullptr; + int maps_error = maps_view_get_maps_plugin_view_handle(hView, (void**)&tv); + mapzen_error_e error = (mapzen_error_e)convert_maps_error_to_mapzen_error(maps_error); + if (error == MAPZEN_ERROR_NONE && tv) { + error = tv->getCenter(hView, center); + } + return error; +} diff --git a/src/mapzen/mapzen_api.h b/src/mapzen/mapzen_api.hpp similarity index 73% rename from src/mapzen/mapzen_api.h rename to src/mapzen/mapzen_api.hpp index 74765e5..a73b94d 100644 --- a/src/mapzen/mapzen_api.h +++ b/src/mapzen/mapzen_api.hpp @@ -18,6 +18,7 @@ #define _MAPZEN_API_H_ #include "mapzen_types.h" +#include #include /** @@ -69,6 +70,30 @@ int mapzen_search_place_list(mapzen_search_req_s *req_details, mapzen_place_list int mapzen_start_route(mapzen_route_req_s *req_details, mapzen_route_cb callback, int request_id, void *user_data); +int mapzen_create_map_view(maps_view_h hView, maps_plugin_map_view_ready_cb pCbFunc); + +int mapzen_destroy_map_view(maps_view_h hView); + +int mapzen_render_map(maps_view_h hView, const maps_coordinates_h coordinates, double zoom_factor, double rotation_angle); + +int mapzen_move_center(maps_view_h hView, int delta_x, int delta_y); + +int mapzen_set_scalebar(maps_view_h hView, bool enable); + +int mapzen_get_scalebar(maps_view_h hView, bool *enabled); + +int mapzen_on_object(maps_view_h hView, const maps_view_object_h object, maps_view_object_operation_e operation); + +int mapzen_screen_to_geography(maps_view_h hView, int x, int y, maps_coordinates_h *mapsCoord); + +int mapzen_geography_to_screen(maps_view_h hView, const maps_coordinates_h mapsCoord, int* x, int* y); + +int mapzen_get_min_zoom_level(maps_view_h hView, int *min_zoom_level); + +int mapzen_get_max_zoom_level(maps_view_h hView, int *max_zoom_level); + +int mapzen_get_center(maps_view_h hView, maps_coordinates_h *center); + #ifdef __cplusplus } #endif diff --git a/src/mapzen/mapzen_geocode.h b/src/mapzen/mapzen_geocode.h index 6c330ca..04d6dbf 100644 --- a/src/mapzen/mapzen_geocode.h +++ b/src/mapzen/mapzen_geocode.h @@ -17,7 +17,7 @@ #ifndef _MAPZEN_GEOCODE_H_ #define _MAPZEN_GEOCODE_H_ -#include "mapzen_api.h" +#include "mapzen_api.hpp" #include "mapzen_types.h" int query_geocode(gchar *maps_key, char *address, int num_results, gpointer user_data); diff --git a/src/mapzen/mapzen_place.h b/src/mapzen/mapzen_place.h index 84026a1..353debf 100644 --- a/src/mapzen/mapzen_place.h +++ b/src/mapzen/mapzen_place.h @@ -17,7 +17,7 @@ #ifndef _MAPZEN_PLACES_H_ #define _MAPZEN_PLACES_H_ -#include "mapzen_api.h" +#include "mapzen_api.hpp" #include "mapzen_types.h" #include "mapzen_server_private.h" diff --git a/src/mapzen/mapzen_revgeocode.h b/src/mapzen/mapzen_revgeocode.h index e61546f..6ec6ed9 100644 --- a/src/mapzen/mapzen_revgeocode.h +++ b/src/mapzen/mapzen_revgeocode.h @@ -17,7 +17,7 @@ #ifndef _MAPZEN_REVGEOCODE_H_ #define _MAPZEN_REVGEOCODE_H_ -#include "mapzen_api.h" +#include "mapzen_api.hpp" #include "mapzen_types.h" int query_revgeocode(gchar *maps_key, gdouble latitude, gdouble longitude, gpointer user_data); diff --git a/src/mapzen/mapzen_route.hpp b/src/mapzen/mapzen_route.hpp index 3af7b77..b464915 100644 --- a/src/mapzen/mapzen_route.hpp +++ b/src/mapzen/mapzen_route.hpp @@ -17,7 +17,7 @@ #ifndef _MAPZEN_ROUTE_H_ #define _MAPZEN_ROUTE_H_ -#include "mapzen_api.h" +#include "mapzen_api.hpp" #include "mapzen_types.h" #ifdef __cplusplus diff --git a/src/mapzen/mapzen_server_private.h b/src/mapzen/mapzen_server_private.h index f587cd9..e96c998 100644 --- a/src/mapzen/mapzen_server_private.h +++ b/src/mapzen/mapzen_server_private.h @@ -17,7 +17,7 @@ #ifndef _MAPZEN_PRIVATE_H_ #define _MAPZEN_PRIVATE_H_ -#include "mapzen_api.h" +#include "mapzen_api.hpp" typedef enum { REQ_TYPE_GEOCODE = 0, diff --git a/src/mapzen/tangram_view.cpp b/src/mapzen/tangram_view.cpp index 6b3b663..9dcadcd 100644 --- a/src/mapzen/tangram_view.cpp +++ b/src/mapzen/tangram_view.cpp @@ -14,7 +14,12 @@ * limitations under the License. */ +extern "C" { +#include "mapzen_queue.h" +#include "mapzen_debug.h" #include "mapzen_util.h" +} + #include "mapzen_plugin_internal.h" #include "tangram_view.hpp" #include "tangram/tangram.h" diff --git a/src/mapzen_plugin.c b/src/mapzen_plugin.c index 5d4e712..15517e1 100644 --- a/src/mapzen_plugin.c +++ b/src/mapzen_plugin.c @@ -18,7 +18,7 @@ #include #include "mapzen_plugin.h" #include "mapzen_plugin_internal.h" -#include "mapzen_api.h" +#include "mapzen_api.hpp" #include "mapzen_util.h" #include #include -- 2.7.4