Skip to content

Commit

Permalink
Merge pull request #888 from jansule/ol5DigitizeButton
Browse files Browse the repository at this point in the history
Add callback props onModalLabelOk and onModalLabelCancel to DigitizeButton
  • Loading branch information
dnlkoch committed Sep 20, 2018
2 parents 922ebea + a3b432e commit b8df5f6
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/Button/DigitizeButton/DigitizeButton.jsx
Expand Up @@ -401,7 +401,23 @@ class DigitizeButton extends React.Component {
*
* @type {Function} onToggle
*/
onToggle: PropTypes.func
onToggle: PropTypes.func,

/**
* Callback function that will be called
* when the ok-button of the modal was clicked
*
* @type {Function} onModalLabelOk
*/
onModalLabelOk: PropTypes.func,

/**
* Callback function that will be called
* when the cancel-button of the modal was clicked
*
* @type {Function} onModalLabelCancel
*/
onModalLabelCancel: PropTypes.func
};

/**
Expand Down Expand Up @@ -934,10 +950,21 @@ class DigitizeButton extends React.Component {
* Turns visibility of modal off and call `setTextOnFeature` method.
*/
onModalLabelOk = () => {
const {
textLabel
} = this.state;

const {
onModalLabelOk
} = this.props;

this.setState({
showLabelPrompt: false
}, () => {
this.setTextOnFeature(this._digitizeTextFeature);
if (onModalLabelOk) {
onModalLabelOk(this._digitizeTextFeature, textLabel);
}
});
}

Expand All @@ -947,6 +974,10 @@ class DigitizeButton extends React.Component {
* digitize layer.
*/
onModalLabelCancel = () => {
const {
onModalLabelCancel
} = this.props;

this.setState({
showLabelPrompt: false,
textLabel: ''
Expand All @@ -955,6 +986,9 @@ class DigitizeButton extends React.Component {
this._digitizeFeatures.remove(this._digitizeTextFeature);
this._digitizeTextFeature = null;
}
if (onModalLabelCancel) {
onModalLabelCancel();
}
});
}

Expand Down Expand Up @@ -1042,6 +1076,8 @@ class DigitizeButton extends React.Component {
modifyInteractionConfig,
translateInteractionConfig,
onToggle,
onModalLabelOk,
onModalLabelCancel,
...passThroughProps
} = this.props;

Expand Down

0 comments on commit b8df5f6

Please sign in to comment.