CallOut弹出窗口没有放大/缩小的位置

时间:2013-12-13 10:35:59

标签: android arcgis esri

我有一个带有别针的Arcgis地图。当我点击一个别针时,我在针脚上显示一个标注(popover)非常精细。但是当我放大/缩小地图时,标注不会定位自己相对于地图上的图钉。如何在放大/缩小时始终在引脚顶部显示标注。

点击图钉并弹出标注 enter image description here

放大时弹出远离引脚的图像 enter image description here

注意:我对Arcgis地图应用的现有示例项目进行了更改,即SymbolizingResults

以下是我对SymbolizingResults活动进行的更改

public class SymbolizingResults extends Activity {

MapView map;
Button queryBtn;
GraphicsLayer gl;
Callout callout;

/** Called when the activity is first created. */

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    map = (MapView) findViewById(R.id.map);
    map.addLayer(new ArcGISTiledMapServiceLayer(
            "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"));

    gl = new GraphicsLayer();
    gl.setRenderer(createClassBreaksRenderer());
    Point p = new Point(37.6922222, -97.3372222);
    HashMap<String, Object> map1 = new HashMap<String, Object>();
    map1.put("NAME", "India");
    PictureMarkerSymbol pic = new PictureMarkerSymbol(this,getResources().getDrawable(R.drawable.pin_dest));
    Graphic gr = new Graphic(p,pic,map1);
    gl.addGraphic(gr);
    map.addLayer(gl);
    queryBtn = (Button) findViewById(R.id.querybtn);

    queryBtn.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // Sets query parameter
            Query query = new Query();
            query.setWhere("STATE_NAME='Kansas'");

            query.setReturnGeometry(true);
            String[] outfields = new String[] { "NAME", "STATE_NAME",
                    "POP07_SQMI" };
            query.setOutFields(outfields);
            query.setOutSpatialReference(map.getSpatialReference());

            Query[] queryParams = { query };

            AsyncQueryTask qt = new AsyncQueryTask();

            qt.execute(queryParams);

        }
    });

    // Sets 'OnSingleTapListener' so that when single tap
    // happens, Callout would show 'SQMI' information associated
    // with tapped 'Graphic'
    map.setOnSingleTapListener(new OnSingleTapListener() {

        private static final long serialVersionUID = 1L;

        public void onSingleTap(float x, float y) {


            if (!map.isLoaded())
                return;

            Point toDroppedPinPoint = map.toMapPoint(x, y);
            System.out.println("X : "+toDroppedPinPoint.getX());
            System.out.println("Y : "+toDroppedPinPoint.getY());

            int[] uids = gl.getGraphicIDs(x, y, 2);
            if (uids != null && uids.length > 0) {

                int targetId = uids[0];
                Graphic gr = gl.getGraphic(targetId);
                callout = map.getCallout();

                // Sets Callout style
                callout.setStyle(R.xml.countypop);
               /* String countyName = (String) gr.getAttributeValue("NAME");
                String countyPop = gr.getAttributeValue("POP07_SQMI")
                        .toString();*/
                // Sets custom content view to Callout
                callout.setContent(loadView("Anshul", "India"));
                callout.show(map.toMapPoint(new Point(x, y)));
            } else {
                if (callout != null && callout.isShowing()) {
                    callout.hide();
                }
            }

        }
    });

}

// Creates custom content view with 'Graphic' attributes
private View loadView(String countyName, String pop07) {
    View view = LayoutInflater.from(CalloutSampleActivity.this).inflate(
            R.layout.sqmi, null);

    final TextView name = (TextView) view.findViewById(R.id.county_name);
    name.setText(countyName + "'s SQMI");

    final TextView number = (TextView) view.findViewById(R.id.pop_sqmi);
    number.setText(pop07);

    final ImageView photo = (ImageView) view
            .findViewById(R.id.family_photo);
    photo.setImageDrawable(CalloutSampleActivity.this.getResources()
            .getDrawable(R.drawable.family));

    return view;

}`

2 个答案:

答案 0 :(得分:1)

问题在于这一行:

callout.show(map.toMapPoint(new Point(x, y)));

在这里,您要说的是要在用户点击时显示标注。这就是样本的作用,在样本中它总是有意义的,因为样本的图形都是多边形(即堪萨斯州的县)。

但是对于某一点,就像您添加的引脚一样,您不希望在分接点处显示标注。如果分接点距离引脚几个像素,然后缩小,差异可能是几百英里!相反,您希望在图形图形点显示标注。但是你只想这样做,如果它实际上是一个点,所以你需要用instanceof检查图形的几何。

我用这个替换了上面的行,它起作用了:

Geometry graphicGeom = gr.getGeometry();
if (graphicGeom instanceof Point) {
    callout.show((Point) graphicGeom);
} else {
    callout.show(toDroppedPinPoint);
}

答案 1 :(得分:0)

我看不到关于你如何放大的代码&amp;出。但从逻辑上讲,你应该在放大和放大时更新标注位置。缩小也就像你在onSingleTap()中那样。