Couple of questions about the API

3658
40
05-29-2014 07:48 AM
DanielMclaglen
New Contributor II
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
New Contributor II
Slowly getting there (apologies as only day 2 working with the API).

Anyway worked out item 3 using the Geolocator widget.

Ta,
D

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
DanielMclaglen
New Contributor II
Solved item 2 now by manually constructing some check boxes from the layer info and attaching event logic for layer visibility.

Ta,
D

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
DanielMclaglen
New Contributor II
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

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
DanielMclaglen
New Contributor II
fixed item 1 by creating the basemap gallery outside of the callback and assign the map to the basemap gallery inside the callback.


            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
0 Kudos
JohnGravois
Frequent Contributor
glad to hear you were able to sort yourself out daniel!  thanks for taking the time to share the solutions.
0 Kudos
DanielMclaglen
New Contributor II
Thanks John.

I am most of the way there although item 4 is still a problem. I have added the app, generated the token & registered it using kernel.id however it is still not quite working.

I have not quite got to the bottom of it but it might be to do with running the VS project as local host / port number.
It would be so much simpler if we could simply pass usename and password into createmap.

Will post again when / if I locate the problem.

Ta,
D

glad to hear you were able to sort yourself out daniel!  thanks for taking the time to share the solutions.
0 Kudos
JohnGravois
Frequent Contributor
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.

directions
https://developers.arcgis.com/javascript/jssamples/widget_directions_basic.html
0 Kudos
DanielMclaglen
New Contributor II
Hi John

Well 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

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.

directions
https://developers.arcgis.com/javascript/jssamples/widget_directions_basic.html
0 Kudos
DanielMclaglen
New Contributor II
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


Hi John

Well 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
0 Kudos