0

I am trying to create a PictureMarkerSymbolin arcgis android, however I found that the marker use the center of the drawable as the anchor point, is it possible to set the anchor?


update:

This is the drawable(with 40x56 in pixel):

enter image description here

This is my code for adding marker:

protected void onCreate(Bundle savedInstanceState) {
    final MapView mapView = (MapView) findViewById(R.id.map_imp_esri);
    mapView.addLayer(new ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"));
    Point p = new Point(-9664114.480484284,3962469.970217699); //Birmingham
    mapView.setResolution(mapView.getMinResolution());

    GraphicsLayer graphicsLayer = new GraphicsLayer(mapView.getSpatialReference(), new Envelope(-180, -90, 180, 90));
    mapView.addLayer(graphicsLayer);

    //add marker
    Drawable d = getResources().getDrawable(R.drawable.marker_a_normal);
    PictureMarkerSymbol sym = new PictureMarkerSymbol(d);
    sym.setOffsetX(-convertToDp(d.getIntrinsicWidth()) / 2);
    sym.setOffsetY(-convertToDp(d.getIntrinsicHeight()) / 2);
    Graphic g = new Graphic(p, sym);
    graphicsLayer.addGraphic(g);
}



private int convertToDp(double input) {
    final float scale = getResources().getDisplayMetrics().density;
    return (int) (input * scale + 0.5f);
}

But this is what I got:enter image description here:

The four screenshot are captured during zooming in the map.

Note, at the image 1, the marker event does not at the united states.

Do I miss anything?

1

Yes, you can set the anchor point using the MarkerSymbol.setOffsetX and MarkerSymbol.setOffsetY.

  symbol1 = new PictureMarkerSymbol(image);
  symbol1.setOffsetX(8);
  symbol1.setOffsetY(8);
1
  • I update my post, can you spare some time to check it? – giser Dec 3 '13 at 1:05
0

I found the reason, the sdk will use the center of the drawable as the anchor when draw the symbol, so in my case , I just set the offsetY to make it work:

 PictureMarkerSymbol sym = new PictureMarkerSymbol(d);
 //sym.setOffsetX(-convertToDp(d.getIntrinsicWidth()) / 2); not necessary
 sym.setOffsetY(-convertToDp(d.getIntrinsicHeight()) / 2);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.