I. Client element client element layer
ArcGIS Android provides a client element layer graphicslayer. With ArcGIS's previous web development experience, we can know that this layer is used to draw client elements. Let's try to add another graphicslayer in mapview:
<? XML version ="1.0"Encoding ="UTF-8"?>
<Linearlayout xmlns: Android =Http://schemas.android.com/apk/res/android"
Android: Orientation ="Vertical"Android: layout_width ="Fill_parent"
Android: layout_height ="Fill_parent">
<Button Android: Id ="@ + ID/buttonaddgraphic"Android: layout_width ="Fill_parent"
Android: layout_height ="Wrap_content"Android: text ="Add client elements"/>
<Com. ESRI. Android. Map. mapview Android: Id ="@ + ID/Map"
Android: layout_width ="Fill_parent"Android: layout_height ="Fill_parent">
<Com. ESRI. Android. Map. AGS. arcgistiledmapservicelayer
Url =Http://server.arcgisonline.com/ArcGIS/rest/services
/World_imagery/mapserver"/>
<Com. ESRI. Android. Map. graphicslayer Android: Id ="@ + ID/glayer"/>
</COM. ESRI. Android. Map. mapview>
</Linearlayout>
Here, I also added a button "add client elements". I hope that when you click this button, the program can add a client element in the center of the map, that is, add a graphic on graphicslayer. Therefore, I added the following code when creating this activity:
Glayer = (graphicslayer) findviewbyid (R. Id.Glayer);
Glayer. setrenderer (NewSimplerenderer (NewSimplemarkersymbol (color.Red,
20, simplemarkersymbol. style.Square)));
Buttonaddgraphic = (button) findviewbyid (R. Id.Buttonaddgraphic);
Buttonaddgraphic. setonclicklistener (NewOnclicklistener (){
Public VoidOnclick (view v ){
Graphic G =NewGraphic ();
G. setgeometry (agsgraphicslayer.This. Map. getcenter ());
Agsgraphicslayer.This. Glayer. addgraphic (g );
Agsgraphicslayer.This. Glayer. postinvalidate ();
}
});
Pay attention to the lines of code highlighted above. The rendering style of graphicslayer is defined above, indicating that the client element layer must display a point element of 20 pixels and a square shape; the following code adds a client element through the button and notifies the program to update the display immediately. These codes run as follows:
Figure 22 Add a client element by clicking the button
Now let's change the rendering method. I want to use a small image to render these elements. For example, I want to use the icon of the current program. How should I modify it? You can check the API to find the familiar picturemarkersymbol symbol class. Let's modify the above Code a bit:
Drawable image = agsgraphicslayer.This. Getbasecontext (). getresources ()
. Getdrawable (R. drawable.Icon);
Glayer. setrenderer (NewSimplerenderer (NewPicturemarkersymbol (image )));
Here, we obtain the program's icon resource and use it as a picturemarkersymbol symbol, so that the modified Code runs like this:
Figure 23 use images to display client Elements
Similarly, we can also perform classification rendering or unique value rendering on the client layer. For example, if I want to show the red half of the elements and the green half of the elements, I can use the classification rendering implementation:
Classbreaksrenderer Renderer =NewClassbreaksrenderer ();
Renderer. setfield ("class ");
Renderer. setminvalue (0 );
Classbreak class1 =NewClassbreak ();
Class1.setclassmaxvalue (0.5 );
Class1.setsymbol (NewSimplemarkersymbol (color.Red, 20,
Simplemarkersymbol. style.Circle));
Renderer. addclassbreak (class1 );
Classbreak class2 =NewClassbreak ();
Class2.setclassmaxvalue (1 );
Class2.setsymbol (NewSimplemarkersymbol (color.Green, 20,
Simplemarkersymbol. style.Circle));
Renderer. addclassbreak (class2 );
Glayer. setrenderer (Renderer );
Buttonaddgraphic = (button) findviewbyid (R. Id.Buttonaddgraphic);
Buttonaddgraphic. setonclicklistener (NewOnclicklistener (){
Public VoidOnclick (view v ){
Graphic G =NewGraphic ();
G. setattributevalue ("class", math.Random());
G. setgeometry (agsgraphicslayer.This. Map. getcenter ());
Agsgraphicslayer.This. Glayer. addgraphic (g );
Agsgraphicslayer.This. Glayer. postinvalidate ();
}
});
In this way, all client elements are displayed in different colors based on the randomly assigned attribute "class", as shown in Figure 24.
Figure 24 display client elements using classification Rendering