Cannot identify layer in web map from ArcGIS Online

5168
7
04-13-2012 09:16 PM
JerryGarcia
Occasional Contributor II
I am using some code from the "Popup In Web Map For Viewing Sample" to identify features.  I have a map service I authored with ArcGIS Online.  I imported shapefiles into ArcGIS Online to author the map.

When I try to identify features, the progressDialog never goes away.  I notices that the "layer" from the ArcGIS online map service is not an instance of either ArcGISFeatureLayer or ArcGISDynamicMapServiceLayer? 

Any suggestions for fixing the sample code to work with my ArcGIS online service?  Thanks!

       public void onSingleTap(float x, float y) {    
         if (map.isLoaded()) {
          // Instantiate a PopupContainer
          popupContainer = new PopupContainer(map.getContext());
          int id = popupContainer.hashCode();
          popupDialog = null;
          // Display spinner.
          if (progressDialog == null || !progressDialog.isShowing())
           progressDialog = ProgressDialog.show(map.getContext(), "", "Locating information...");

          // Loop through each layer in the webmap
          int tolerance = 30;
    Envelope env = new Envelope(map.toMapPoint(x, y), 40 * map.getResolution(), 40 * map.getResolution());
          Layer[] layers = map.getLayers();
          count = new AtomicInteger();
          for (Layer layer : layers) {
           // If the layer has not been initialized or is invisible, do nothing.
          
           if (!layer.isInitialized() || !layer.isVisible())
           continue;
         
           if (layer instanceof ArcGISFeatureLayer) {
              
           // Query feature layer and display popups
           ArcGISFeatureLayer featureLayer = (ArcGISFeatureLayer) layer;             
           if (featureLayer.getPopupInfo() != null && featureLayer.getPopupInfo().isInitialized()) {
            // Query feature layer which is associated with a popup definition.
            count.incrementAndGet();
            new RunQueryFeatureLayerTask(x, y, tolerance, id).execute(featureLayer);
           }
          }
          else if (layer instanceof ArcGISDynamicMapServiceLayer) {
           // Query dynamic map service layer and display popups.
           ArcGISDynamicMapServiceLayer dynamicLayer = (ArcGISDynamicMapServiceLayer) layer;
           // Retrieve layer info for each sub-layer of the dynamic map service layer.
           ArcGISLayerInfo[] layerinfos = dynamicLayer.getAllLayers();
           if ( layerinfos == null )
            continue;
          
           // Loop through each sub-layer
           for (ArcGISLayerInfo layerInfo : layerinfos) {
            // Obtain PopupInfo for sub-layer.
            PopupInfo popupInfo = dynamicLayer.getPopupInfo(layerInfo.getId());
            // Skip sub-layer which is without a popup definition.
            if ( popupInfo == null || ! popupInfo.isInitialized() ) {
             continue;
            }
            // Check if a sub-layer is visible.
            ArcGISLayerInfo info = layerInfo;
            while ( info != null && info.isVisible() ) {
             info = info.getParentLayer();
            }
            // Skip invisible sub-layer
            if ( info != null && ! info.isVisible() ) {
             continue;
            };

            // Check if the sub-layer is within the scale range
            double maxScale = (layerInfo.getMaxScale() != 0) ? layerInfo.getMaxScale():popupInfo.getMaxScale();
            double minScale = (layerInfo.getMinScale() != 0) ? layerInfo.getMinScale():popupInfo.getMinScale();

            if ((maxScale == 0 || map.getScale() > maxScale) && (minScale == 0 || map.getScale() < minScale)) {
             // Query sub-layer which is associated with a popup definition and is visible and in scale range.
             count.incrementAndGet();
             alertbox("RunQueryFeatureLayerTask","dynamic");
             new RunQueryDynamicLayerTask(env, popupInfo, dynamicLayer.getSpatialReference(), id).execute(dynamicLayer.getUrl() + "/" + layerInfo.getId());
            }
           }
          }        
          }
         }
       }
     });
0 Kudos
7 Replies
JerryGarcia
Occasional Contributor II
Here is a link to the web service I am trying to do an identify on.  I'd like to simple click on a line and return the attributes.  How do I do this with the Android API?

http://www.arcgis.com/home/webmap/viewer.html?webmap=50ff9d5984604f81ac5872355162f560

What type of layer is returned in the map service so I can do an identify?  Can someone provide a code snippet?  Thanks!

The layers from this service are not caught in any of the below:
if (layer instanceof ArcGISTiledMapServiceLayer) { }
if (layer instanceof ArcGISFeatureLayer) { }
if (layer instanceof ArcGISDynamicMapServiceLayer) { }
0 Kudos
SimonKlein
Occasional Contributor
Hi,

