The Measure Tool sample follows Android's Contexual Action Bar design pattern to provide basic measuring and sketching capabilities in a self-contained tool.
The MeasuringTool
can be integrated into an existing app provided the following two requirements are met:
- An active
MapView
in you app - An Action Bar implemented in your app
- Copy the
MeasuringTool
java class to your applications projectssrc
folder. - Create a new action button, which typically can be achieved by adding a
MenuItem
to the menu xml that populates the Action Bar.
<item
android:id="@+id/action_measure"
android:icon="@android:drawable/ic_menu_edit"
android:orderInCategory="100"
android:showAsAction="ifRoom"
android:title="@string/measure"/>
- Add the following code snippet to your
Activity
orFragment
that contains theMapView
to start theMeasuringTool
when the Action Button is clicked.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_measure:
startActionMode(new MeasuringTool(mapView));
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
The symbols used to draw the lines and polygons can be customized by calling:
setLineSymbol(LineSymbol symbol)
setMarkerSymbol(MarkerSymbol symbol)
setFillSymbol(FillSymbol symbol)
The linear and area units in the drop down list can be customized by calling:
setLinearUnits(Unit[] linearUnits)
setAreaUnits(Unit[] areaUnits)
The sample provides a MapActivity
class to show an example implementation. The MapActivity
class shows an example of extending the MeasuringTool
with custom units and custom symbols.