Hello:There is a way to do this.The coding pattern is very similar to what you'll find in the Dynamic Map Layer sample of the ArcGIS Runtime SDK for Qt sample viewer application.As demonstrated in that example, you'll need to begin by using the LocalMapService along with an "empty" MPK. It's important that you enable dynamic layers on the LocalMapService as well.QString dataPath = pathSampleData + "mpks" + QDir::separator() + "mpk_blank.mpk";
m_localMapService = EsriRuntimeQt::LocalMapService(dataPath);
m_localMapService.setEnableDynamicLayers(true);
Create a WorkspaceInfo using the static method "CreateSDEConnection", passing in a workspace ID string and the connection string to the SDE instance. Keep in mind, your client machine where this app is running must have the appropriate client libraries installed for the database you are going to connect to, whether it be SQLServer, Oracle, or Postgres, for example. In this case, we are connecting to a SQLServer database:"INSTANCE=sde:sqlserver:bedrock4;DATABASE=nongdb;USER=map;PASSWORD=map"
// Get the WorkspaceInfoSet from the LocalMapService...
EsriRuntimeQt::WorkspaceInfoSet& workspaceInfoSet = m_localMapService.dynamicWorkspaces();
// create a workspace info via the static method according to data type
m_workspaceId = QString("1");
EsriRuntimeQt::WorkspaceInfo workspaceInfo =
EsriRuntimeQt::WorkspaceInfo::CreateSDEConnection(m_workspaceId, QString("INSTANCE=sde:sqlserver:bedrock4;DATABASE=nongdb;USER=map;PASSWORD=map"));
workspaceInfo.setEditable(true);
workspaceInfoSet.add(workspaceInfo);
m_localMapService.setDynamicWorkspaces(workspaceInfoSet);
// You are ready to start the map service
m_localMapService.start();
After your LocalMapService has started up successfully, you are ready to add your dynamic layer to the map. It goes something like this:void Sde_workspace_sample::onLocalServiceCreationSuccess(const QString& url, const QString& name)
{
// create the ArcGISDynamicMapServiceLayer using the LocalMapService's url
m_dynamicLocalServiceLayer = EsriRuntimeQt::ArcGISDynamicMapServiceLayer(m_localMapService.urlMapService());
m_dynamicLocalServiceLayer.setName("MySDELayer");
m_map.addLayer(m_dynamicLocalServiceLayer);
m_dynamicLocalServiceLayer.setVisible(true);
EsriRuntimeQt::DynamicLayerInfoCollection& layerInfos = m_dynamicLocalServiceLayer.dynamicLayerInfos();
EsriRuntimeQt::DynamicLayerInfo& layerInfo = layerInfos[0];
// Create some symbology for the added layer
EsriRuntimeQt::SimpleRenderer simpleRenderer(EsriRuntimeQt::SimpleFillSymbol(QColor("yellow"),EsriRuntimeQt::SimpleFillSymbolStyle::Solid, EsriRuntimeQt::SimpleLineSymbol(QColor("black"), 1, EsriRuntimeQt::SimpleLineSymbolStyle::Solid)));
EsriRuntimeQt::DrawingInfo countriesDrawingInfo(simpleRenderer, 20);
layerInfo.setDrawingInfo(countriesDrawingInfo);
// set dynamic workspaces for our local map service
EsriRuntimeQt::TableDataSource sdeDataSource;
sdeDataSource.setWorkspaceId(m_workspaceId);
// Here is where you identify the feature class you want to add
sdeDataSource.setDataSourceName(QString("nongdb.map.CALIFORNIA"));
// Set the layer's datasource
EsriRuntimeQt::LayerDataSource layerDataSource;
layerDataSource.setDataSource(sdeDataSource);
layerInfo.setLayerSource(layerDataSource);
m_dynamicLocalServiceLayer.refresh();
}
I hope this is helpful! Let us know...