CreateDynamicLayerInfosFromLayerInfos() does not work with a .MPK that references an SDE Database.

4067
3
01-05-2015 05:16 PM
TrevorHooper
New Contributor II

It works if the .mpk is a does not reference the SDE but instead takes a copy of the layers. Another strange thing is that any Raster layers in the .MPK are not visible if the .mpk references the SDE DB but are if the .mpk is a copy. Does anyone have any ideas why this might be? And what I have to do when provisioning the .mpk that references the SDE DB so it works like the .mpk that takes a copy of the SDE layers.

I am using Runtime 10.24 For .Net

Thanks

Trevor

0 Kudos
3 Replies
MichaelBranscomb
Esri Frequent Contributor

Hi Trevor,

Please can you give some background on what you are trying to achieve and provide the code to reproduce the problem? (we can point at an SDE instance here)

Cheers

Mike

0 Kudos
TrevorHooper
New Contributor II

Hi Mike,

    Thanks for the quick reply.

I am programming a Runtime 10.24 .NET WPF application for a client. They have a large Oracle Geodatabase with a SDE front end. The application is using the LocalServer functionality to access the Geodatabase layers via a map Package. (They do not have the licencing required to publish a map service). As a proof of concept we have been using a small .mpk file so that I could program all of the functionality needed in the App without connecting to the SDE (I don't have permission). Everything works well with this .mpk

here is a link:   https://dl.dropboxusercontent.com/u/48200319/BDT_Test_AreaSmall.mpk

The problem has come up when we changed the MapPackage to one that References the SDE.

Link here: https://dl.dropboxusercontent.com/u/48200319/BDT_Test_AreaWithRasters.mpk

The problem occurs when using the BDT_Test_AreaWithRasters.mpk

problem 1: when I load the mpk with the code in the MyMapView_LayerLoaded handler commented out. All layers except for the 2 Raster layers show up in the Legend. (Of course no data is displayed as I don't have an SDE connection). So why don't the Raster layers show in the legend. If I leave the Rasters out of the MapPackage and have an SDE connection the data displays.

problem2: I want to re-order some layers and in a different place in the code be able to change renderers on "ITLBackgroundData"(0). To do this I need to get the DynamicLayerInfoCollection using

CreateDynamicLayerInfosFromLayerInfos(). This works fine when using BDT_Test_AreaSmall.mpk  but fails when using BDT_Test_AreaWithRasters.mpk

Any thoughts would be appreciated.

Cheers Trevor

Here is some code that should reproduce the problem:

Dim _localMapService As LocalMapService  'Global Variable

Private Async Sub LoadBackgrounds()

Try

Dim mySpatialReference As Esri.ArcGISRuntime.Geometry.SpatialReference

mySpatialReference = Esri.ArcGISRuntime.Geometry.SpatialReference.Create(3005)

MyMapView.Map.SpatialReference = mySpatialReference

Dim myEnvelope As Esri.ArcGISRuntime.Geometry.Envelope

myEnvelope = New Esri.ArcGISRuntime.Geometry.Envelope(1070635.92, 499061.341, 1071988.61, 499115.4)

MyMapView.Map.InitialViewpoint = New Esri.ArcGISRuntime.Controls.Viewpoint(myEnvelope)

_localMapService = New LocalMapService("..\..\MapData\BDTData\BDT_Test_Area.mpk", 1000000, True)

_localMapService.EnableDynamicLayers = True

Await _localMapService.StartAsync()

Dim arcGISDynamicMapServiceLayer As ArcGISDynamicMapServiceLayer

arcGISDynamicMapServiceLayer = New ArcGISDynamicMapServiceLayer()

arcGISDynamicMapServiceLayer.ID = "ITLBackgroundData"

arcGISDynamicMapServiceLayer.ServiceUri = _localMapService.UrlMapService

arcGISDynamicMapServiceLayer.IsVisible = True

MyMapView.Map.Layers.Add(arcGISDynamicMapServiceLayer)

Catch ex As System.Net.HttpListenerException

MessageBox.Show(ex.ToString)

End Try

End Sub

Private Sub MyMapView_LayerLoaded(sender As Object, e As LayerLoadedEventArgs) Handles MyMapView.LayerLoaded

If e.Layer.ID = "ITLBackgroundData" Then

If Not IsBusy Then

IsBusy = True

Dim myDynamicLayerInfos As DynamicLayerInfoCollection = (TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer)).DynamicLayerInfos

If myDynamicLayerInfos Is Nothing Then

myDynamicLayerInfos = (TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer)).CreateDynamicLayerInfosFromLayerInfos()

