/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
// Initial activity content view. (START)
super.onCreate(savedInstanceState);
setContentView(R.layout.mapscreen);
// Retrieve the map layout and initial extent from mapscreen XML layout.
map = (MapView) findViewById(R.id.map);
// Add ESRI basemap layer to MapView.
map.addLayer(new ArcGISTiledMapServiceLayer("" +
"http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"));
// Add Facility Feature layer to the MapView
String URL = "http://PUT YOUR SERVER INFO HERE/ArcGIS/rest/services/Mobile/PUT YOUR MAP SERVICE HERE";
ArcGISFeatureLayer fLayer = new ArcGISFeatureLayer(URL, MODE.ONDEMAND);
map.addLayer(fLayer);
// This puts the ERSI logo on the bottom left corner of the screen once the map screen appears.
map.setEsriLogoVisible(true);
}
//Check Box Setup
public void onCheckboxClicked(View view) {
// Is the view now checked?
boolean checked = ((CheckBox) view).isChecked();
// Check which checkbox was clicked
switch(view.getId()) {
case R.id.checkBox1:
if (checked)
fLayer.setVisible(true);
else
fLayer.setVisible(false);
break;
}
}
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/app_frame" android:layout_width="fill_parent" android:layout_height="fill_parent" > <com.esri.android.map.MapView android:id="@+id/map" android:layout_width="fill_parent" android:layout_height="fill_parent" initExtent="-9246560.42264577, 3775709.72082467, -8746857.60892366, 4180002.76740144" /> <ImageView android:id="@+id/imageView1" android:layout_width="77dp" android:layout_height="54dp" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:src="@drawable/logo_white" /> <CheckBox android:id="@+id/checkBox1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:onClick="onCheckboxClicked" android:text="WORK!!!!!" /> </RelativeLayout>
final CheckBox Layeronoffcheckbox = (CheckBox) layout2.findViewById (R.id.checkBox1);
Layeronoffcheckbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean isChecked) {
if (isChecked()){
fLayer.setVisible(true);
}
else{
fLayer.setVisible(false);
}
}
});
Yes, this should work.
Thanks, I recently figure it out.
Are there any sample codes for adding a featureServer from a Map Server such as this..
http://services.arcgis.com/arcgis/rest/services/layer/FeatureServer/0
I've read the API and do not see any examples. I figured out DynamicMapServiceLayer and can't seem to find code for a feature layer.
Yes this has indeed worked for me.
As for the part where it should stay checked or unchecked depending with what is on the MapView, I used this;
final CheckBox legend_image_check = drawerDialog.findViewById(R.id.hide_legend_image); legend_image_check.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (legend_image_check.isChecked()) { featureLayer.setVisible(true); } else { featureLayer.setVisible(false); } } });
layer.setVisible(true) does not seem to work.
John, have you been successful at figuring a way to toggle layer visibility? This is a old post but I just stumbled across it.
Thanks!