How-to configure the Measure tool¶
The measure tool is configured in two places:
The application-level
measureconfiguration object controls which units are offered and whether the on-map annotations start on or off.The ServiceManager component’s
measureToolOptionscontrol the point-coordinate projections and the initially selected units.
Application measure configuration¶
Pass a measure object when creating the application to control the
units offered in the tool and the default annotation behavior:
var app = new gm3.Application({
mapserver_url: CONFIG.mapserver_url,
mapfile_root: CONFIG.mapfile_root,
measure: {
lengthUnits: ["m", "km", "ft", "mi", "ch", "r"],
areaUnits: ["m", "km", "ft", "mi", "a", "h"],
showMeasureLabels: true
}
});
lengthUnitsis the list of length units offered in the tool. Valid values are:mfor meters.kmfor kilometers.ftfor feet.mifor miles.chfor chains.rfor rods.
The default is
["m", "km", "ft", "mi", "ch"].areaUnitsis the list of area units offered in the tool. Valid values are:mfor square meters.kmfor square kilometers.ftfor square feet.mifor square miles.afor acres.hfor hectares.
The default is
["m", "km", "ft", "mi", "a", "h"].showMeasureLabelsis a boolean that sets the initial state of the on-map measure annotations.true(the default) shows them,falsehides them until the user turns them on with the labels button. See Turning off measure annotations by default for details.
Note
Length and area units are paired: selecting a length unit automatically selects a complementary area unit (and vice versa). Chains and rods both pair with acres, following surveyor convention.
ServiceManager options¶
The measure tool is rendered by the ServiceManager component, so the
point-coordinate and initial-unit options are passed in as
measureToolOptions when the ServiceManager is added to the
application.
Here’s the example from the demo:
app.add(gm3.components.ServiceManager, 'service-tab', {
services: true,
measureToolOptions: {
pointProjections: point_projections
}
});
pointProjectionsis an array of projection and label definitions, that is defined the same as with the Coordinate Display. When a user clicks on a point on the map, the point will be shown in all of the defined projections.initialUnitsoverrides the initially selected length and area units when the tool opens. It is a single unit code from thelengthUnits/areaUnitslists above (for examplem,ft, orch).
Example of setting the default units to meters¶
The code below will set the default the measurement units to meters instead of feet.
app.add(gm3.components.ServiceManager, 'service-tab', {
services: true,
measureToolOptions: {
pointProjections: point_projections,
initialUnits: 'm'
}
});