Bring portal map in html file

449
8
11-26-2018 01:31 PM
MansiShah
New Contributor III

Hello,

I am trying to use the JS API v. 3.22 to bring my portal map into an HTML div in my index.html file. I am receiving a dojo call back error but when I click on the error it takes me to my portal where after the sign in and certificate recognition, I can see my map so I'm not sure why it is not able to show up in my index. If the authentication is the issue and if anyone else has run into that and can point me in the right direction on how to handle that and modify my code below (I've also attached it as a JS file below) I would greatly appreciate it.

When I go to the webmap in portal it does require me to recognize my certificate twice and ask me to sign in (all three of the steps are attached as screenshots below).

var map;
var newMap;

require([
"dojox/mobile",
"dojo/parser",
"dojo/dom",
"esri/map",
"dojo/domReady!",
"esri/arcgis/Portal",
"dojo/_base/connect",
"esri/urlUtils",
"esri/arcgis/utils"],
function(mobile, parser, dom, Map, Portal, arcgisPortal, connect, urlUtils, arcgisUtils){

parser.parse();

var portal = new arcgisPortal.Portal("https://servername/arcgis/"); //this works because we have connect as a function now
connect.connect(portal, 'onLoad', function() {
console.log("portal: ", portal);
console.log(portal.defaultVectorBasemap);
});
var newMap;

arcgisUtils.arcgisUrl = "https://servername/arcgis/";
console.log("after arcgisUtils.arcgisUrl");
arcgisUtils.createMap("769582fc23364618b2d3cee42aa67d0e", "viewDiv").then(function(response){
console.log("response: ", response);
newMap = response.map;
});
console.log("after createMap");

map = new Map("viewDiv",{
basemap: newMap,
center: [-122.45, 37.35],
zoom: 13
});

});

Thank you so much for any help.

0 Kudos
8 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Mansi,

  Have you tried using this sample and just replacing the webmap id with your own and the portal url too.

Web map by ID | ArcGIS API for JavaScript 3.26 

0 Kudos
MansiShah
New Contributor III

Robert,

I tried that and I get the error: "Uncaught SyntaxError: Unexpected token <" at 

https://servername/arcgis/home/webmap/viewer.html?webmap=/769582fc23364618b2d3cee42aa67d0e&f=json&ca...https://tfdm26-portal.tfdm.freedom.local/arcgis/home/webmap/viewer.html?webmap=/769582fc23364618b2d3...

When I copy and paste the above link in a new browser tab, it opens up to my portal webmap. 

Note: The slash that is added is front of the web id starting with 769 does not make a difference whether it is there or not.  

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Mansi,

  So you uncommented this line and changed the url to your Portal right

        //if accessing webmap from a portal outside of ArcGIS Online, uncomment and replace path with portal URL
        //arcgisUtils.arcgisUrl = "https://pathto/portal/sharing/content/items";
0 Kudos
MansiShah
New Contributor III

Yes I uncommented and tried to replace it with both my portal URL: https://servername/arcgis" 

as well as the URL that I see when I actually load up the webmap in my portal in the browser:

https://servername/arcgis/home/webmap/viewer.html?webmap=/769582fc23364618b2d3cee42aa67d0e

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Mansi,

  Notice the example url in that sample. "portal/sharing/content/items"

//arcgisUtils.arcgisUrl = "https://pathto/portal/sharing/content/items";
0 Kudos
MansiShah
New Contributor III

But that URL is not valid for our servers though. I get a 404 error meaning those files or folders don't exist for us. I can see my webmap in the portal using the links I have posted above though. Its starting to seem as if the issue is the certificates because when I go to the portal webmap in the browser, I am asked to click ok on my certificate as well as sign in. 

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Mansi,

  Well I am a bit out of my area of expertise here dealing with Portal url paths. Sorry I have no more advice.

KenBuja
MVP Honored Contributor

Your require modules aren't agreeing with the function arguments. This will always cause problems.

require([
"dojox/mobile",
"dojo/parser",
"dojo/dom",
"esri/map",
"esri/arcgis/Portal",
"dojo/_base/connect",
"esri/urlUtils",
"esri/arcgis/utils",
"dojo/domReady!"],
function(mobile, parser, dom, Map, Portal, arcgisPortal, connect, urlUtils, arcgisUtils){

Also, "dojo/_base/connect" has been deprecated and should be replaced by "dojo/on", "dojo/aspect", or "dojo/topic"