4.0: Is there a way to create a WebMap from JSON instead of ArcGIS Online ID?

4138
3
Jump to solution
05-13-2016 01:33 PM
JeffJacobson
Occasional Contributor III

Is there a way to create a WebMap using ArcGIS REST API formatted JSON? What I would like to do is construct a map using a webmap defined in a JSON file on the same server as the web application rather than getting the JSON from ArcGIS Online (by providing an AGOL item id corresponding to a webmap).

Obviously, when you construct a WebMap object by providing an AGOL webmap item id, there must be code in the API that is parsing the returned JSON, but I am not finding any documented way to construct a webmap without hosting the map on ArcGIS Online or on a Portal.

0 Kudos
1 Solution

Accepted Solutions
KellyHutchins
Esri Frequent Contributor

There is a (currently) undocumented fromJSON property on the Web Map that you can use to load a web map from json. Here's a code example showing how it works:

JS Bin - Collaborative JavaScript Debugging

View solution in original post

3 Replies
PanagiotisPapadopoulos
Esri Regular Contributor

first export the Json for your Web map requesting the json with the following url

https://www.arcgis.com/sharing/content/items/4a4d0a1b5c1b4311839fd2c49e27d2b0/data?f=pjson

create webmap parameter

var webmap = {};

add webmap parameter item tag to host the map title

webmap.item = {

          "title":"Map Title",

          "snippet": "web"

        };

add webmap parameter itemData tag to host the JSON data (here place the json downloaded from arcgis online)

webmap.itemData = {

  "operationalLayers": [

    {

      "url": "http://12.18.20.190:6080/arcgis/rest/services/toc/ms_a/MapServer",

      "id": "lvn9638",

      "visibility": false,

      "opacity": 1,

      "title": "layer name"

    },

    {

      "url": "http://192.168.0.19:6080/arcgis/rest/services/toc/ms_a_x/MapServer",

      "id": "nvvf9234",

      "visibility": false,

      "opacity": 1,

      "title": "layer name"

    },

...........................

...........................

  ],

  "baseMap": {

    "baseMapLayers": [

{"id":"World_Light_Gray_Base_1486","layerType":"ArcGISTiledMapServiceLayer","opacity":1,"visibility":true,"url":"http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer"},

      {"id":"World_Light_Gray_Reference_4241","layerType":"ArcGISTiledMapServiceLayer","isReference":true,"opacity":1,"visibility":true,"url":"http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Reference/MapServer"}

    ],

    "title": "Light Gray"

  },

  "version": "1.9.1",

  "modifyMapAllowed": true

};

add the webmap parameter during the map creation from the createMap function

mapDeferred = esri.arcgis.utils.createMap(webmap, "map", {

  mapOptions : {

  slider : true,

  nav : false,

  wrapAround180 : true,

  center: [23, 39],

          zoom: 1,

  lods: lods,

  logo: false,

  showAttribution: false

  },

  ignorePopups : false,

  geometryServiceURL : app.geometryServ

  });

0 Kudos
PanagiotisPapadopoulos
Esri Regular Contributor

sorry this is for 3.16 API.

I just noticed you are asking for 4.0

0 Kudos
KellyHutchins
Esri Frequent Contributor

There is a (currently) undocumented fromJSON property on the Web Map that you can use to load a web map from json. Here's a code example showing how it works:

JS Bin - Collaborative JavaScript Debugging