Adding a layer to map .... use ArcGISDynamicMapServiceLayer with ArcGIS Server?

3008
9
04-03-2014 12:12 PM
GinaKiani
New Contributor
Hello
I am trying any way possible to add my own layer on top of a basemap using the ArcGIS SDK with Eclipse for Android
The samples from ArcGIS, (i.e.. AddLayer and AttributeEditor) use  new ArcGISDynamicMapServiceLayer
I have access to an ArcGIS server through my organization and have tried every way to upload my layer there which is hosed in "my content" and made public
Every time I add the url to the code however, it never displays....
I am wondering if maybe it is because I need a password to access my organization's ArcGIS server?
Can I program that in there somehow to make it work??

I have also tried to create a new map service from ArcGIS desktop, and have added my user name and password there, but that isn't working either 😞
Whether, via the dynamic service layer from my organization's arcGIS server, or any other way possible, .kml maybe?, is there any way at all that I can load my own data layer on top of a basemap in the Android application I am creating??
Thank-You So much for any help at all!!!
0 Kudos
9 Replies
ShellyGill1
Esri Contributor
Hi Gina,

If your content is not public, then you'll need to log in to authenticate an app with the portal. You could start with trying out this sample:
https://developers.arcgis.com/android/sample-code/featured-user-group/

This shows how you can log in and then retrieve content, and then go on to open a map. This sample has hardcoded credentials, but if you want to put some code for logging in into your own app, then you can read this topic:
https://developers.arcgis.com/java/guide/use-oauth-2-0-authentication.htm

And try out this sample:
https://developers.arcgis.com/android/sample-code/oauth2/

You could check the layer initialization to see if you get errors about not being able to access the layer you are loading - look at the MapView.setOnStatusChangedListener method and the OnStatusChangedListener interface:
https://developers.arcgis.com/android/api-reference/reference/com/esri/android/map/event/OnStatusCha...
Hope this helps
0 Kudos
GinaKiani
New Contributor
Hi
I really appreciate your response but don't think that's what I want to do....
From the look of it, a log-in would come up before anyone could view the map and I don't want to just give my account info out to the world, but I do want the public world to be able to see the data layer just by opening the android app
I did find another sample called "AddCSV2GraphicsLayer"
Could you offer any help in getting my own URL hosted .CSV layer to display in my map view?
Thanks!!!
0 Kudos
ShellyGill1
Esri Contributor
Hi Gina,

I re-read your post - when you say you have access to a server through your organization - is that an on-premises server physically on your companys network? If you have an on-premises ArcGIS for Server that's hosting your data, people outside your company firewalls may not be able to see that server. Is that the case? Or are you using ArcGIS Online to host your data, and have an organization account on this which is hosting your data - if you share that hosted data publicly, then it should be accessible to anyone without login.

A tip is if the URL of the services has a string of randome alphanumerics in it then it's probably not on-premises. E.g. here's the URL of a service I have hosted and made public on ArcGIS Online:
http://services1.arcgis.com/BOEfX71Wt2oRBpkR/arcgis/rest/services/Mountains1/FeatureServer/0
And here's the URL of a service on an ArcGIS for Server machine that is accessible publicly on the internet:
http://sampleserver6.arcgisonline.com/arcgis/rest/services/EmergencyFacilities/MapServer

Try adding either of these as a layer in code - I dont have any hosted dynamic map services, so for my service it would need to be added in an ArcGISFeatureLayer instead. Perhaps you can post the publicly accessible URL of your service so others can check if the URL is accessible? If so, then you should definitely be able to have anyone open your android app and see the map without needing to login or anything.
0 Kudos
RobertBurke
Esri Contributor
Hi Gina,

Just a followup. Since you say that you are looking in MyContent and you can see your service listed there, can have a look at the other columns that describe that service, like Type and Shared.  For Shared it could be Not Shared, Shared with Everyone, or shared with a specific group.  Is your's Everyone?  For Type, does it show up as a Feature Service, Tiled Map Service, Web Map?

If it's a FeatureService you may need to use a class besides ArcGISDynamicMapServiceLayer.

You also mentioned a sample, the Attribute Editor:
https://developers.arcgis.com/android/sample-code/attribute-editor/

Check out the sample code, copied and pasted below.  See how their ArcGISDynamicMapServiceLayer (first bit of code below) points to a MapServer/Map service?  And then the second bit of code points to a FeatureServer/Feature Service.  If the Item in Your Content is a Feature Service, you should use the ArcGISFeatureLayer class instead of ArcGISDynamicMapServiceLayer.

dmsl = new ArcGISDynamicMapServiceLayer("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSFields/MapServer");
    mapView.addLayer(dmsl);

    featureLayer = new ArcGISFeatureLayer(
            "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSFields/FeatureServer/0",
            MODE.SELECTION);
    setContentView(mapView);

If you could share the URL to your service and the bit of code where you instantiate the class, it would be helpful.

