MMPK: Bad Symbol Rotation

4440
23
Jump to solution
07-06-2017 09:45 AM
MarkCederholm
Occasional Contributor III

Attached is a small MMPK, created in Pro 2.0, that demonstrates a bad symbol rotation in Runtime 100.1 [I don't recall seeing this issue in Pro 1.4.1/Runtime 100.0, but I may be wrong].

Here's how it appears imported into Pro:

And here's how it appears in Runtime:

Tags (2)
0 Kudos
23 Replies
AnttiKajanus1
Occasional Contributor III

Ah, ofc. I was using an offline map and not mmpk file so you cannot access the geodatabase directly. As a workaround you need to do something like this then.  

offlineMapPackage = await MobileMapPackage.OpenAsync(offlineDataFolder);
offlineMap = offlineMapPackage.Maps.First();

await offlineMap.LoadAsync();
var featureLayers = offlineMap.OperationalLayers.OfType<FeatureLayer>().ToList();
var featureLayer = featureLayers.First();
var gdbTable = featureLayer.FeatureTable as GeodatabaseFeatureTable;
var gdb = gdbTable.Geodatabase;

var pointLayers = new List<int>();
for (int i = 0; i < gdb.GeodatabaseFeatureTables.Count; i++)
{
    var table = gdb.GeodatabaseFeatureTables[i] as GeodatabaseFeatureTable;
    if (table.GeometryType == GeometryType.Point)
         pointLayers.Add(i);
}

offlineMapPackage = await MobileMapPackage.OpenAsync(offlineDataFolder);
offlineMap = offlineMapPackage.Maps.First();
featureLayers = offlineMap.OperationalLayers.OfType<FeatureLayer>().ToList();
featureLayer = featureLayers.First();
gdbTable = featureLayer.FeatureTable as GeodatabaseFeatureTable;

foreach (var index in pointLayers)
{
     var table = gdbTable.Geodatabase.GeodatabaseFeatureTables[index];
     table.UseAdvancedSymbology = false;
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I couldn't figure other ways to workaround with this and the solution includes opening the mmpk twice. You can clean up the approach a bit but at least it works. The code below only work directly with mmpk that only has one geodatabase inside of it so if you have multiple, then you need to add logic to iterate the layers etc. I'm not sure what we can do to make this easier but I'll log an enhancement ticket for it.(EDIT: except fix the original issue so the workaround isn't needed)

0 Kudos
MarkCederholm
Occasional Contributor III

It works for a single-layer map, but in a multilayer map, only the first table is being loaded and has geometry info.

0 Kudos
JenniferNery
Esri Regular Contributor

Alternatively, you can load the map to get to its FeatureLayers and load their table to get GeometryType. Since UseAdvancedSymbology can only be set before table is loaded, you will need to clone the original layer and get its unloaded table and modify this property. Also, be sure to replace the original layer with cloned layer. Very similar to Antti's proposed workaround the only difference is not having to open MobileMapPackage twice and I believe you already attempted the clone.

var mmpk = await MobileMapPackage.OpenAsync(path);
var map = mmpk.Maps.FirstOrDefault();
await map.LoadAsync();
var layers = map.OperationalLayers.OfType<FeatureLayer>().ToArray();
foreach (var l in layers)
{
    await l.FeatureTable.LoadAsync();
    if (l.FeatureTable.GeometryType == GeometryType.Point)
    {
        var clone = l.Clone() as FeatureLayer;
        var table = (ArcGISFeatureTable)clone.FeatureTable;
        table.UseAdvancedSymbology = false;
        map.OperationalLayers.Remove(l);
        map.OperationalLayers.Add(clone);
    }
}
MyMapView.Map = map;
0 Kudos
MarkCederholm
Occasional Contributor III

Cloning a layer messes it up, I've discovered.  For example, the definition expression goes away, and somewhere a spatial reference goes away.  

I tried loading every table some time ago, but then the second time I try to load the map, it crashes.  After some more playing around with Antti's approach, I finally found a way to get it to work by loading each layer rather than the table itself:

          private async Task<List<int>> GetPointLayers(string sPath, int iMapIndex)
          {
               MobileMapPackage mmpk = await MobileMapPackage.OpenAsync(sPath);
               Map map = mmpk.Maps[iMapIndex];
               Geodatabase gdb = null;
               foreach (FeatureLayer fLyr in map.OperationalLayers.OfType<FeatureLayer>())
               {
                    await fLyr.LoadAsync();
                    GeodatabaseFeatureTable gfTab = fLyr.FeatureTable as GeodatabaseFeatureTable;
                    if (gdb != null)
                         continue;
                    gdb = gfTab.Geodatabase;
               }
               await map.LoadAsync();
               List<int> PointLayers = new List<int>();
               for (int i = 0; i < gdb.GeodatabaseFeatureTables.Count; i++)
               {
                    GeodatabaseFeatureTable gfTab = gdb.GeodatabaseFeatureTables[i];
                    if (gfTab.GeometryType != GeometryType.Point)
                         continue;
                    PointLayers.Add(i);
               }
               return PointLayers;
          }

As Antti said, hopefully the symbology problem will be fixed in the next release.

--Mark

0 Kudos
JenniferNery
Esri Regular Contributor

I see, thanks for posting the workaround that worked for you. I'm able to reproduce that Clone omits DefinitionExpression when set in the original. Apparently this clone issue is already logged. Hopefully these issues you found are resolved in future versions of the API. Thanks.

If table is already loaded and you only want to do this workaround when necessary, you can add this filter.

var useworkaround = ((ArcGISFeatureTable)l.FeatureTable).LayerInfo?.DrawingInfo?.Renderer?.ToJson()?.Contains("visualVariables") ?? false;‍‍
0 Kudos
MarkCederholm
Occasional Contributor III

FYI, the layer clone bug is still present at 100.6

0 Kudos
PreetiMaske
Esri Contributor

Thanks Mark. I see this bug is on the listed of candidate issues for upcoming release. I cannot promise or commit but I am very hopeful it will addressed in next release.  I will keep you posted 🙂

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

Hi,

The original issue should now be resolved in the recent v100.2 release.

Please download the latest Visual Studio extension from ArcGIS for Developers or update your NuGet packages via the NuGet package manager.

Cheers

Mike

0 Kudos
MarkCederholm
Occasional Contributor III

Looks like this problem has resurfaced in 100.5.  The old 100.1 workaround fixes it.

0 Kudos
MarkCederholm
Occasional Contributor III

The problem is still present in 100.6.  That's just plain pathetic!

0 Kudos