Skip to content

Commit

Permalink
Allow the selection to be toggled off during print
Browse files Browse the repository at this point in the history
Adds a new prop to Map and PrintImage that can turn off the rendering of
the selection layer.

refs: #745
  • Loading branch information
theduckylittle committed Nov 8, 2024
1 parent ec90cbe commit bca0ff4
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/gm3/actions/mapSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,11 +510,18 @@ function isMapSourceActive(mapSource) {
/** Get the list of all map-sources which have a
* layer that is on.
*/
export function getActiveMapSources(mapSources, onlyPrintable = false) {
export function getActiveMapSources(
mapSources,
onlyPrintable = false,
includeSelection = true
) {
const active = [];
const allMaps = !onlyPrintable;
for (const ms in mapSources) {
if (isMapSourceActive(mapSources[ms])) {
if (
isMapSourceActive(mapSources[ms]) &&
(includeSelection || ms !== "selection")
) {
if (allMaps || mapSources[ms].printable) {
active.push(ms);
}
Expand Down
4 changes: 3 additions & 1 deletion src/gm3/components/map/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,11 @@ class Map extends React.Component {
refreshMapSources() {
// get the list of current active map-sources
const printOnly = this.props.printOnly === true;
const includeSelection = this.props.includeSelection !== false;
const activeMapSources = mapSourceActions.getActiveMapSources(
this.props.mapSources,
printOnly
printOnly,
includeSelection
);

// annoying O(n^2) iteration to see if the mapsource needs
Expand Down
2 changes: 2 additions & 0 deletions src/gm3/components/print/printImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const PrintImage = (props) => {
center={center}
resolution={rez}
printOnly={true}
includeSelection={props.includeSelection}
mapRenderedCallback={() => {
if (parentRef.current) {
setImage(getImage(parentRef.current, [props.width, props.height]));
Expand All @@ -108,6 +109,7 @@ const PrintImage = (props) => {
PrintImage.defaultProps = {
width: 600,
height: 400,
includeSelection: true,
};

const mapToProps = (state) => ({
Expand Down
24 changes: 24 additions & 0 deletions src/gm3/components/print/printModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export class PrintModal extends Modal {
layout: 0,
resolution: 1,
layouts: props.layouts ? props.layouts : DefaultLayouts,
includeSelection: "true",
};
}

Expand Down Expand Up @@ -550,6 +551,24 @@ export class PrintModal extends Modal {
);
}

/** Choose whether to include the selected layers in the output.
*/
renderIncludeSelection(t) {
return (
<select
onChange={(evt) => {
this.setState({
includeSelection: evt.target.value,
});
}}
value={this.state.resolution}
>
<option value="true">{t("yes")}</option>
<option value="false">{t("no")}</option>
</select>
);
}

renderBody() {
// small set of CSS hacks to keep the print map
// invisible but drawn.
Expand Down Expand Up @@ -605,6 +624,10 @@ export class PrintModal extends Modal {
<label>{`${t("resolution")}:`}</label>
{this.renderResolutionSelect(t)}
</p>
<p>
<label>{`${t("include-selection")}:`}</label>
{this.renderIncludeSelection(t)}
</p>
</div>
)}
</Translation>
Expand All @@ -620,6 +643,7 @@ export class PrintModal extends Modal {
width={mapSize.width}
height={mapSize.height}
store={this.props.store}
includeSelection={this.state.includeSelection === "true"}
/>
</div>
</div>
Expand Down
5 changes: 4 additions & 1 deletion src/gm3/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,8 @@
"zoomto-results" : "Zoom to results",
"zoomto-tip" : "Zoom to layer extents.",
"zoom-in" : "Zoom In",
"zoom-out" : "Zoom Out"
"zoom-out" : "Zoom Out",
"include-selection": "Include selection",
"yes": "Yes",
"no": "No"
}

0 comments on commit bca0ff4

Please sign in to comment.