Move points and add attributes.

4090
11
06-04-2012 01:27 PM
BrianGustafson
New Contributor III
Is there a sample that shows how to move points in a graphics layer and display the attributes?  The Graphic object does not have an onClickListener or anything else that allows you to click a graphics.
0 Kudos
11 Replies
AndyGup
Esri Regular Contributor
Brian, you can use the updateGraphic() method to move a graphic. Currently there is no move() method that lets you specify a distance since the updateGraphic() method is projection agnostic. Here's a link: http://help.arcgis.com/en/arcgismobile/10.0/apis/android/api/com/esri/android/map/GraphicsLayer.html..., com.esri.core.geometry.Geometry)

If you want to see how to create a point that's a certain distance away from a starting point, I have some JavaScript and Flex code that shows how to do that on the client. I haven't converted it to Java yet. If interested email me: agup at esri dot com.

The Nearby Sample shows how to use an OnSingleTapListener and then iterate through the graphics until you find the one with the correct ID: http://help.arcgis.com/en/arcgismobile/10.0/apis/android/help/index.html#//01190000002s000000

Here's the pattern:


int[] graphicIDs = graphicsLayer.getGraphicIDs(x, y, 25);
if (graphicIDs != null && graphicIDs.length > 0) {
 //Graphic gr = graphics[0];
 Graphic gr = graphicsLayer.getGraphic(graphicIDs[0]);
 updateContent((String) gr.getAttributeValue("Rating"),
   (String) gr.getAttributeValue("Title"));
 Point location = (Point) gr.getGeometry();
 callout.setOffset(0, -15);
 callout.show(location, content);
}
0 Kudos
BrianGustafson
New Contributor III
Thanks Andy.

How do I add attributes to the graphics?  I am trying to do it this way.

HashMap<String, Object> map = new HashMap<String, Object>();
map.put("note", "");
graphicsLayer.updateGraphic(graphic.getUid(), map);
0 Kudos
AndyGup
Esri Regular Contributor
You're close, try something like this:

HashMap<String, Object> hashMap = new HashMap<String, Object>();
hashMap.put("Title", title);
hashMap.put("BodyText", bodyText);
graphicsLayer.addGraphic(new Graphic(point, symbol, hashMap, null));


-Andy
0 Kudos
BrianGustafson
New Contributor III
I am getting really close to what I am trying to do.  Is there a way to drag the points to move them and delete them?  Also, what are the coordinates that I get off of the geometry(point).  It is not the screen coordinates it looks like (1.845, 4800.00).  I somehow need to convert these coordinates to Web Mercator so that I can pull them from a SQLite DB and load them to a web application.
0 Kudos
AndyGup
Esri Regular Contributor
If you are using a tiled map with spatial reference 102100, then the value you get back from the location variable in the following code snippet should be Web Mercator:


Point location = (Point) gr.getGeometry();



Make sure you are seeing/using the raw numbers for x,y. I suspect you are just missing the "eX" portion of the number. Check them in the debugger and they should look like 1.888e7, where 1.888e7 = 18�??880�??000.

I don't know of any way to drag points at the moment with v1.1.1. One other option is you could listen for a long press and display a pop-up with an option to delete.

-Andy
0 Kudos
MarkHorsell
New Contributor
but how do you select the point in the first place?
0 Kudos
BrianGustafson
New Contributor III
You need to setup a listener on the graphics layer and then search for graphics in the touch radius using the getGraphicsIDs function.
0 Kudos
AndyGup
Esri Regular Contributor
@Mark, To add to Brian's comment. As mentioned above, you can listen for a map event such as a setOnSingleTapListener and then get the graphic IDs from the graphic layer. The getGraphicsIDs() method is an overloaded method and you can find more information on it here. Once you have the graphic IDs you can either iterate through them and test for a certain condition, or just grab the first one.

You can see an example of this code in the "Nearby" SDK sample. Here's the code snippet from that sample:

map.setOnSingleTapListener(new OnSingleTapListener() {

 private static final long serialVersionUID = 1L;

 public void onSingleTap(float x, float y) {

  if(callout != null){
   callout.hide();
  }
  else
  {
   callout = map.getCallout();
   callout.setStyle(R.xml.calloutstyle);
  }
 
  int[] graphicIDs = graphicsLayer.getGraphicIDs(x, y, 25);
  if (graphicIDs != null && graphicIDs.length > 0) {
   Graphic gr = graphicsLayer.getGraphic(graphicIDs[0]);
   updateContent((String) gr.getAttributeValue("Rating"),
     (String) gr.getAttributeValue("Title"));
   Point location = (Point) gr.getGeometry();
   callout.setOffset(0, -15);
   callout.show(location, content);
  }
  
 }
});
0 Kudos
MarkHorsell
New Contributor
Many thanks for replying, however i'm not sure this is useful to me!

I need to interrogate a ArcGISDynamicMapServiceLayer and am using query as per the attributeEditor sample.

Do i need to abandon that approach? If i used this approach does that mean i have to have all the features of a map loaded into graphics at all times? Doesn't that make dynamicMapServiceLayer redundant?
0 Kudos