popupInfo  featureLayer

3177
1
08-30-2013 06:45 PM
Yunus_SupriadiWijaya
New Contributor III
why  popupInfo always return null value?

if (featureLayer == null)
          return;
         PopupInfo popupInfo = featureLayer.getPopupInfo(layerID);
         if (popupInfo == null)
          return;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

map = new MapView(this);

ArcGISTiledMapServiceLayer basemap = new ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer");

ArcGISFeatureLayer fl1 = new ArcGISFeatureLayer("http://sampleserver5a.arcgisonline.com/arcgis/rest/services/LocalGovernment/Recreation/FeatureServer/0",ArcGISFeatureLayer.MODE.ONDEMAND); 
map.addLayer(basemap);
   map.addLayer(fl1);
setContentView(map);



map.setOnLongPressListener(new OnLongPressListener() {
      private static final long serialVersionUID = 1L;
      private ArcGISFeatureLayer featureLayer = null;

      public void onLongPress(float x, float y) {     
        if (map.isLoaded()) {
      if (progressDialog != null && progressDialog.isShowing() && count.intValue() == 0) 
       progressDialog.dismiss();

         // Get the point featurelayer
          Layer[] layers = map.getLayers();
         
          for (Layer layer : layers) {
          if (layer instanceof ArcGISFeatureLayer) {
           ArcGISFeatureLayer fl = (ArcGISFeatureLayer) layer;
           if (fl.getGeometryType() == Geometry.Type.POINT) {
            featureLayer = fl;
            break;
           }
          }
         }
          
          int layerID = (int) featureLayer.getID();         
         

         if (featureLayer == null) 
          return;
         PopupInfo popupInfo = featureLayer.getPopupInfo(layerID);
         if (popupInfo == null)
          return;
         
         // Create a new graphic
         Point point = map.toMapPoint(x, y);
         Graphic graphic;
         FeatureType[] types = featureLayer.getTypes();
         if (types == null || types.length < 1) {
          FeatureTemplate[] templates = featureLayer.getTemplates();
          if (templates == null || templates.length < 1) {
           graphic = new Graphic(point, null);
          }
          else {
           graphic = featureLayer.createFeatureWithTemplate(templates[0], point);
          }
         }
         else {
          graphic = featureLayer.createFeatureWithType(featureLayer.getTypes()[0], point);
         }

         // Instantiate a PopupContainer
         popupContainer = new PopupContainer(map);
         // Add Popup
         Popup popup = featureLayer.createPopup(map, 0, graphic);
         popup.setEditMode(true);
         popupContainer.addPopup(popup);
       createEditorBar(featureLayer, false);   

     // Create a dialog for the popups and display it.
         popupDialog = new PopupDialog(map.getContext(), popupContainer);
         popupDialog.show();
        }
      }
    
  });
  }

0 Kudos
1 Reply
EgorFedorov
New Contributor

I don't know exactly how to deal with this, but I've found that ArcGISFeatureLayer's method createPopupInfo() can create an instance of PopupInfo that can be added to FeatureLayer via setPopupInfos method.

Have you resolved your problem already?

0 Kudos