Skip to content

Commit 329c18d

Browse files
Feedback from @chughes-lincoln
1 parent f66cb65 commit 329c18d

6 files changed

Lines changed: 91 additions & 21 deletions

File tree

docs/howto/configure-measure-tool.rst

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,74 @@
11
How-to configure the Measure tool
22
=================================
33

4-
The measure tool is managed as a part of the ServiceManager component.
5-
Therefore, all the options for the measure tool are passed in as options
6-
to the ServiceManger component when it's added to the application.
4+
The measure tool is configured in two places:
5+
6+
#. The application-level ``measure`` configuration object controls which
7+
units are offered and whether the on-map annotations start on or off.
8+
#. The ServiceManager component's ``measureToolOptions`` control the
9+
point-coordinate projections and the initially selected units.
10+
11+
Application measure configuration
12+
---------------------------------
13+
14+
Pass a ``measure`` object when creating the application to control the
15+
units offered in the tool and the default annotation behavior:
16+
17+
.. code:: javascript
18+
19+
var app = new gm3.Application({
20+
mapserver_url: CONFIG.mapserver_url,
21+
mapfile_root: CONFIG.mapfile_root,
22+
measure: {
23+
lengthUnits: ["m", "km", "ft", "mi", "ch", "r"],
24+
areaUnits: ["m", "km", "ft", "mi", "a", "h"],
25+
showMeasureLabels: true
26+
}
27+
});
28+
29+
- ``lengthUnits`` is the list of length units offered in the tool. Valid
30+
values are:
31+
32+
- ``m`` for meters.
33+
- ``km`` for kilometers.
34+
- ``ft`` for feet.
35+
- ``mi`` for miles.
36+
- ``ch`` for chains.
37+
- ``r`` for rods.
38+
39+
The default is ``["m", "km", "ft", "mi", "ch"]``.
40+
41+
- ``areaUnits`` is the list of area units offered in the tool. Valid
42+
values are:
43+
44+
- ``m`` for square meters.
45+
- ``km`` for square kilometers.
46+
- ``ft`` for square feet.
47+
- ``mi`` for square miles.
48+
- ``a`` for acres.
49+
- ``h`` for hectares.
50+
51+
The default is ``["m", "km", "ft", "mi", "a", "h"]``.
52+
53+
- ``showMeasureLabels`` is a boolean that sets the *initial* state of
54+
the on-map measure annotations. ``true`` (the default) shows them,
55+
``false`` hides them until the user turns them on with the labels
56+
button. See :doc:`Turning off measure annotations by default
57+
<disable-measure-labels>` for details.
58+
59+
.. note::
60+
61+
Length and area units are paired: selecting a length unit
62+
automatically selects a complementary area unit (and vice versa).
63+
Chains and rods both pair with acres, following surveyor convention.
64+
65+
ServiceManager options
66+
----------------------
67+
68+
The measure tool is rendered by the ServiceManager component, so the
69+
point-coordinate and initial-unit options are passed in as
70+
``measureToolOptions`` when the ServiceManager is added to the
71+
application.
772

873
Here's the example from the demo:
974

@@ -20,14 +85,10 @@ Here's the example from the demo:
2085
that is defined the same as with the :doc:`Coordinate
2186
Display <coordinate-display>`. When a user clicks on a point on
2287
the map, the point will be shown in all of the defined projections.
23-
- ``initialUnits`` is one of:
24-
- ``m`` for meters.
25-
- ``km`` for kilometers.
26-
- ``ft`` for feet (this is the default).
27-
- ``mi`` for miles.
28-
- ``ch`` for chains.
29-
- ``a`` for acres.
30-
- ``h`` for hectares.
88+
- ``initialUnits`` overrides the initially selected length and area
89+
units when the tool opens. It is a single unit code from the
90+
``lengthUnits``/``areaUnits`` lists above (for example ``m``, ``ft``,
91+
or ``ch``).
3192

3293
Example of setting the default units to meters
3394
----------------------------------------------

docs/howto/disable-measure-labels.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ Users can always toggle the annotations on or off while measuring using
99
the labels button in the upper-left map controls.
1010

