AnsweredAssumed Answered

Map.ToJson()

Question asked by j.buchtaesri-de-esridist Employee on Sep 14, 2017
Latest reply on Sep 14, 2017 by akajanus-esristaff

I wonder, if I've found a bug or if I'm just misunderstanding the Map.ToJson Method .

 

As it is documented to return "A string that is the JSON value for the map.", I thought that the following code should result in a cloned map:

// create the first map...
var firstmap = new Map(Basemap.CreateLightGrayCanvasVector());
var gdb = await Geodatabase.OpenAsync(gdbPath);
foreach(var table in gdb.GeodatabaseFeatureTables)
{
    await table.LoadAsync();
    Map.OperationalLayers.Add(new FeatureLayer(table));
}
Assert.IsTrue(Map.IsLoaded)

// clone it via json..
var json = Map.ToJson();
var secondMap = Map.FromJson(json);

 

Unfortunately, the second map isn't even close to be like the first one. It doesn't know about basemaps, operationalLayers, Min/MaxScale, .....

 

Looking at the json string, I can see that basemap information is included, but nothing about the OperationalLayers exists:

{
     "baseMap": {
          "baseMapLayers": [{
               "layerType": "VectorTileLayer",
               "styleUrl": "https://www.arcgis.com/sharing/rest/content/items/1e47168d181248e491541ffd5a91c0de/resources/styles/root.json",
               "title": "styles",
               "type": "VectorTileLayer"
          },
          {
               "isReference": true,
               "layerType": "VectorTileLayer",
               "styleUrl": "https://www.arcgis.com/sharing/rest/content/items/b11b54e79acf4f9d8f6fbbdd5db97547/resources/styles/root.json",
               "title": "styles",
               "type": "VectorTileLayer"
          }],
          "title": "Light Gray Canvas (Vector)"
     },
     "spatialReference": {
          "wkid": 102100,
          "latestWkid": 3857
     },
     "version": "2.8",
     "authoringApp": "RuntimeSDK",
     "authoringAppVersion": "100.1.0.1744"
}

 

(The actual use case is not cloning the map, but to store the map to disk, so Map.clone() isn't an alternative here).

 

Am I doing wrong?

Outcomes