Select to view content in your preferred language

Couple of questions about the API

6448
40
05-29-2014 07:48 AM
DanielMclaglen
Emerging Contributor
Hi Guys

I 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
0 Kudos
40 Replies
DanielMclaglen
Emerging Contributor
Hi John

Ok I tried the other way so decided to go down the proxy route and the whole thing is driving me round the bend.
I tested the proxy and that returned correctly.

However when using it on my createmap it fails, I suspect it is fairly simple where the error as I could not figure out what the urlprefix should be. Anyway this is what I ended up doing and it routes via the proxy however there is still a challenge.

Proxy.config


<?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>



Hooking up to route via the proxy


            esriConfig.defaults.io.proxyUrl = "http://localhost:54254/proxy/proxy.ashx";
            esriConfig.defaults.io.alwaysUseProxy = true;



Any ideas where I am going wrong.

Ta,
D

Hi John

I 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?hi...

this 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
0 Kudos
JohnGravois
Deactivated User
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>
0 Kudos
DanielMclaglen
Emerging Contributor
Hi John

Thanks again for taking the time to post. I see the problem but have not had time to test as my main network internet connection has been down today (ironically failing on the proxy).

Will update once I have implemented the changes. Quick though and that is the mustMatch flag in the proxy config. Whenever it is set to true the proxy fails here.

        if (mustMatch)
            throw new ArgumentException("Proxy is being used for an unsupported service:");


According to the documentation it says
"When true only the sites listed using serverUrl will be proxied."

However whenever that is set to true the proxy fails -- again probably missing something silly here.

Thanks,
D

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>
0 Kudos
JohnGravois
Deactivated User
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'.
0 Kudos
DanielMclaglen
Emerging Contributor
Hi John

Indeed 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

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'.
0 Kudos
DanielMclaglen
Emerging Contributor
I have just manually generated the token and manually constructed map call and I get the same error so it does not look like the proxy is causing the problem. Could it be layers on the map?

Hi John

Indeed 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
0 Kudos
DanielMclaglen
Emerging Contributor
Ok I have got to the bottom of it and the proxy is working.
I created a new map with no layers and everything is fine.

The existing map has layers coming from

https://services2.arcgis.com
&
https://services.arcgisonline.com

So I would say the challenges are coming from here.

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?
0 Kudos
JohnGravois
Deactivated User
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.
0 Kudos
DanielMclaglen
Emerging Contributor
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.

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.
0 Kudos
JohnGravois
Deactivated User
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....
0 Kudos