Select to view content in your preferred language

Callout doesn't move with MapView.centerAt

4777
10
Jump to solution
03-01-2012 06:48 PM
StephenQuan
Deactivated User
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();  } }
0 Kudos
1 Solution

Accepted Solutions
AndyGup
Esri Regular Contributor
I've confirmed that this problem has been fixed in the upcoming v2.0 release of the SDK and the ArcGIS for Android app.

-Andy

View solution in original post

0 Kudos
10 Replies
AndyGup
Esri Regular Contributor
@Stephen The behavior you are seeing is most likely due to the application life cycle. I'm guessing that the Callout is being drawn before the pan animation has completed. As a test, if you set the centerAt() boolean animated property to false the behavior should go away:

map.centerAt(esri102100, false);


The best practice for setting this up is to implement an OnPanListener() and then show the Callout once the pan event is complete. The GeoRSSFeeds SDK sample shows a basic implementation of a map listener.

I'm also opening a ticket to take a closer look at it...just in case.

-Andy
0 Kudos
AndyGup
Esri Regular Contributor
This turned out to be a bug in SDK v1.0.1. It was entered as #NIM078920.

-Andy
0 Kudos
SimonKlein
Regular Contributor
Any information on this bug, as it is not fixed in 1.1?
0 Kudos
AndyGup
Esri Regular Contributor
Sorry for the delay, I am checking on this and hope to get more details on when it will be fixed.

-Andy
0 Kudos
VirenSavaliya
Emerging Contributor
Hello All,

I got solution.

                                  

   
  callout.setContent(body);
     callout.setStyle(R.xml.calloutxml);
     callout.setCoordinates(centerPT);
     map.zoomin();
     map.zoomToResolution(centerPT, 100);
     callout.show();



I used zoomin and zoomout fuction so map will reflect changes.

Try this.
0 Kudos
AndyGup
Esri Regular Contributor
I've confirmed that this problem has been fixed in the upcoming v2.0 release of the SDK and the ArcGIS for Android app.

-Andy
0 Kudos
JosephMarin
New Contributor
Hi Andy,
I'm using v2 on Android, and I still replicate this problem, just as the original poster described. Are you sure that it was fixed for 2.0?

Thanks,
Joe
0 Kudos
AndyGup
Esri Regular Contributor
@jwmarin Good catch. I tried it on a different test phone and was able to reproduce as well. I'll submit a ticket and post my findings.

-Andy
0 Kudos
AndyGup
Esri Regular Contributor
Sorry for the confusion, the issue has been reopened. In meantime please use this workaround:


        
// Show the callout at the correct location.
Callout callout = mMapView.getCallout(); 
callout.setContent(textView);
callout.setCoordinates(point);
callout.setStyle(R.xml.callout);
// @WORKAROUND - Force map to zoom in
mMapView.zoomToResolution(point, 100);
callout.refresh();
callout.show();


-Andy
0 Kudos