private WorkspaceInfo workspaceInfo; private JMap createMap() { ... // Add a new workspace LocalMapService mapService = new LocalMapService(getPathSampleData() + "MPKs/USCitiesStates.mpk"); mapService.setEnableDynamicLayers(true); WorkspaceInfoSet dynamicWorkspaces = mapService.getDynamicWorkspaces(); workspaceInfo = new WorkspaceInfo("WORKSPACE", WorkspaceInfo.WorkspaceFactoryType.FILE_GDB, "DATABASE=C:/data/arcgis/USA/usa.gdb"); dynamicWorkspaces.add(workspaceInfo); mapService.start(); dynamicLayer = new ArcGISDynamicMapServiceLayer(mapService.getUrlMapService()); ... } private void render(Renderer<Graphic> renderer, int layerId) { // Create new drawing info from our renderer, with set transparency DrawingInfo drawingInfo = new DrawingInfo(renderer, TRANSPARENCY); // Get the layerInfo from the dynamic layer and set the drawing info DynamicLayerInfoCollection layerInfos = dynamicLayer.getDynamicLayerInfos(); DynamicLayerInfo layerInfo = layerInfos.get(layerId); layerInfo.setDrawingInfo(drawingInfo); TableDataSource tableDataSource = new TableDataSource(); tableDataSource.setWorkspaceId(workspaceInfo.getId()); tableDataSource.setDataSourceName("Cities"); LayerDataSource layerDataSource = new LayerDataSource(); layerDataSource.setDataSource(tableDataSource); layerInfo.setLayerSource(layerDataSource); // Refresh the layer dynamicLayer.refresh(); }
Solved! Go to Solution.
This works at 10.1.1. The samples showing a simple dynamic workspace functionality workflow are in the sample app under 'Datasources' called 'Add Raster' and 'Add Shapefile'.
I've also just given Jan's code above a spin, i.e. modifying the Dynamic Layers 'Simple Renderer' sample, and that workflow works nicely as well. By switching one of the mpk layers to point to a local shp file instead, the 'render' button displayed/udpated my local shapefile's renderer, in my case instead of the 'states' layer. (Note that I used WorkspaceInfo.CreateShapefileFolderConnection("WORKSPACE", "c:/data/shapefile") to create the workspaceInfo in my test code, and I put my actual shp file name in tableDataSource.setDataSourceName("MyShapefile").)
workspaceInfo = WorkspaceInfo.CreateFileGeoDatabaseConnection("WORKSPACE", "c:/data/ArcObjectsData/portland/portland.gdb");
tableDataSource.setDataSourceName("Zones");
In general, I must agree with Carlos that limiting the capabilities of local gpk packages is a particularly pain point in moving to Runtime sdk from Engine.