1111
To change the *default* so the annotations start **off**, set
12-
``showMeasureLabels`` to ``false`` in the application's ``map``
13-
configuration object.
12+
``showMeasureLabels`` to ``false`` in the application's ``measure``
13+
configuration object, alongside the other measure options such as
14+
``areaUnits`` and ``lengthUnits``.
1415

1516
Example:
1617

@@ -19,7 +20,9 @@ Example:
1920
var app = new gm3.Application({
2021
mapserver_url: CONFIG.mapserver_url,
2122
mapfile_root: CONFIG.mapfile_root,
22-
map: {
23+
measure: {
24+
areaUnits: ["ft", "mi", "a", "h", "m", "km"],
25+
lengthUnits: ["ft", "mi", "ch", "r", "m", "km"],
2326
showMeasureLabels: false
2427
}
2528
});

src/gm3/components/map/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,11 @@ class Map extends React.Component {
414414
this.configureSelectionLayer();
415415

416416
// Measure annotations are on by default (opt-out). Honor a deployer's
417-
// config.map.showMeasureLabels override here -- the map mounts once, so
417+
// config.measure.showMeasureLabels override here -- it sits alongside the
418+
// other measure options (areaUnits, lengthUnits). The map mounts once, so
418419
// this seeds the initial state without clobbering later user toggles.
419-
if (typeof this.props.config.showMeasureLabels === "boolean") {
420-
this.props.setShowMeasureLabels(this.props.config.showMeasureLabels);
420+
if (typeof this.props.measureConfig.showMeasureLabels === "boolean") {
421+
this.props.setShowMeasureLabels(this.props.measureConfig.showMeasureLabels);
421422
}
422423

423424
const viewParams = {};
@@ -978,6 +979,7 @@ function mapState(state) {
978979
mapView: state.map,
979980
serviceName: state.query.serviceName,
980981
config: state.config.map || {},
982+
measureConfig: state.config.measure || {},
981983
selectionStyle: state.config.selectionStyle || {},
982984
// resolve this to meters
983985
selectionBuffer: util.convertLength(

src/gm3/components/measure/unit.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ import { useTranslation } from "react-i18next";
2929
// - "area": which area unit to use for a given length unit
3030
// - "length": which length unit to use for a given area unit
3131
const COMPLEMENTARY_UNIT = {
32-
// length unit -> area unit
33-
area: { m: "m", km: "km", ft: "ft", mi: "mi", ch: "ft" },
32+
// length unit -> area unit. Chains and rods pair with acres: surveyors
33+
// (the chain/rod users) expect acres, and square rods are not a selectable
34+
// area unit, which would otherwise leave the area with no unit chosen.
35+
area: { m: "m", km: "km", ft: "ft", mi: "mi", ch: "a", r: "a" },
3436
// area unit -> length unit
3537
length: { m: "m", km: "km", ft: "ft", mi: "mi", a: "ft", h: "m" },
3638
};

src/gm3/reducers/map.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const defaultState = {
5555
editTools: [],
5656
projection: "EPSG:3857",
5757
// on-map measure annotations (rendering concerns). On by default; a
58-
// deployer can opt out via config.map.showMeasureLabels = false.
58+
// deployer can opt out via config.measure.showMeasureLabels = false.
5959
showMeasureLabels: true,
6060
measureLengthUnits: "ft",
6161
measureAreaUnits: "ft",

tests/gm3/components/measure.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ describe("getComplementaryUnit tests", () => {
169169
expect(getComplementaryUnit("ft", "area")).toBe("ft");
170170
expect(getComplementaryUnit("m", "area")).toBe("m");
171171
expect(getComplementaryUnit("km", "area")).toBe("km");
172-
expect(getComplementaryUnit("ch", "area")).toBe("ft");
172+
// chains and rods pair with acres (surveyor convention).
173+
expect(getComplementaryUnit("ch", "area")).toBe("a");
174+
expect(getComplementaryUnit("r", "area")).toBe("a");
173175
});
174176

175177
test("maps an area unit to its preferred length unit", () => {

0 commit comments

Comments
 (0)