Select to view content in your preferred language

ArcGIS Feature Layer with Callouts not working properly

4008
1
07-12-2013 07:41 AM
JohnAllen
Deactivated User
I have one map document with the same layer added three times, each layer has a different color symbol. I published the map as a map service on our server. In my app I call each layer from the map service separately, each as ArcGIS Feature Layers.

When I open the map all three ArcGIS Feature layers appear.

Next, I have a callout set-up in my app. When you click on a point from one of the feature layers the callout is suppose to appear for each of the three feature layers, BUT the callout only appears for one of them.

The reason I set-up the app this way is because I initially had one ArcGIS feature layer with a callout and everything worked fine. Then, I needed to be able to turn different colored dots off, so thats when I went back and added the same layer three times with different colored dots for each in my published map document, then I called those layers separately in my app, now only one of the layers callouts work.

Only callouts for flayer are working.

Java Code:
public class Mapscreen extends Activity {

 public MapView map;  
  
 //Callout Variables
 private int m_calloutStyle;
 private Callout m_callout;
 private ViewGroup calloutContent;
 private Graphic m_identifiedGraphic;
 ArcGISFeatureLayer fLayer;
 ArcGISFeatureLayer fLayer1;
 ArcGISFeatureLayer fLayer2;
 ImageView CallOutClose;
 
 //Basemap Variables.
 ArcGISTiledMapServiceLayer basemapImagery;
 ArcGISTiledMapServiceLayer basemapTopo;

 /** Called when the activity is first created. */
 public void onCreate(Bundle savedInstanceState) {
  // Initial activity content view. (START)
  super.onCreate(savedInstanceState);
  setContentView(R.layout.mapscreen);

  // Retrieve the map layout and initial extent from mapscreen XML layout.
  map = (MapView) findViewById(R.id.map);   
  
  // Get basemaps
  basemapTopo = new ArcGISTiledMapServiceLayer(this.getResources().getString(R.string.WORLD_TOPO_MAP));
    
  // Add basemaps
  map.addLayer(basemapTopo); 
  
  // Get feature layer = Blue = No
  String URL = "http://...../MapServer/2";
  final ArcGISFeatureLayer fLayer2 = new ArcGISFeatureLayer(URL, MODE.ONDEMAND);
  
  // Get feature layer = Yellow = Unknown
  String URL1 = "http://...../MapServer/1";
  final ArcGISFeatureLayer fLayer1 = new ArcGISFeatureLayer(URL1, MODE.ONDEMAND);
    
  // Get feature layer = Green = Yes
  String URL2 = "http://...../MapServer/0";
  final ArcGISFeatureLayer fLayer = new ArcGISFeatureLayer(URL2, MODE.ONDEMAND);
  
  // Add feature layers
  map.addLayer(fLayer2);
  map.addLayer(fLayer1);
  map.addLayer(fLayer);  

  // This puts the ERSI logo on the bottom left corner of the screen once the map screen appears. This is mandatory by
                ESRI.
  map.setEsriLogoVisible(true);  
  
  LayoutInflater inflater = getLayoutInflater();
  // Get the MapView's callout from xml->identify_calloutstyle.xml
  m_calloutStyle = R.xml.facility_calloutstyle;
  // Get the layout for the Callout from layout->identify_callout_content.xml
  calloutContent = (ViewGroup) inflater.inflate(R.layout.facility_callout_content, null);  
  
  m_callout = map.getCallout();  
  m_callout.setContent(calloutContent);   

                //Callout Part - 1
  map.setOnSingleTapListener(new OnSingleTapListener() {

   private static final long serialVersionUID = 1L;

   @Override
   public void onSingleTap(float x, float y) {

    if (m_isMapLoaded) {
     // If map is initialized and Single tap is registered on screen identify the location selected
     identifyLocation(x, y);
    }
   }
  });
       }
// Initial activity content view. (END)

//Callout Part - 2
 /**
  * Takes in the screen location of the point to identify the feature on map.
  * 
  * @param x
  *            x co-ordinate of point
  * @param y
  *            y co-ordinate of point
  */
 private void identifyLocation(float x, float y) {

  // Hide the callout, if the callout from previous tap is still showing on map
  if (m_callout.isShowing()) {
   m_callout.hide();
  }

  // Find out if the user tapped on a feature
  SearchForFeature(x, y);

  // If the user tapped on a feature, then display information regarding the feature in the callout
  if (m_identifiedGraphic != null) {
   Point mapPoint = map.toMapPoint(x, y);
   // Show Callout
   ShowCallout(m_callout, m_identifiedGraphic, mapPoint);
   //Close button for the callout is initiated here.
   ImageView CallOutClose = (ImageView) findViewById(R.id.callout_close_button);
   CallOutClose.setOnClickListener(new View.OnClickListener() {
    
    @Override
    public void onClick(View v) {
     m_callout.hide();
     
    }
   });
  }
 }
 
