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
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 } }
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?
@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.
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.
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 } }
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.