If Not myDynamicLayerInfos Is Nothing Then

MessageBox.Show("Layer infos OK")

Dim sourceArray(myDynamicLayerInfos.Count) As DynamicLayerInfo

myDynamicLayerInfos.CopyTo(sourceArray, 0)

TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer).DynamicLayerInfos = myDynamicLayerInfos

TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer).DynamicLayerInfos.RemoveAt(0)

TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer).DynamicLayerInfos.Add(sourceArray(0))

TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer).DynamicLayerInfos.RemoveAt(1)

TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer).DynamicLayerInfos.Add(sourceArray(2))

TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer).DynamicLayerInfos.RemoveAt(0)

TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer).DynamicLayerInfos.Add(sourceArray(1))

Else

MessageBox.Show("Layer infos Not OK")

End If

End If

End If

End If

End Sub

0 Kudos
TrevorHooper
New Contributor II

I have worked around this problem with the following code, If  CreateDynamicLayerInfosFromLayerInfos() fails, I Generate the DynamicLayerInfos one by one(This does not answer the question why the CreateDynamicLayerInfosFromLayerInfos() fails 😞

myDynamicLayerInfos = (TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer)).CreateDynamicLayerInfosFromLayerInfos()

                    If Not myDynamicLayerInfos Is Nothing Then

                        'MessageBox.Show("Layer infos OK")

                        Dim sourceArray(myDynamicLayerInfos.Count) As DynamicLayerInfo

                        myDynamicLayerInfos.CopyTo(sourceArray, 0)

                        TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer).DynamicLayerInfos = myDynamicLayerInfos

                        TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer).DynamicLayerInfos.RemoveAt(0)

                        TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer).DynamicLayerInfos.Add(sourceArray(0))

                        TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer).DynamicLayerInfos.RemoveAt(0)

                        TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer).DynamicLayerInfos.Add(sourceArray(1))

                        TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer).DynamicLayerInfos.RemoveAt(0)

                        TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer).DynamicLayerInfos.Add(sourceArray(2))

                        TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer).DynamicLayerInfos.RemoveAt(0)

                        TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer).DynamicLayerInfos.Add(sourceArray(3))

                    Else

                        myDynamicLayerInfos = New DynamicLayerInfoCollection

                        Dim lms As New LayerMapSource

                        lms.MapLayerID = 0

                        Dim dli As DynamicLayerInfo

                        Dim sourceArray2(19) As DynamicLayerInfo

                        Dim myLayerDataSource As Esri.ArcGISRuntime.Layers.LayerDataSource

                        For i = 0 To 19

                            dli = New DynamicLayerInfo

                            dli.Source = lms

                            dli.ID = i

                            myDynamicLayerInfos.Add(dli)

                        Next

                        myDynamicLayerInfos.CopyTo(sourceArray2, 0)

                        TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer).DynamicLayerInfos = myDynamicLayerInfos

                        TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer).DynamicLayerInfos.RemoveAt(0)

                        TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer).DynamicLayerInfos.Add(sourceArray2(0))

                        TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer).DynamicLayerInfos.RemoveAt(0)

                        TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer).DynamicLayerInfos.Add(sourceArray2(1))

                        TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer).DynamicLayerInfos.RemoveAt(0)

                        TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer).DynamicLayerInfos.Add(sourceArray2(2))

                        TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer).DynamicLayerInfos.RemoveAt(0)

                        TryCast(MyMap.Layers("ITLBackgroundData"), ArcGISDynamicMapServiceLayer).DynamicLayerInfos.Add(sourceArray2(3))

                        'MessageBox.Show("Layer infos Not OK")

                    End If

                End If

0 Kudos