I hope this helps in some way.
0 Kudos
GinaKiani
New Contributor
Hello
I have been trying to figure this out since and have realized that the layers I am able to publish are feature services
Here are a couple of links to my content:
http://services1.arcgis.com/ZIL9uO234SBBPGL7/arcgis/rest/services/OaklandLandmarkPtsPly/FeatureServe...
http://services1.arcgis.com/ZIL9uO234SBBPGL7/arcgis/rest/services/OaklandLandmarkPtsPly/FeatureServe...

I did try to publish a dynamic service layer, but wasn't able to access my organizations server to do so....
Is there a way to do it maybe with the free arcgis.com account??

Thanks!!
0 Kudos
ShellyGill1
Esri Contributor
Hi,

When you say "wasn't able to access my organizations server to do so....", I'll take that as you don't have a separate ArcGIS for Server installation somewhere, you're talking about using hosted serviced via ArcGIS.com. With the hosted service I think you have a choice of tiled map service, or feature service - http://doc.arcgis.com/en/arcgis-online/share-maps/hosted-web-layers.htm#ESRI_SECTION1_5E584527C2BE44.... The option for a dynamic map service is only available if you have your own ArcGIS for Server installation, sorry for any incorrect or misleading comments previously (I would go back to edit to make sure it's clear for others reading the thread but only last post is editable). So as before, you can use a different class called ArcGISFeatureLayer to add these services to your Android app, e.g.
MapView map = (MapView) findViewById(R.id.map);
ArcGISFeatureLayer featureLayer = new ArcGISFeatureLayer("http://services1.arcgis.com/ZIL9uO234SBBPGL7/arcgis/rest/services/OaklandLandmarkPtsPly/FeatureServer/1", ArcGISFeatureLayer.MODE.ONDEMAND);
map.addLayer(featureLayer);

The code above works for me. I saw these services have been published with editing capability, so I was able to add a new landmark to the service you published.
0 Kudos
GinaKiani
New Contributor
Yes,
Exactly, You are right, I do not have ArcGIS server installed but am using my school's hosted service which, yes, does only allow me to publish tiled or feature services....
It's good to know that I simply cannot publish a dynamic service layer so I can quit wasting my time trying~
Using the code here, I have been able to preview my layer in my app!!
Thank-You so much for that!!
I don't suppose you might also be able to direct me to some documentation or tutorial on how I can now make that layer editable to the user or allow them to add features if they choose!?!?
I believe I need to add a graphics layer to do that for starters???
I truly appreciate any help you can offer!!
Thanks a bunch 🙂
0 Kudos
ShellyGill1
Esri Contributor
Great, glad we're helping somewhat - it can be quite a lot to understand when you first start of, how all the pieces fit together.

I don't suppose you might also be able to direct me to some documentation or tutorial on how I can now make that layer editable to the user or allow them to add features if they choose


So there's two parts to that - and the first bit you already did, which is make sure the hosted service is editable.

You do not need to add a separate GraphicsLayer, you can use the class you are already using, ArcGISFeatureLayer. A graphics layer has a lot in common with the ArcGISFeatureLayer (which actually inherits GraphicsLayer), but GraphicsLayer is not connected to a feature service (you make the graphics up yourself), whereas the ArcGISFeatureLayer is connected to the service and features come from the service. You'll see that the methods on ArcGISFeatureLayer that deal with the individual 'features' in the layer actually use take or return Graphic objects, so possibly this is where you were thinking a GraphicsLayer was required - read this for more info: http://developers.arcgis.com/android/guide/features-and-graphics.htm 

The second part is to actually add functionality to your app in Android to allow users to edit, which is a little bit more involved than just displaying. I would start by reading the topics under 'Edit Data' in the Guide:
http://developers.arcgis.com/android/guide/what-is-editing-.htm
There are separate topics listed here for creating (adding) new features, and for editing existing features geometry and/or attributes.

I'd also recommend trying out this sample: http://developers.arcgis.com/android/sample-code/attribute-editor/
This shows one way of letting users change attributes of existing features in a service. I would try changing this to point to your own service and see how that works. There is also a Geometry Editor sample, but note that one uses 'feature templates' - I noticed you dont have templates in your service, so that's maybe a step more complicated than you need at this point, but the reading the code should give you an idea how to let users add features anyway.

There's also another thing to consider, that we are introducing new ways of working with feature services - if you are working with 10.2 then all the above info is basically the way to go. But if you are working with 10.2.2 or intend to update to that or new releases, there is the 'GeodatabaseFeatureServiceTable' which is the new way of showing feature services, and dealing with editing of those service. However its still being worked on, so for a small project you can probably stick with the ArcGISFeatureLayer for now and get things working that way - you can always change your code later if the project has longevity. Some info about the upcoming release is here: http://blogs.esri.com/esri/arcgis/2014/04/04/get-ready-for-the-next-release-of-the-arcgis-runtime-sd....

Hope that helps, quite a lot of info, but it should be fairly straightforward to get some code working once you know what you're aiming at - let us know how you get on.
0 Kudos
GinaKiani
New Contributor
So happy to have some direction on where to start!!
Android programming definitely has been a little more difficult for me to pick up than other types I've had my hand at thus far....
Thank-You so much for all your help and all this info
It's nice to have a solid idea from someone knowledgeable to give more confidence to the steps forward  🙂
0 Kudos