Print webmap id to the console from a client browser session to a web mapping application

1545
14
Jump to solution
05-31-2019 08:36 AM
AndresCastillo
MVP Regular Contributor

 Robert Scheitlin, GISP Champion,Ken Buja‌, Rene Rubalcava

If I am in a client browser session to a web mapping application, say http://gis.wpb.org/PublicWorksGridViewer/,

how would I print the webmap id to the console?

I was able to get it before, I just haven't remembered yet.

I've tried variations of the following, and nothing works as of yet:

console.log(webMap.itemId)

console.log(map.itemId)

console.log(map.itemInfo)

etc

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Andres,

   I am not an Admin in the "Enterprise GIS" GeoNet space that you have this question in. If you move this discussion to the Web AppBuilder for ArcGIS space where it really should be then I can convert this discussion to a Question.

For the AGOL application you can get the webmap in the console using:

this.config.webmap

For a WAB app running in Node.js you can use:

this.appConfig.map.itemId

For a deployed WAB Developer app use:

window._viewerMap.itemId

esri/arcgis/utils is a core JS API module that is used to create a map class out of a WebMap Id and has other methods.

View solution in original post

14 Replies
RobertScheitlin__GISP
MVP Emeritus

Andres,

   If the code is inside a widget then it would be:

console.info(this.map.itemId);

AndresCastillo
MVP Regular Contributor

Robert,

I don't think the web map id would be inside a widget, would it?

I would just want to find out the web map id that the web mapping application is using.

I want to do this from the client's console.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

OK then use:

window._viewerMap.itemId

AndresCastillo
MVP Regular Contributor

Thank you Robert, although both

console.info(window._viewerMap.itemId);

and

console.log(window._viewerMap.itemId);

return 'undefined' to the console.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Andres,

  So I am confused then. If you want to do this from the clients console window then you are not inside any JS code and you would just type "window._viewerMap.itemId" at the > prompt when you are in the console window. If you are adding this to some code inside the app then you would use console.log or console.info.

AndresCastillo
MVP Regular Contributor

Robert,

I see what you mean now.

It was me that didn't know not to put a console method call while inside of a clients' console.

Thank you so much.

How did you know to use the '_viewerMap' object?

Did you know it was named that way?

I was looking within the web application's source code files to see where and how the webMap object was defined and named, such as:

require([

    "esri/WebMap",

    "esri/views/MapView"

], function(WebMap, MapView) {

var map = new WebMap({ 
portalItem: { 
id: "" 
} 
});  ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Which JS file would I find that require esri/WebMap in?

Edit:

Also, How would I approach the application programmatically to find out where that required module lives?

I'd like to mark your answer as correct, but my original question is more focused to making a script that will loop through all the applications, and return the web map id's at once.

Since you answered this additional question in an awesome manner, would it be appropriate for me to branch it off as of my comment on May 31, 2019 4:51 PM, so that I could mark your reply as correct?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Andres,

How did you know to use the '_viewerMap' object?

Previous development work on the Local Layer widget. In the MapManager.js it is set there:

window._viewerMap = map;

Did you know it was named that way?

Same answer as above

Also, which JS file would I find that require esri/WebMap in?

No where. WebMap is not used in the code it is just Map. esri/arcgis/utils is used to get a Map class from a web map id.

Since you answered this additional question in an awesome manner, would it be appropriate for me to branch it off as of my comment on May 31, 2019 4:51 PM, so that I could mark your reply as correct?

Yes

AndresCastillo
MVP Regular Contributor

Hi Robert,

I have branched this discussion, and marked all your replies as helpful.

Unfortunately, the site is not giving me an option to mark your reply as correct.

Maybe this discussion's admin can chime in here?

Can you expand on what 'esri/arcgis/utils' is?

Is it the utils.js file inside of jimu.js?

If I were to attempt to search for a module in the code that was introduced via require, how would I approach the application in a programmatic way to find out in which file of the application that module lives?

0 Kudos
AndresCastillo
MVP Regular Contributor

I think I notice why it won't let me mark it as correct.

Because when I branch, it only gives me the option to branch as 'discussion', not a new question.

If you want, I can create a brand new question, copy and paste all threads, let you reply to that, and mark your reply correct.

Unless you can provide a better way?

I also notice that on apps like this:

http://wpbgis.maps.arcgis.com/apps/Viewer/index.html?appid=3de4db80b6474e2f8069097d71560e8c

The "window._viewerMap.itemId" does not even exist.

Maybe because it is a different app template?

And

When I am in the wab dev configurator site, such as:

https://<machineName>/webappbuilder/?id=30

The "window._viewerMap.itemId" does not even exist.

I know I can see the web map in the configurator's "more details" of the map tab, but

How do you recommend I go about finding the web map id from a client browser session in these cases?

0 Kudos