In this section, you can learn how to work with the OCM load tile example.
To start working with the load tile example, you need to add a catalog or catalogs from which you want to request decoded or encoded tile data. You need to add a catalog to the DataStoreServer
instance first, and then add it to the DataStoreClient
instance.
-
To access data from the HERE platform, create a Network
instance.
#include <olp/core/client/OlpClientSettingsFactory.h>
...
auto network = olp::client::OlpClientSettingsFactory::
CreateDefaultNetworkRequestHandler( );
-
To handle requests asynchronously, create a TaskScheduler
instance and specify the number of threads that the SDK should use.
Note: If you do not define the TaskScheduler
explicitly or set the number of threads to 1, HERE Data SDK for C++ will handle all requests synchronously.
#include <olp/core/client/OlpClientSettingsFactory.h>
...
const std::shared_ptr< olp::thread::TaskScheduler > task_scheduler
= olp::client::OlpClientSettingsFactory::CreateDefaultTaskScheduler( 4u );
-
To access the OCM data from the HERE platform, create a DataStoreServer
instance using the Network
and TaskScheduler
instances.
#include <olp/clientmap/datastore/DataStoreServer.h>
...
olp::clientmap::datastore::DataStoreServerSettings server_settings;
server_settings.network_request_handler = network;
server_settings.task_scheduler = task_scheduler;
auto server = std::make_shared< olp::clientmap::datastore::DataStoreServer >(
server_settings );
-
Initialize the DataStoreServer
instance and cache.
server->Init();
If the operation is successful, you get the kNone
error.
-
Create a DataStoreClient
instance using a shared pointer to the DataStoreServer
instance.
Note: Multiple DataStoreClient
instances can use the same DataStoreServer
instance.
#include <olp/clientmap/datastore/DataStoreClient.h>
...
olp::clientmap::datastore::DataStoreClientSettings client_settings;
olp::clientmap::datastore::DataStoreClient client( server, client_settings );
-
To access data from the OCM catalog, create an AuthenticationCredentials
instance using the here.access.key.іd
and here.access.key.secret
values from your platform
credentials.
For instructions on how to get platform credentials, see the Get credentials section in the Getting Started Guide.
Note: You can also load credentials from a file. For instruction, see Read authentication credentials from a file in the Add catalog to DataStoreServer and DataStoreClient instances.
#include <olp/authentication/AuthenticationCredentials.h>
...
olp::authentication::AuthenticationCredentials credentials(
"your-here-access-key-id", "your-here-access-key-secret" );
-
Сreate an AuthenticationSettings
instance using the AuthenticationCredentials
, Network
, and TaskScheduler
instances.
#include <olp/authentication/TokenProvider.h>
#include <olp/clientmap/datastore/Settings.h>
...
olp::authentication::Settings settings( credentials );
settings.network_request_handler = network;
settings.task_scheduler = task_scheduler;
olp::client::AuthenticationSettings authentication_settings;
authentication_settings.provider
= olp::authentication::TokenProviderDefault( std::move( settings ) );
-
Create a CatalogSettings
instance using the AuthenticationSettings
instance.
#include <olp/clientmap/datastore/Settings.h>
...
olp::clientmap::datastore::CatalogSettings catalog_settings;
catalog_settings.authentication_settings = authentication_settings;
-
Configure DataStoreClient
to get data from a specific version of the OCM catalog.
If you do not set the version explicitly or set it to boost::none
, the catalog version is set internally to the latest version that is available on the HERE platform when the catalog is added.
Note: You cannot add two versions of the same catalog to the same DataStoreClient
instance. To get data from different versions of the same catalog, create a DataStoreClient
instance for each catalog version and add different versions of the catalog to different DataStoreClient
instances.
catalog_settings.version = "version_number";
-
Add a catalog to the DataStoreServer
instance using the HERE Resource Name (HRN) of the catalog and the CatalogSettings
instance.
const auto add_catalog_server =
server->AddCatalog( kCatalogHrn, catalog_settings );
-
Check if the AddCatalog
operation is successful.
if ( !add_catalog_server.IsSuccessful( ) )
{
OLP_SDK_LOG_WARNING_F( kLogTag, "Failed to add a catalog to server - error=%s",
ToString( add_catalog_server.GetError( ) ).c_str( ) );
return EXIT_SUCCESS;
}
The operation can be unsuccessful if one of the following is true:
- The catalog with the requested HRN does not exist.
-
DataStoreClient
fails to check if the catalog with the requested HRN exists. Catalog existence is checked only if the catalog version is not set or set to boost::none
.
-
Add the same catalog to the DataStoreClient
instance using the HRN of the catalog and the CatalogSettings
instance.
const auto add_catalog_result =
client.AddCatalog( kCatalogHrn, catalog_settings );
-
Check if the AddCatalog
operation is successful.
if ( !add_catalog_client.IsSuccessful( ) )
{
OLP_SDK_LOG_WARNING_F( kLogTag, "Failed to add a catalog to client - error=%s",
ToString( add_catalog_client.GetError( ) ).c_str( ) );
return EXIT_SUCCESS;
}
The operation can be unsuccessful if one of the following is true:
- The catalog with the requested HRN does not exist.
-
DataStoreClient
fails to check if the catalog with the requested HRN exists. Catalog existence is checked only if the catalog version is not set or set to boost::none
.
-
If the AddCatalog
operation is successful, to access data from the added catalog, save its CatalogHandle
.
const auto catalog_handle = add_catalog_result.GetResult( );
Now, you can use the handle of the added catalog to get encoded and decoded tile data.
You can load decoded map data for all map layers from all catalogs that you added to the DataStoreClient
instance.
You can use the data that you get in the callback or copy it for future purposes.
You can get encoded tile data for all map layers from all catalogs that are added to the DataStoreClient
instances.
If you need to keep any layer data outside the callback scope, copy the data at which the LayerPayloadData
instance points. The pointers are not guaranteed to be valid outside the callback scope.