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?
Solved! Go to Solution.
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?
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?
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:
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.
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.
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 ...
Actually, it isn't public at the moment but it's the backbone for MobileMapPackages.
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" }