I am trying to create stand-alone html file using ArcGIS JavaScript API. I can see it in sandbox, but when I saved the content of the html to my local html file. I cannot display it in my browsers. Any help? Thanks.
By the way, I have web map ID from my arcgis online map. Thanks.
Jian,
Are you trying to view it using file:// in your browsers address bar? if so then you need to place the html file in a virtual directory on your machines IIS or place the file in the c:\inetpub\www folder and then use http://localhost/yourhtmlfilename.html
Thanks. I tried per you suggestion, and it still failed. Actually I guess it may be caused by web map id part, please use this sample:
Web map by ID | ArcGIS API for JavaScript
//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";
arcgisUtils.createMap("4c009d4c236c4c0e91936b2fbfb085da","map").then(function(response){
//update the app
dom.byId("title").innerHTML = response.itemInfo.item.title;
dom.byId("subtitle").innerHTML = response.itemInfo.item.snippet;
you can try to copy the html content to create a stand-alone html file, and see how to open it with the browsers. I can open other sample without using web map id in my browsers, no matters where I saved that html file, this works:
Jian,
I have taken that exact sample and copied the code to a html file on my development laptop and using the non file:// url it works great:
file:///C:/JS_Workspace/WebMap%20(2).html - does not show map
http://gislap183/js/WebMap%20(2).html - shows map just fine
I can show other maps without using web map id, but cannot see this one with web map
Jian,
Like I said I can take that exact sample and copy it to my machine and if I use:
file:///C:/JS_Workspace/WebMap%20(2).html - does not show map
and if I use:
http://gislap183/js/WebMap%20(2).html - shows map just fine
Many other sample are file use file:///C:/JS_Workspace/whatever.html but that one is not.
Look at your browsers web console and you will see the error that is preventing you from using it.
It will be something like:
init.js:152 XMLHttpRequest cannot load file://www.arcgis.com/sharing/rest/content/items/4c009d4c236c4c0e91936b2fbfb085da?f=json. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
Which means you need to use http://machinename or http://localhost
Thanks. I put them in C:\inetpub\wwwroot, and used localhost. I did not get any response even errors from the html using web map, and I have no problems with the ones without using web map. Strange.
Jian,
And you opened your browsers developer tools (F12 button) and the web console did not report any errors?
The ArcGIS for Javascript API examples which include Web Map ID doe not work outside of a sandbox, i.e: Web map by ID | ArcGIS API for JavaScript 3.18 - the samples do not work, nor do they work if replaced with other webmap ID's in ArcGIS online shared with Everyone.
What's really strange is that their maps are indeed shared, i.e.: https://www.arcgis.com/home/webmap/viewer.html?webmap=ef9c7fbda731474d98647bebb4b33c20
The API samples simple don't work in any browser. But other sample code downloaded or copied work just fine.
Does anyone know why the Web Map ID sample code is broken?
Thanks, Jen