add shapefile or layer package dynamically

4028
7
05-05-2014 12:19 PM
Labels (1)
FrancoisGilbert
New Contributor
Hello,

I have completed the first phase of my wpf application and I am happy with the results.

Now I would like to add the capability to dynamically add layers to my app. that already have map loaded. Currently my appliction is loading LocalDynamicMapServiceLayer that are written in a ini file.

I have seen the sample project that gives the possibility to add shapefile (however I would like to have sample .shp files with the demo). Is there shapefiles that comes with the demo on arcgis online. When I ran the demo, the shapefiles are loading but I was not able to see them. However, for the technical side, I understood that the layer comming from the shapefiles was added offline inside an empty map package.

Now, I would also like to read something that would help me to understand how I can add a layer package. I think a simple layer can be loaded when it is part of a map. For the layer package, it is not part of a map and I am not sure if ArcGis runtime can load the layer package directly or you need to create also an empty map package that will be the content of the layer package.

Regards
0 Kudos
7 Replies
MichaelBranscomb
Esri Frequent Contributor
Hi,

Re: Shapefiles:
If the Shapefiles are not displaying it could be a problem with your data source definition, or alternatively with the renderer. You can test the layer is being successfully added/referenced by using a QueryTask and setting the Source property which will ensure it queries the dynamic layer definition. If you get results then it could instead be a problem with the renderer definition. In this case, verify the geometry type of the layer you are adding, and depending on the type of renderer, if for example it is a UniqueValueRenderer, verify the field names. You can also view the requests in Fiddler to verify everything looks ok.

As discussed in other forum threads, eventually we do plan to support direct read of shapefiles in the ArcGIS Runtime, but this will be introduced in the forthcoming ArcGIS Runtime SDK for .NET.

RE: Layer Packages:
Unfortunately Layer Packages are not currently supported in the ArcGIS Runtime LocalServer. If you would like to see this feature in a future release, please post the idea at http://ideas.arcgis.com/ideaList?category=ArcGIS+Runtime.

Cheers

Mike
0 Kudos
FrancoisGilbert
New Contributor
Mike,

My appologies for the shapefile, it is working. Concerning the layer package, I will post the request.

Concerning the addition of an individual layer, I suppose that if we publish a dynamic map, the application could browse into that map to load a single layer inside that map. This mean that the person who publish the individual layer will have to include it in an empty map service. Is there any way to add a single layer without using a map service?

François
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
Hi François,

Please can you clarify what you mean by an 'individual layer'?

If it is an individual layer within a map service, then you would need to add the whole service via the API and set the visibility of the sub layers on the service. Alternatively you might consider using a feature layer but it depends what functionality/behaviour you require from the layer in the map.

Cheers

Mike
0 Kudos
FrancoisGilbert
New Contributor
Mike,

In my application, when it starts, I see 2 things in the table of content.

1. The weather forecast : it has many raster layer and it is stored in a map package.
2. The watershed boundaries and weather station that is stored in another map package.

After the application ran, I would like to put a button to be able to add a feature layer. I suppose that feature layer would appear in the third layer group and that I have to store that feature layer in an empty map package before I start the service. What I do not know is where the source data comes from. Is it a part of a map service that is already running or it simply comes from a layer file I do not know.

François
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
François,

It sounds like you would like to develop functionality which will allow the user to add any dataset/service to your application? Browsing for service-based layers and browsing for local content are two very different concepts and therefore the activities are best separated in the UI.

* Local content: When browsing for local content such as a shapefile or file geodatabase feature class the workspace in which the dataset resides must be registered with the local service before the service is started (workspaces cannot be set whilst the service is in the Starting, Running or Stopping state). You might choose to use a new local map service each time, or use a single map service in a workflow where you stop the service, add the new workspace and restart the service again. I would recommend a new service but it may depend how many datasets your users can add to the application. You can add the layer to the map as either a dynamic map service layer or a feature layer but in either case it must use the dynamicLayer endpoint of the map server. Feature services do not support the dynamicLayer capability. Note the dataset on disk is not related to the original Map Package from which you started the service. Everything is happening dynamically on a per request basis. It may help to examine the requests in Fiddler to understand fully what is happening behind the scenes.

* Online content: When browsing for online content, such as a map service, you may need to browse into the service if you want the user to have the ability to add an individual layer. In this case you will need to write some functionality to query the service and display the sublayers in a dialogue allowing the user to pick a specific layer although you would be referencing the entire service via the API. The same principle applies to feature services too but in that case you must always add a specific sub layer of the service as a featurelayer.

Cheers

Mike
0 Kudos
FrancoisGilbert
New Contributor
Mike,

Thank you. That clarifies the situation. I wish ESRI would have had a programming model that would allow developer to be isolated from online or offline content but that might append in the future but this would probably break the whole programming model. However, you explained well how it works and I can manage a solution with it.

Regards
François
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
François,

An excellent suggestion to unify the programming model for online and offline content and one we are already implementing in various ways in the new ArcGIS Runtime SDK for .NET (https://developers.arcgis.com/net/), for example:

- FeatureLayers have a FeatureTable property which can be either a local GeodatabaseFeatureTable or an online GeodatabaseFeatureServiceTable.
- RouteTask can be created as an OnlineRouteTask or a LocalRouteTask.

In both those examples, once you are working with the FeatureTable or the RouteTask, the API is basically the same regardless of whether the source content is local or online. Of course there are some types of content where this approach cannot be applied, but we are trying to improve the overall experience.

Cheers

Mike
0 Kudos