I would guess because it is a group layer

 //if we have a grouplayer we need to check the sublayers too for popups
    if(layer instanceof GroupLayer){
     Layer[] groupLayers = ((GroupLayer) layer).getLayers();
     for(Layer groupLayer:groupLayers){
      if (groupLayer instanceof ArcGISFeatureLayer) {
       // Query feature layer and display popups
       ArcGISFeatureLayer featureLayer = (ArcGISFeatureLayer) groupLayer;
       if (featureLayer.getPopupInfo() != null
         && featureLayer.getPopupInfo().isInitialized()) {
        // Query feature layer which is associated with a popup
        // definition.
        found=true;
        count.incrementAndGet();
        new RunQueryFeatureLayerTask(x, y, IDENTIFY_TOLERANCE,
          id).execute(featureLayer);
       }
      }



And btw. there is a special forum for the SDK http://forums.arcgis.com/forums/139-ArcGIS-for-Android-SDK


EDIT: ok after looking at your webmap I don't see any group layers. I would just recommend set a breakpoint and debug your layers array to see what's in there
0 Kudos
tempJamiePowell
New Contributor
Here are a few examples regarding performing an Identify on the line features mentioned. Looking at the data through both ArcGIS Online and the ArcGIS Server JavaScript API, the features can be identified successfully.  Also please look at the documentation regarding the identify task.

http://resources.arcgis.com/en/help/android-sdk/concepts/index.html#/Identify_task_sample/0119000000...

-------------------------------------------------------------------------------------------------------------------

1) IdentifyTask constructor : IdentifyTask(String url)
http://help.arcgis.com/en/arcgismobi...lang.String%29

2) IdentifyParameters constructor : IdentifyParameters(String url,
Geometry geometry,
Envelope mapExtent,
SpatialReference extentSR,
int[] layers,
int mapWidth,
int mapHeight,
int dpi,
boolean returnGeometry)

Constructor with required parameters.

Parameters:
url - the URL of the service to identify on
geometry - the geometry to identify
mapExtent - the current extent of the map
extentSR - the spatial reference of the map
layers - the array of layer IDs of the layers that the IdentifyTask will execute on
mapWidth - the width of the map in pixels
mapHeight - the height of the map in pixels
dpi - the dot-per-inch of the map displayed on the device
0 Kudos
JaySirinrat
New Contributor
Here are a few examples regarding performing an Identify on the line features mentioned. Looking at the data through both ArcGIS Online and the ArcGIS Server JavaScript API, the features can be identified successfully.  Also please look at the documentation regarding the identify task.

http://resources.arcgis.com/en/help/android-sdk/concepts/index.html#/Identify_task_sample/0119000000...

-------------------------------------------------------------------------------------------------------------------

1) IdentifyTask constructor : IdentifyTask(String url)
http://help.arcgis.com/en/arcgismobi...lang.String%29

2) IdentifyParameters constructor : IdentifyParameters(String url,
Geometry geometry,
Envelope mapExtent,
SpatialReference extentSR,
int[] layers,
int mapWidth,
int mapHeight,
int dpi,
boolean returnGeometry)

Constructor with required parameters.

Parameters:
url - the URL of the service to identify on
geometry - the geometry to identify
mapExtent - the current extent of the map
extentSR - the spatial reference of the map
layers - the array of layer IDs of the layers that the IdentifyTask will execute on
mapWidth - the width of the map in pixels
mapHeight - the height of the map in pixels
dpi - the dot-per-inch of the map displayed on the device



Hi Jamie,

I also have the same problem. I created a map with 4 operational layers from arcgis online and I got the webmap id for using in my code. How I can use the webmap id instead of map url in the sample (http://help.arcgis.com/en/webapi/javascript/arcgis/samples/find_drilldown/index.html).


Please help, thanks in advance

Jay
0 Kudos
AndreiGosman
New Contributor II
Hello,

I have exactly the same problem.

Has been an answer found?
0 Kudos
Sharadarya
New Contributor
Hello,

I am also facing the same problem. I am working on organization web map and trying to run this code on it. But it crashes on getting the graphics id from feature layer.
int[] ids = featureLayer.getGraphicIDs(x, y, tolerance);

I also noticed that ArcGIS collector application crashes on identify the feature on feature service.

What could be the problem ?

Thanks
Sharad Arya
0 Kudos
EgorFedorov
New Contributor

Hello.

I've met the same issue. I did not resolved it yet, but I assume that the problem is in featureLayer.getPopupInfo() method. It returns null and the following code do not work.

if (featureLayer.getPopupInfo() != null && featureLayer.getPopupInfo().isInitialized()) {

            // Query feature layer which is associated with a popup definition.

...

}

I've tried featureLayer.createPopupInfo(), and then featureLayer.setPopupInfos(...), but this is not enough for editing feature (popup does not show any editable content). Continue exploring...

0 Kudos