No the map doesn't have to be hosted on arcgis online. If you look at the sample I linked you'll see that we define the web map as follows - note that the urls to the map layers could point to your services.
webmap.itemData = {
"operationalLayers": [{
"url":layerURL,
"visibility": true,
"opacity": 0.75,
"title": "Soil Survey Map",
"itemId": "204d94c9b1374de9a21574c9efa31164"
}],
"baseMap": {
"baseMapLayers": [{
"opacity": 1,
"visibility": true,
"url": "http://services.arcgisonline.com/ArcGIS/rest/services/World_Terrain_Base/MapServer"
},{
"isReference": true,
"opacity": 1,
"visibility": true,
"url": "http://services.arcgisonline.com/ArcGIS/rest/services/Reference/World_Reference_Overlay/MapServer"
}],
"title": "World_Terrain_Base"
},
"version": "1.1"
};
Kelly,I have tried this code, but the Promise returned from esri.arcgis.utils.createMap(webmap, "map");
never invokes the success or failure events. Below I have listed my code used. Also, I have listed below my code a sample of the JSON provided to this print widget.Could you offer any insight as to why esri.arcgis.utils.createMap(webmap, "map");
is not working? I appreciate your prompt reply.Thanks!
/**
*
* Invoked when Flex viewer sends JSON map via event bus.
*
* @param data - JSON map
*/
function mapDataReceived(data) {
var webmap = {};
webmap.item = {
"title":"Soil Survey Map of USA",
"snippet": "Detailed description of data",
"extent": data.mapOptions.extent
};
webmap.itemData = data;
mapPromise = esri.arcgis.utils.createMap(webmap, "map");
var map;
mapPromise.then(mapCreationSuccess, mapCreationFailed);
}
function mapCreationSuccess(response) {
var map = response.map;
var printTask = new esri.tasks.PrintTask(config.EXPORT_WEBMAP_URL);
//TODO Change template to user options.
var template = new esri.tasks.PrintTemplate();
template.exportOptions = {
width: 500,
height: 400,
dpi: 96
};
template.format = "PDF";
template.layout = "MAP_ONLY";
template.preserveScale = false;
var params = new esri.tasks.PrintParameters();
params.map = map;
params.template = template;
printTask.execute(params, printResult, printError);
}
function mapCreationFailed(error) {
console.error("Unable to create map.");
}
JSON provided to mapDataReceived(..)
{
"exportOptions": {
"outputSize":[892,550]},
"mapOptions": {
"scale":141344140.17757848,
"extent": {
"ymin":-92.48878923766816,
"ymax":92.48878923766816,
"xmax":150,
"spatialReference": {
"wkid":4326
},
"xmin":-150}
},
"operationalLayers": [{
"url":"https://IPAddressToArcGISServer/arcgis/rest/services/ServiceName/MapServer",
"title":"BaseMap",
"id":"BaseMap"
}],
"layoutOptions": {
"legendOptions": {
"operationalLayers": [{
"id":"BaseMap"
}]}}}