Make vector tile use the provider API key 10/94010/2
authorVarun <tallytalwar@gmail.com>
Wed, 26 Oct 2016 15:25:35 +0000 (11:25 -0400)
committerVarun <tallytalwar@gmail.com>
Wed, 26 Oct 2016 20:57:14 +0000 (16:57 -0400)
Change-Id: I80f1697d36dc7215ee51446c1dfd5e9991a6dba5

scenes/bubble-wrap/bubble-wrap.yaml
src/mapzen/mapzen_api.cpp
src/mapzen/mapzen_api.hpp
src/mapzen/tangram_view.cpp
src/mapzen/tangram_view.hpp
src/mapzen_plugin.c

index dce07e5..8da7cb4 100644 (file)
@@ -544,7 +544,7 @@ sources:
         #url:  //localhost:8080/vector/all/{z}/{x}/{y}.mvt
         # road labels in Tangram JS are broken when overzooming, set max_zoom: 18 to preview fix
         url_params:
-            api_key: vector-tiles-7bfyfz8
+            api_key:
         max_zoom: 16
 
 #    # Only enable this for local debug, should not be enabled for prod (app inserts these at runtime)
index dfe1ac5..1d7af6f 100644 (file)
@@ -97,7 +97,7 @@ int mapzen_start_route(mapzen_route_req_s *req_details, mapzen_route_cb callback
        return ret;
 }
 
-int mapzen_create_map_view(maps_view_h hView, maps_plugin_map_view_ready_cb pCbFunc)
+int mapzen_create_map_view(maps_view_h hView, maps_plugin_map_view_ready_cb pCbFunc, const char* providerKey)
 {
        TangramView* tv = new TangramView();
        if (!tv) {
@@ -109,7 +109,7 @@ int mapzen_create_map_view(maps_view_h hView, maps_plugin_map_view_ready_cb pCbF
        if (old_tv) {
                delete old_tv;
        }
-       return tv->create(hView, pCbFunc);
+       return tv->create(hView, pCbFunc, providerKey);
 }
 
 int mapzen_destroy_map_view(maps_view_h hView)
index a87b97c..37a79e4 100644 (file)
@@ -70,7 +70,7 @@ 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_create_map_view(maps_view_h hView, maps_plugin_map_view_ready_cb pCbFunc, const char* providerKey);
 
 int mapzen_destroy_map_view(maps_view_h hView);
 
index f007c19..8b457ae 100644 (file)
@@ -57,7 +57,7 @@ void TangramView::deinitNetworkRequests() {
        stopUrlRequests();
 }
 
-mapzen_error_e TangramView::create(maps_view_h view, maps_plugin_map_view_ready_cb callback)
+mapzen_error_e TangramView::create(maps_view_h view, maps_plugin_map_view_ready_cb callback, const char* providerKey)
 {
        if (!view) {
                return MAPZEN_ERROR_INVALID_PARAMETER;
@@ -128,6 +128,9 @@ mapzen_error_e TangramView::create(maps_view_h view, maps_plugin_map_view_ready_
        m_map->setPixelScale(scaleFactor);
 
        m_map->loadSceneAsync(NORMAL_SCENE_FILE_PATH, false, sceneLoadedCb, (void*)view);
+       if (providerKey) {
+               m_providerKey = providerKey;
+       }
 
        // Make the GL context current and perform GL setup.
        evas_gl_make_current(m_gl, m_surface, m_context);
@@ -871,6 +874,7 @@ void TangramView::setMapType(maps_view_h view)
                }
                m_viewType = newViewType;
                m_map->loadSceneAsync(newSceneFile, false, sceneLoadedCb, (void*)view);
+               m_isProviderKeySet = false;
        }
 
        bool buildings_enabled = false;
@@ -903,6 +907,13 @@ void TangramView::setMapType(maps_view_h view)
        }
        free(language);
 
+       // set provider key for vector tiles
+       if (m_providerKey.size() > 0 && !m_isProviderKeySet) {
+               MAPS_LOGD("Queueing API key update: %s", m_providerKey.c_str());
+               m_map->queueSceneUpdate("sources.mapzen.url_params.api_key", m_providerKey.c_str());
+               m_isProviderKeySet = true;
+       }
+
        // bool traffic_enabled = false;
        // maps_view_get_traffic_enabled(view, &traffic_enabled);
        m_map->applySceneUpdates();
index 49fddd9..51dafdb 100644 (file)
@@ -41,7 +41,7 @@ public:
        TangramView();
        ~TangramView();
 
-       mapzen_error_e create(maps_view_h view, maps_plugin_map_view_ready_cb callback);
+       mapzen_error_e create(maps_view_h view, maps_plugin_map_view_ready_cb callback, const char* providerKey);
        mapzen_error_e destroy(maps_view_h view);
        mapzen_error_e render(maps_view_h view, const maps_coordinates_h coord, double zoom, double angle);
        mapzen_error_e moveCenter(maps_view_h view, int delta_x, int delta_y);
@@ -100,6 +100,8 @@ private:
        bool m_buildingsEnabled = true;
        bool m_sceneLoaded = false;
        std::string m_language = "eng";
+       std::string m_providerKey = "";
+       bool m_isProviderKeySet = false;
 
        int m_x = 0;
        int m_y = 0;
index 9edd7b0..9804615 100644 (file)
@@ -55,7 +55,7 @@ EXPORT_API int maps_plugin_multi_reverse_geocode(const maps_coordinates_list_h g
 
 EXPORT_API int maps_plugin_create_map_view(maps_view_h hView, maps_plugin_map_view_ready_cb pCbFunc)
 {
-       int ret = mapzen_create_map_view(hView, pCbFunc);
+       int ret = mapzen_create_map_view(hView, pCbFunc, __provider_key);
        return convert_mapzen_error_to_maps_error(ret);
 }