Web Map Popups/ Get ArcGISFeatureLayer from ArcGISDynamicMapServiceLayer

4562
8
Jump to solution
02-28-2012 09:58 PM
SimonKlein
Occasional Contributor
Hi,
I use different Web Maps in my application and and each consists of different ArcGISDynamicMapServiceLayer with 1 or more feature layers and some tiled layers.
When i press one of the featurelayer graphics on the map i want to display the coresponding Popup. The problem is i can not seem to find a way to get the feature layer from the ArcGISDynamicMapServiceLayer. I only get ArcGISLayerInfo which are not useful for my purposes. Am i missing something or is there another way to do this? Thanks
0 Kudos
1 Solution

Accepted Solutions
ArchanaAgarwal
New Contributor III
There is no need to instantiate a FetureLayer from a sub-layer of a DynamicLayer if the user wants to show
Popup for that sub-layer and the popup is configured in a web map. All the user needs to do are to retrieve
the popupInfo and graphic from the sub-layer. One of our samples "PopupInWebmapForViewing" demonstrates
how to show popups for DynamicLayer and FeatureLayer. The following code snippet is for DynamicLayer.


          // 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.
            new RunQueryDynamicLayerTask(env, popupInfo, dynamicLayer.getSpatialReference(), id).execute(dynamicLayer.getUrl() + "/" + layerInfo.getId()); // get graphics and show popup
           }
          }

View solution in original post

0 Kudos
8 Replies
SimonKlein
Occasional Contributor
Ok, basically i just want to get the ArcGISFeatureLayers out of an ArcGISDynamicMapServiceLayer.
ArcGISLayerInfo is not an option if i want to get the graphics from the ArcGISFeatureLayer.
Any ideas?
0 Kudos
AndyGup
Esri Regular Contributor
@simra Did you check out the SelectFeatures sample that comes with the SDK install? I think that covers the basics of what you are trying to do.

You have to specify a new ArcGISFeatureLayer(), add that to the map, and then finally set up a MapOnTouchListener(). The pattern for doing this is demonstrated in that sample.

-Andy
0 Kudos
SimonKlein
Occasional Contributor
Thanks for your answer but my problem is a little different.
I have an web map which structure is looking like this:
The web map itself

  • ArcGISTiledMapServiceLayer (The basemap)

  • ArcGISDynamicMapServiceLayer

  • [INDENT]FeatureLayer[/INDENT]
    [INDENT]FeatureLayer[/INDENT]
  • ArcGISDynamicMapServiceLayer

  • [INDENT]FeatureLayer[/INDENT]

So when i add the web map to a map view i can call mMapView.getLayers() which gives me Layer Objects which i can cast into DynamicLayers or TiledLayers what i want, thats fine. But when i have my ArcGISDynamicMapServiceLayer which consists of FeatureLayers (in this case Graphics) i want to use to create a Legend and to create a Popup from this FeatureLayer.
So, i get an ArcGISDynamicMapServiceLayer from the map with getLayers() but for the later use i need to get actual ArcGISFeatureLayer objects from the ArcGISDynamicMapServiceLayer. But the ArcGISLayerInfo objects only get me the ID of the FeatureLayer. Because of this i would need to create new ArcGISFeatureLayers based on the URL of the ArcGISDynamicMapServiceLayer and the ID, add this to the map to get fully initialized and loaded. To double all Featurelayers on the map is not an option in some maps i have and also it looks silly.

Thanks!
0 Kudos
ArchanaAgarwal
New Contributor III
There is no need to instantiate a FetureLayer from a sub-layer of a DynamicLayer if the user wants to show
Popup for that sub-layer and the popup is configured in a web map. All the user needs to do are to retrieve
the popupInfo and graphic from the sub-layer. One of our samples "PopupInWebmapForViewing" demonstrates
how to show popups for DynamicLayer and FeatureLayer. The following code snippet is for DynamicLayer.


          // 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.
            new RunQueryDynamicLayerTask(env, popupInfo, dynamicLayer.getSpatialReference(), id).execute(dynamicLayer.getUrl() + "/" + layerInfo.getId()); // get graphics and show popup
           }
          }
0 Kudos
SimonKlein
Occasional Contributor
This way it works. Thanks!
0 Kudos
FrankHochstrate
New Contributor
Hi,

I've got a similar problem, but in my case

PopupInfo popupInfo = dynamicLayer.getPopupInfo(layerInfo.getId());
always retuns null ( popupInfo == null).

Where exactly do I have to define the popup-information for a specific layer?

I started from an mxd (connected to a fgdb) and published it as a ArcGIS Server Service (Map Service).

Using this MapService in my Android-App (modified ESRI example PopupInWebmapForViewing) does not show any popups because dynamicLayer.getPopupInfo always returns null.

Any ideas?

Thanks in advance.
0 Kudos
imritanshu
New Contributor III

hey frank,

Did u find the solution for this problem? m also facing same issue with my featurelayer.

If u got any solution please let me know.

your help will be most appreciate.

Thanks...

Rhitz

0 Kudos
VivekRane
New Contributor
Is it possible to show popups in shapefiles?
0 Kudos