AnsweredAssumed Answered

Callout doesn't move with MapView.centerAt

Question asked by stephen_quan on Mar 1, 2012
Latest reply on Dec 18, 2013 by sandeepgs
Hi, I am encountering a problem when the Callout I create doesn't pan with the map programmatically on a call to MapView.centerAt().

To reproduce the problem:


  1. I create a MapView with the World_Street_Map service (i.e. the HelloWorldMap sample)

  2. I create a point that represents the ESRI HQ in WebMercator coordinates (by reprojecting it from 34.05691 latitude, -117.1957 longitude)

  3. I construct a Callout at this coordinate

  4. IF I STOP HERE, THE CALLOUT IS SPATIALLY IN THE CORRECT POSITION

  5. If I now call MapView.centerAt to the ESRI HQ the map pans so that ESRI HQ is in the center of the map, but the callout is now in Moreno Valley?!?!

  6. If I were to interactively pan the map the Callout will magically jump back to ESRI HQ in Redlands

Here is additional references and steps to reproduce the problem:

Here's my calloutstyle.xml (needs to be placed under res/xml folder):

<?xml version="1.0" encoding="utf-8"?>  <resources>  <calloutViewStyle    titleTextColor="#000000"    titleTextSize="10"    titleTextStyle="0"    titleTextTypeFace="0"    backgroundColor="#ffffff"     backgroundAlpha="255"    frameColor="#000000"    flat="true"    anchor="5" />  </resources>


Here's my Activity's main body (you may need to change package and class names to match your project):

package com.esri.android.calloutcentertest;  import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.widget.TextView; import android.widget.Toast; import com.esri.android.map.Callout; import com.esri.android.map.MapView; import com.esri.android.map.ags.ArcGISDynamicMapServiceLayer; import com.esri.android.map.event.OnSingleTapListener; import com.esri.core.geometry.GeometryEngine; import com.esri.core.geometry.Point; import com.esri.core.geometry.SpatialReference;  public class CalloutCenterTestActivity extends Activity {  MapView map = null;   /** Called when the activity is first created. */  public void onCreate(Bundle savedInstanceState) {   super.onCreate(savedInstanceState);   setContentView(R.layout.main);    // Retrieve the map and initial extent from XML layout   map = (MapView)findViewById(R.id.map);   map.addLayer(new ArcGISDynamicMapServiceLayer(    "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer")   );     // The map.getCallout().setCoordinates() / map.centerAt() bug.   Toast.makeText(this, "TAP SCREEN TO SHOW ESRI HQ", Toast.LENGTH_LONG).show();   final Context ctx = this;   map.setOnSingleTapListener(new OnSingleTapListener() {    private static final long serialVersionUID = 5173550791541184304L;     public void onSingleTap(float x, float y) {     Toast.makeText(ctx, "SHOWING ESRI HQ IN CALLOUT", Toast.LENGTH_SHORT).show();          // Create a point for ESRI HQ in WebMercator coordinate system.     Point esri4326 = new Point(-117.1957, 34.05691);     Point esri102100 = (Point) GeometryEngine.project(      esri4326,      SpatialReference.create(4326),      SpatialReference.create(102100)     );      // Construct the Callout content.     TextView textView = new TextView(ctx);     textView.setText("ESRI HQ");          // Show the callout at the correct location.     Callout callout = map.getCallout();      callout.setContent(textView);     callout.setCoordinates(esri102100);     callout.setStyle(R.xml.calloutstyle);     callout.refresh();     callout.show();          // The map pans to ESRI HQ but the callout stays behind!     map.centerAt(esri102100, true);          // If the user pans the map interactively, the callout corrects itself.    }   } );  }   protected void onPause() {   super.onPause();   map.pause();  }   protected void onResume() {   super.onResume();   map.unpause();  } }

Outcomes