 //Callout Part - 3
 /**
  * Sets the value of m_identifiedGraphic to the Graphic present on the
  * location of screen tap
  * 
  * @param x
  *            x co-ordinate of point
  * @param y
  *            y co-ordinate of point
  */
 private void SearchForFeature(float x, float y) {

  Point mapPoint = map.toMapPoint(x, y);

  if (mapPoint != null) {

   for (Layer layer : map.getLayers()) {
    if (layer == null)
     continue;

    if (layer instanceof ArcGISFeatureLayer) {
     ArcGISFeatureLayer fLayer = (ArcGISFeatureLayer) layer;
     // Get the Graphic at location x,y
     m_identifiedGraphic = GetFeature(fLayer, x, y);
    } else
     continue;
   }
  }
 }
 
 //Callout Part - 4
 /**
  * Returns the Graphic present the location of screen tap
  * 
  * @param fLayer
  * @param x
  *            x co-ordinate of point
  * @param y
  *            y co-ordinate of point
  * @return Graphic at location x,y
  */
 private Graphic GetFeature(ArcGISFeatureLayer fLayer, float x, float y) {

  // Get the graphics near the Point.
  int[] ids = fLayer.getGraphicIDs(x, y, 10, 1);
  if (ids == null || ids.length == 0) {
   return null;
  }
  Graphic g = fLayer.getGraphic(ids[0]);
  return g;
 }
 
 //Callout Part - 5
 /**
  * Shows the Attribute values for the Graphic in the Callout
  * 
  * @param calloutView
  * @param graphic
  * @param mapPoint
  */
 private void ShowCallout(Callout calloutView, Graphic graphic, Point mapPoint) {

  // Get the values of attributes for the Graphic
  String Name = (String) graphic.getAttributeValue("Name");
  String Phone = (String) graphic.getAttributeValue("Phone"); 

  // Set callout properties
  calloutView.setCoordinates(mapPoint);
  calloutView.setStyle(m_calloutStyle);
  calloutView.setMaxWidth(700);
  calloutView.setMaxHeight(500);

  TextView calloutTextLine0 = (TextView) findViewById(R.id.callout_content_textview0);     
  calloutTextLine0.setText("Name:" + " " + Name);
  
  TextView calloutTextLine1 = (TextView) findViewById(R.id.callout_content_textview1); 
  calloutTextLine1.setMovementMethod(LinkMovementMethod.getInstance());
  calloutTextLine1.setText("Phone:" + " " + Phone);
  
  calloutView.show();
 }  


0 Kudos
1 Reply
JohnAllen
Deactivated User
So, apparently the way I have my callout set up the callout only works with the last ArcGIS feature layer that is added.
So in my code above fLayer was added last, thus the callout worked for that layer. I switched it to have fLayer1 added last and the callout only worked that layer.

How can I modify the callout to work on all three layers?
0 Kudos