webmap_as_json for mapping.export_map method?

1995
5
12-18-2018 05:30 AM
RubénPérez_Planillo
New Contributor III

Hello,

We are developing a process to send an email with a map showing the location in case of emergency.

arcgis.mapping.export_map method request a map to the printing service configured in your organization. So it's the perfect method for us.

THe problem is where to get de json that represents the state of the MapView (zoom, layer´s visibility...)

#cosa = "{\"mapOptions\":{......"

#where to get webmap_as_json ??
out = arcgis.mapping.export_map(cosa,"PNG8","MAP_ONLY",gis=gis)
out‍‍‍‍‍

There is no an explicit method to obtain the 'webmap_as_json' variable which is the format that demands Printing service behind.

This is the specification of the json format:

ExportWebMap specification—Documentation (10.5) | ArcGIS Enterprise 

is there any chance of getting it? I did it on javascript, but i cannot find anything similar for python.

thanks for the help!

0 Kudos
5 Replies
KevinTientcheu3
New Contributor II

Hello Ruben,

Would the ArcGIS Online Assitant be useful?

ArcGIS Online Assistant 

You can click on 'I want to...' at the top and select veiw JSON.

I hope it helps!

0 Kudos
RubénPérez_Planillo
New Contributor III

Thanks for the answer.

ArcGIS Online assistant is a very useful app but it's not the answer to my problem.

export_map needs a representation of the state of a webmap, not the definition of the webmap which is the json I should get from ArcGIS Online.

This json is easy to obtain in other APIs, such as javascript, but it seems to be not available in python.

0 Kudos
DavinWalker2
Esri Contributor

Hi Ruben,

Did you end up having any luck with this?

0 Kudos
RubénPérez_Planillo
New Contributor III

Hello,

No luck on this. I far as I know there is no possibility of get this webmap_as_json directly from the API as You can do in javascript.

0 Kudos
MehdiPira1
Esri Contributor

Hi Rubén Pérez Planillo‌,

Map options and export options are not included in the web map json for export_map method in ArcGIS API for Python by default yet. As such, you need to insert those options into web map json first then run the export_map method.

from arcgis.gis import GIS
from arcgis.mapping import export_map

gis = GIS("portal or AGOL url", "username", "password")
webmap_item = gis.content.get("webmap id")
webmap_json = webmap_item.get_data()

# Modify json with map options and export options
webmap_json['mapOptions'] = {
    "extent" : {
        "xmin": webmap_item.extent[0][0],
        "ymin": webmap_item.extent[0][1],
        "xmax": webmap_item.extent[1][0],
        "ymax": webmap_item.extent[1][1],
        "spatialReference": {
            "latestWkid": 3857,
            "wkid": 102100
        }
    },
    "scale" : 24000,
    "spatialReference" : {
        "wkid" : 102100
    }
}

webmap_json['exportOptions'] = { "dpi" : 96,
                                 "outputSize" :  [746, 575]
                               }

out = export_map(web_map_as_json=webmap_json, format='PNG8', layout_template='MAP_ONLY', gis=gis)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

For a spatial reference variable, you can use "spatialReference" : webmap_item.spatialReference instead of hard-coding provided the web map is already spatially defined.

I hope that helps.

------------------------------------------------------------------------------------------------------------------------------------

Please mark as helpful if you find it helpful. If it answered your question please mark it as answered.