Hi GuysI am very new to arcgs and have a couple of questions.1. I am accessing a saved arcgs map using the call back for function createmap. I have added the basemap gallery to the map and this works and changes the base map without any problems. The only issue is that the basemap image gallery is not displaying the thumbnails. Are there any known issues with his?2. Is there a way / widget for the layer selector that can be added?3. Is there a way / widget for the search box?4. Is there an example of passing the username and password to create map to avoid the authentication challenge. Have seen some posts about using OAuth but could not quite get that to work.The map looks like attached[ATTACH=CONFIG]34178[/ATTACH]Ta,D
ready(function () { parser.parse(); var basemapGallery = new BasemapGallery({ showArcGISBasemaps: true, map: map }, "basemapGallery"); basemapGallery.startup(); // The web map id would need to be pulled from the database in a callback function arcgisUtils.createMap("mapid", "map").then(function (response) { // Update HTML display fields dom.byId("title").innerHTML = response.itemInfo.item.title; // + ' - ' + response.itemInfo.item.snippet; dom.byId("subtitle").innerHTML = response.itemInfo.item.snippet; var map = response.map; map.setBasemap('aa'); //////////////////////////////////////////////////////////////////////////////////// // Add map controls var scalebar = new Scalebar({map: map, scalebarUnit: "english"}); var home = new HomeButton({map: map}, "HomeButton"); home.startup(); // Assign to map to basemap basemapGallery.map = map; var geocoder = new Geocoder({map: map}, "search"); geocoder.startup(); var legendLayers = arcgisUtils.getLegendLayers(response); var legendDijit = new Legend({map: map, layerInfos: legendLayers}, "legend"); legendDijit.startup(); //////////////////////////////////////////////////////////////////////////////////// // Do the layers tick boxes var layers = response.itemInfo.itemData.operationalLayers; array.forEach(layers, function (layer) { new CheckBox({ id: "cb_" + layer.id, name: "cb_" + layer.id, checked: true, onChange: function (bool) { bool ? map.getLayer(this.id.split("_")[1]).show() : map.getLayer(this.id.split("_")[1]).hide(); } }, domConstruct.create("input", { id: "lyr_" + layer.id })).placeAt(dom.byId("layertoggle")); // create a label for the check box var label = domConstruct.create('label', { "for": "cb_" + layer.id, "id": "lbl_" + layer.id, "innerHTML": layer.title }); domConstruct.place(label, dom.byId("layertoggle")); domConstruct.place(domConstruct.create("br"), dom.byId("layertoggle")); domConstruct.place(domConstruct.create("br"), dom.byId("layertoggle")); }); }); });
I am guessing item 1 is a bug because when I look at the source of the image src I get an error saying the request is not run over ssl. Changing the url to https then retrieves the image.If I move the basemap image gallery outside of the createmap call back then it works (obviously requires a valid map for this to work).Ideas?Ta,D
glad to hear you were able to sort yourself out daniel! thanks for taking the time to share the solutions.
daniel,it would definitely be simpler, but it wouldn't be very secure to store usernames and passwords in your application source. 🙂if you'd like to authenticate on behalf of your end users, you should be using a proxy.the sample below doesn't spin up using createMap(), but comparable logic is used to force requests to a subscription routing service through a proxy which generates a token dynamically.directionshttps://developers.arcgis.com/javascript/jssamples/widget_directions_basic.html
Hi JohnWell they would not have to be stored in the source code as they would come from a database. In this case it does not really matter though as all the users know the logins (app is internal use only, that said they do not know someone else's login). Anyway does not matter if it can't so long as there is a way as having the challenge would really annoy my end users.Will have a look at the proxy and re-post later.Thanks for taking the time to respond,D
<?xml version="1.0" encoding="utf-8" ?> <ProxyConfig allowedReferers="*" mustMatch="false"> <serverUrls> <serverUrl url="http://services.arcgisonline.com" matchAll="true"/> <serverUrl url="http://arcgis.com" clientId="MYAPPID" clientSecret="MYSECRET" rateLimit="600" rateLimitPeriod="60" matchAll="true"> </serverUrl> </serverUrls> </ProxyConfig>
esriConfig.defaults.io.proxyUrl = "http://localhost:54254/proxy/proxy.ashx"; esriConfig.defaults.io.alwaysUseProxy = true;
Hi JohnI have had a look at the proxy solution and I can't say I am a fan of the extra config doing it this way.I have tried doing it this way.http://forums.arcgis.com/threads/90031-Bypass-Identity-Manager-with-ArcGIS.com-OAuth-token-object?highlight=bypass+loginthis for me is a much cleaner way of doing it but this does not work for me either. The code in the link still receives the challenge with a message saying I do not have access to the resource and if I use the 3.9 library there is no challenge and the map does not get drawn. I am running from localhost. The app set seems ok as I can get the token manually.Do you know if the above method works with 3.9?Ta,D
<serverUrl url="http://www.arcgis.com" username="john" password="doe" matchAll="true"> </serverUrl>
<!DOCTYPE html> <html> <head> <title>Create a Web Map</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"> <link rel="stylesheet" type="text/css" href="http://js.arcgis.com/3.8/js/esri/css/esri.css"> <style> html,body,#mapDiv,.map.container{ padding:0; margin:0; height:100%; } </style> <script>var dojoConfig = { parseOnLoad:true };</script> <script src="http://js.arcgis.com/3.9compact/"></script> <script> require([ "esri/map", "esri/arcgis/utils", "esri/urlUtils", "esri/config", "dojo/domReady!" ], function (Map, arcgisUtils, urlUtils, esriConfig) { //define proxy rule urlUtils.addProxyRule({ proxyUrl: "/sproxy/proxy.ashx", urlPrefix: "www.arcgis.com/sharing/rest" }); //swap for your own private webmap arcgisUtils.createMap("cd23069c1aeb44f79e072932d30bccac", "mapDiv"); }); </script> </head> <body> <div id="mapDiv"></div> </body> </html>
if (mustMatch) throw new ArgumentException("Proxy is being used for an unsupported service:");
Daniel, if you snoop the web traffic when you launch your application you should see that a request to retreive the private webmap json is specifically whats failing. http://www.arcgis.com/sharing/rest/content/items/cd23069c1aeb44f79e072932d30bccac/data?f=json this can be resolved by adding the following serverUrl tag to your proxy.config. <serverUrl url="http://www.arcgis.com" username="john" password="doe" matchAll="true"> </serverUrl> after updating your proxy.config, try adapting this sample (i just confirmed it works fine) <!DOCTYPE html> <html> <head> <title>Create a Web Map</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"> <link rel="stylesheet" type="text/css" href="http://js.arcgis.com/3.8/js/esri/css/esri.css"> <style> html,body,#mapDiv,.map.container{ padding:0; margin:0; height:100%; } </style> <script>var dojoConfig = { parseOnLoad:true };</script> <script src="http://js.arcgis.com/3.9compact/"></script> <script> require([ "esri/map", "esri/arcgis/utils", "esri/urlUtils", "esri/config", "dojo/domReady!" ], function (Map, arcgisUtils, urlUtils, esriConfig) { //define proxy rule urlUtils.addProxyRule({ proxyUrl: "/sproxy/proxy.ashx", urlPrefix: "www.arcgis.com/sharing/rest" }); //swap for your own private webmap arcgisUtils.createMap("cd23069c1aeb44f79e072932d30bccac", "mapDiv"); }); </script> </head> <body> <div id="mapDiv"></div> </body> </html>
yup. mustMatch="true" causes the proxy to compare the request to the whitelist in the proxy.config. if the url stub is not an exact match, it will throw an error rather than fetch the page and hand it back to you.from what i saw before, you had 'arcgis.com' but not 'www.arcgis.com'.
Hi JohnIndeed the issue was www however I am still having further trouble.It still challenges and debugging the proxy I see that the following json is returned when it tries to get the actual map.{"error":{"code":403,"messageCode":"GWM_0003","message":"You do not have permissions to access this resource or perform this operation.","details":[]}}I have admin rights on the system and am using my credentials. I have checked the map is shared etc but do not seem to be able to locate any other settings that might affect this. Any ideas?Thanks again for the taking the time to assist,D
I have just manually generated the token and manually constructed map call and I get the same error so I am it does not look like the proxy is causing the problem. Could it be layers on the map?
glad to hear i was able to help sort you out. you'll want to use either http or https across the board for resources and your actual application to avoid mixed protocol errors thrown by the browser.
http://yourmachine/folder/proxy.ashx?http://services2.arcgis.com/arcgis/blah....
Yeah thanks although not quite fine yet as still getting the challenges caused by the layers.At the mo i have routed everything through the proxy and added the config for the https://services2 address but no joy.
are your own REST services public or do they require authentication? if so, are you including the credentials for that specific resource in the proxy.config?if you try to use the proxy directly in the browser to access the REST endpoint is it successful?ie:http://yourmachine/folder/proxy.ashx?http://services2.arcgis.com/arcgis/blah....
you can set permissions on individual items (that you own) in ArcGIS Online by navigating to their item details page and clicking "share"[ATTACH=CONFIG]34341[/ATTACH]http://esrihack.maps.arcgis.com/home/item.html?id=a3e05a39087c4a768d43ae231ea158e0
<serverUrl url="http://www.arcgis.com" clientId="ID" clientSecret="SECRET" username="USER" password="PW" rateLimit="600" rateLimitPeriod="60" matchAll="true"> </serverUrl>
<serverUrl url="https://services2.arcgis.com/gGQziFjRK38YOiW5/arcgis/rest/services" clientId="ID" clientSecret="SECRET" username="USER" password="PW" rateLimit="600" rateLimitPeriod="60" matchAll="false"> </serverUrl>
<serverUrl url="https://services2.arcgis.com/gGQziFjRK38YOiW5/arcgis/rest/services" username="USER" password="PW" rateLimit="600" rateLimitPeriod="60" matchAll="false"> </serverUrl>
thats fine. you can tell them you'd like to work with me specifically if you want 🙂appId/appSecret should not be thought of as a way to authenticate and access shared content. those credentials are specifically intended to allow an application to access subscription services which burn credits without requiring someone to sign in, or provide information to identify an app which uses an OAuth2 technique to have people sign in with their own credentials to work with private content.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.