Android 调用弹出窗口不';t通过放大/缩小来定位自身

Android 调用弹出窗口不';t通过放大/缩小来定位自身,android,arcgis,esri,Android,Arcgis,Esri,我有一个带图钉的Arcgis地图。当我点击图钉时,我会在图钉上显示一个标注(popover),效果非常好。但是当我放大/缩小地图时,标注不会相对于地图上的图钉定位。在放大/缩小时,我如何始终在图钉顶部显示标注 轻触插针,弹出标注 以及放大时弹出窗口远离pin的图像 注:我已对Arcgis地图应用程序的现有示例项目进行了更改,即 以下是我对SymbolizingResults活动所做的更改 public class SymbolizingResults extends Activity {

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

轻触插针,弹出标注

以及放大时弹出窗口远离pin的图像

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

以下是我对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;

}`
公共类符号zingResults扩展活动{
地图视图;
按钮查询;
图形杀手gl;
标注标注;
/**在首次创建活动时调用*/
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
map=(MapView)findviewbyd(R.id.map);
map.addLayer(新的ArcGISTiledMapServiceLayer)(
"http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"));
gl=新GraphicsLayer();
gl.setRenderer(createClassBreaksRenderer());
p点=新点(37.6922222,-97.3372222);
HashMap map1=新的HashMap();
地图1.put(“名称”、“印度”);
PictureMarkerSymbol pic=新的PictureMarkerSymbol(this,getResources().getDrawable(R.drawable.pin_dest));
图形gr=新图形(p、pic、map1);
总帐、附加图表(gr);
地图添加层(gl);
queryBtn=(按钮)findViewById(R.id.queryBtn);
setOnClickListener(新的OnClickListener(){
公共void onClick(视图v){
//设置查询参数
查询=新查询();
query.setWhere(“STATE_NAME='Kansas');
query.setReturnGeometry(true);
字符串[]外场=新字符串[]{“名称”,“州名称”,
“POP07_SQMI”};
查询:设置外场(外场);
setOutSpatialReference(map.getSpatialReference());
Query[]queryParams={Query};
AsyncQueryTask qt=新的AsyncQueryTask();
执行(查询参数);
}
});
//设置“OnSingleTapListener”,以便在单次点击时
//如果发生这种情况,调用将显示相关的“SQMI”信息
//用“图形”键
setOnSingleTapListener(新的OnSingleTapListener(){
私有静态最终长serialVersionUID=1L;
单个贴图上的公共无效(浮动x、浮动y){
如果(!map.isLoaded())
返回;
点到下降点=映射到点(x,y);
System.out.println(“X:+toDroppedPinPoint.getX());
System.out.println(“Y:+toDroppedPinPoint.getY());
int[]uids=gl.getGraphicId(x,y,2);
如果(uids!=null&&uids.length>0){
int targetId=uids[0];
图形gr=gl.getGraphic(targetId);
callout=map.getCallout();
//设置详图索引样式
callout.setStyle(R.xml.countypop);
/*字符串countyName=(字符串)gr.getAttributeValue(“名称”);
字符串countyPop=gr.getAttributeValue(“POP07_SQMI”)
.toString()*/
//将自定义内容视图设置为详图索引
标注:setContent(负荷视图(“Anshul”,“India”);
标注显示(映射到贴图点(新点(x,y));
}否则{
if(callout!=null&&callout.isShowing()){
callout.hide();
}
}
}
});
}
//创建具有“图形”属性的自定义内容视图
私有视图loadView(字符串countyName,字符串pop07){
View=LayoutFlater.from(CalloutSampleActivity.this)。充气(
R.layout.sqmi,空);
final TextView name=(TextView)view.findViewById(R.id.country\u name);
name.setText(countyName+“'s SQMI”);
最终TextView编号=(TextView)view.findViewById(R.id.pop_sqmi);
编号:setText(pop07);
最终图像视图照片=(图像视图)视图
.findviewbyd(R.id.家庭照片);
photo.setImageDrawable(CalloutSampleActivity.this.getResources()
.getDrawable(R.drawable.family));
返回视图;
}`

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

问题在于这一行:

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);
}

这是来自Arcgis的示例代码,我在其中进行了更改。但是在放大/缩小时更新标注的逻辑我也尝试过,但没有成功。非常感谢gary。我的50分是你的。请在这方面也帮助我