gpt4 book ai didi

android - CallOut 弹出窗口不会通过放大/缩小定位自身

转载 作者:太空狗 更新时间:2023-10-29 14:17:28 27 4
gpt4 key购买 nike

我有一张带图钉的 Arcgis map 。当我点击一个图钉时,我会在图钉上显示一个标注(弹出窗口),效果非常好。但是当我放大/缩小 map 时,标注不会将自己定位为关于 map 上的图钉。如何在放大/缩小时始终在图钉顶部显示标注。

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

并且放大时弹出窗口的图像会远离图钉 enter image description here

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

这是我对 SymbolizingResults Activity 所做的更改

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;

}`

最佳答案

问题是这一行:

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

关于android - CallOut 弹出窗口不会通过放大/缩小定位自身,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20564327/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com