JerryGarcia

Cannot identify layer in web map from ArcGIS Online

Discussion created by JerryGarcia on Apr 13, 2012
Latest reply on Jul 30, 2014 by efedorovdataeast
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());
            }
           }
          }        
          }
         }
       }
     });

Outcomes