Map.ToJson()

1651
6
Jump to solution
09-14-2017 05:02 AM
JensBuchta
Occasional Contributor

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/...",
               "title": "styles",
               "type": "VectorTileLayer"
          },
          {
               "isReference": true,
               "layerType": "VectorTileLayer",
               "styleUrl": "https://www.arcgis.com/sharing/rest/content/items/b11b54e79acf4f9d8f6fbbdd5db97547/resources/styles/...",
               "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?

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
AnttiKajanus1
Occasional Contributor III

Hi Jens, 

Actually, ToJson only serializes values that are supported by the WebMap specification so there are a lot of properties that aren't supported by this. This also means that none of the local layers aren't supported by this serialization. Could you describe what you are using it for?

View solution in original post

6 Replies
AnttiKajanus1
Occasional Contributor III

Hi Jens, 

Actually, ToJson only serializes values that are supported by the WebMap specification so there are a lot of properties that aren't supported by this. This also means that none of the local layers aren't supported by this serialization. Could you describe what you are using it for?

JensBuchta
Occasional Contributor

Hi Antti,

thanks for your explanation.

Well, basically it's all about storing the definition of a map to disc. Let's say, I created a map based on a few (not only one) Runtime-Geodatabases and gave the user the possibility to change the symbology during runtime. Then, it'll be all great to store that on disk. I can do this on my own, of course, by iterating through basemap, OperationalLayers and so on.

But this will always be a file that:

  • never is complete (I will always miss something)
  • Will be a different file format if implemented by different people.

So it'll be great to have an API for that. Some kind of a "Mobile Map Definition" that references data in contrast to the Mobile Map Package that contains all data.

0 Kudos
AnttiKajanus1
Occasional Contributor III

Yeah, if you want to persist a map that is using stuff that the webmap is not supporting, you have to have custom serialization for it. Offline maps that we support (through OffineMapTask and MobileMapPackage) is based on extended webmap specification (mobile map specification) but it doesn't support all possible properties either since the workflows to use them are heavily based on the WebGIS model.

We have a feature item for supporting full offline map serialization but that isn't at the moment being worked with. I will link this issue to the feature requests as well. 

0 Kudos
JensBuchta
Occasional Contributor

Is the extented webmap specification (mobile map specification) public? I've never seen this, although I know about Web map specification overview | ArcGIS for Developers ...

0 Kudos
AnttiKajanus1
Occasional Contributor III

Actually, it isn't public at the moment but it's the backbone for MobileMapPackages.

0 Kudos
by Anonymous User
Not applicable

Hi antti kajanus -

When I add some operational layers to a map, then call Map.ToJson() with 100.3.0.2102, the resulting json has no operationalLayers element. 

I see it documented here as being part of the spec: operationalLayers | ArcGIS for Developers 

Please let me know if this is a bug with ToJson,  or if I am misinterpreting what is meant by webmap spec.

Thanks, Kirk

{
 "baseMap":{
 "baseMapLayers":[
 {
 "layerType":"ArcGISTiledMapServiceLayer",
 "title":"World Street Map",
 "url":"https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"
 },
 {
 "layerType":"ArcGISMapServiceLayer",
 "title":"MapserviceLayer",
 "url":"http://localhost:6080/arcgis/rest/services/avecc_test2//MapServer",
 "visibility":false
 }
 ],
 "title":"Streets"
 },
 "spatialReference":{
 "wkid":102100,
 "latestWkid":3857
 },
 "version":"2.9",
 "authoringApp":"RuntimeSDK",
 "authoringAppVersion":"100.3.0.2102"
}
0 Kudos