首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CallOut弹出窗口不能通过放大/缩小进行自身定位

CallOut弹出窗口不能通过放大/缩小进行自身定位
EN

Stack Overflow用户
提问于 2013-12-13 18:35:59
回答 2查看 1.1K关注 0票数 3

我有一个带pins.When的Arcgis地图,我点击一个图钉,我在图钉上显示一个标注(弹出窗口),当我放大/缩小地图时,标注不会相对于map.How上的图钉定位,我可以在放大/缩小时始终在图钉顶部显示标注。

轻触引脚并弹出标注

和弹出的图像在放大时会远离图钉

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

下面是我对SymbolizingResults活动所做的更改

代码语言:javascript
复制
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;

}`
EN

回答 2

Stack Overflow用户

发布于 2013-12-27 23:12:39

麻烦的是这一行:

代码语言:javascript
复制
callout.show(map.toMapPoint(new Point(x, y)));

在这里,您说您希望在用户点击的位置显示标注。这就是示例所做的,并且在示例中总是有意义的,因为示例的图形都是多边形(即堪萨斯州的县)。

但是对于一个点,比如您添加的销,您不希望在点击的点处显示详图索引。如果点击的点距离引脚只有几个像素,然后你将其缩小,那么差异可能会有数百英里!相反,您希望在接点图形的点处显示详图索引。但您只想在它实际上是一个点的情况下执行此操作,因此您需要使用instanceof检查图形的几何形状。

我用下面的代码替换了上面的代码行,它可以工作了:

代码语言:javascript
复制
Geometry graphicGeom = gr.getGeometry();
if (graphicGeom instanceof Point) {
    callout.show((Point) graphicGeom);
} else {
    callout.show(toDroppedPinPoint);
}
票数 1
EN

Stack Overflow用户

发布于 2013-12-26 01:31:56

我看不到你如何放大和缩小的代码。但从逻辑上讲,您应该在放大和缩小中更新标注位置,就像在onSingleTap()中所做的那样。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20564327

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档