Skip to content

Commit

Permalink
Merge 9621a8d into 29a0c2d
Browse files Browse the repository at this point in the history
  • Loading branch information
annarieger committed Sep 27, 2018
2 parents 29a0c2d + 9621a8d commit 16918a5
Showing 1 changed file with 43 additions and 9 deletions.
52 changes: 43 additions & 9 deletions src/Button/DigitizeButton/DigitizeButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,15 @@ class DigitizeButton extends React.Component {

/**
* Listener function for the 'select' event of the ol.interaction.Select
* if in delete mode.
* if in `Delete` mode.
* See https://openlayers.org/en/latest/apidoc/ol.interaction.Select.Event.html
* for more information.
*/
onFeatureRemove: PropTypes.func,

/**
* Listener function for the 'select' event of the ol.interaction.Select
* if in copy mode.
* if in `Copy` mode.
* See https://openlayers.org/en/latest/apidoc/ol.interaction.Select.Event.html
* for more information.
*/
Expand Down Expand Up @@ -417,7 +417,17 @@ class DigitizeButton extends React.Component {
*
* @type {Function} onModalLabelCancel
*/
onModalLabelCancel: PropTypes.func
onModalLabelCancel: PropTypes.func,

/**
* Listener function for the 'select' event of the ol.interaction.Select
* if in `Edit` mode.
* Can be also called inside of 'select' listener function of
* the ol.interaction.Select in `Copy` and `Delete` mode if provided.
* See https://openlayers.org/en/latest/apidoc/ol.interaction.Select.Event.html
* for more information.
*/
onFeatureSelect: PropTypes.func
};

/**
Expand Down Expand Up @@ -496,7 +506,8 @@ class DigitizeButton extends React.Component {
map,
drawType,
editType,
drawStyle
drawStyle,
onFeatureSelect
} = this.props;

const {
Expand Down Expand Up @@ -531,6 +542,9 @@ class DigitizeButton extends React.Component {
if (editType === DigitizeButton.COPY_EDIT_TYPE) {
this._selectInteraction.un('select', this.onFeatureCopy);
}
if (isFunction(onFeatureSelect) && editType === DigitizeButton.EDIT_EDIT_TYPE) {
this._selectInteraction.un('select', onFeatureSelect);
}
map.un('pointermove', this.onPointerMove);
}
}
Expand Down Expand Up @@ -583,7 +597,7 @@ class DigitizeButton extends React.Component {
color: DigitizeButton.DEFAULT_STROKE_COLOR
})
})
});
});
} else {
styleObj = drawStyle || new OlStyleStyle({
text: new OlStyleText({
Expand Down Expand Up @@ -746,7 +760,8 @@ class DigitizeButton extends React.Component {
map,
selectInteractionConfig,
modifyInteractionConfig,
translateInteractionConfig
translateInteractionConfig,
onFeatureSelect
} = this.props;

this._selectInteraction = new OlInteractionSelect({
Expand All @@ -762,6 +777,10 @@ class DigitizeButton extends React.Component {
this._selectInteraction.on('select', this.onFeatureCopy);
}

if (isFunction(onFeatureSelect) && editType === DigitizeButton.EDIT_EDIT_TYPE) {
this._selectInteraction.on('select', onFeatureSelect);
}

let interactions = [this._selectInteraction];

if (editType === DigitizeButton.EDIT_EDIT_TYPE) {
Expand Down Expand Up @@ -802,12 +821,16 @@ class DigitizeButton extends React.Component {
*/
onFeatureRemove = evt => {
const {
onFeatureRemove
onFeatureRemove,
onFeatureSelect
} = this.props;

if (isFunction(onFeatureRemove)) {
onFeatureRemove(evt);
}
if (isFunction(onFeatureSelect)) {
onFeatureSelect(evt);
}

const feat = evt.selected[0];
this._selectInteraction.getFeatures().remove(feat);
Expand All @@ -824,14 +847,24 @@ class DigitizeButton extends React.Component {
*/
onFeatureCopy = evt => {
const {
onFeatureCopy
onFeatureCopy,
onFeatureSelect
} = this.props;

const feat = evt.selected[0];

if (!feat) {
return;
}

if (isFunction(onFeatureCopy)) {
onFeatureCopy(evt);
}

const feat = evt.selected[0];
if (isFunction(onFeatureSelect)) {
onFeatureSelect(evt);
}

const copy = feat.clone();
copy.setStyle(feat.getStyle());
this._digitizeFeatures.push(copy);
Expand Down Expand Up @@ -1070,6 +1103,7 @@ class DigitizeButton extends React.Component {
onTranslating,
onFeatureRemove,
onFeatureCopy,
onFeatureSelect,
drawInteractionConfig,
selectInteractionConfig,
modifyInteractionConfig,
Expand Down

0 comments on commit 16918a5

Please sign in to comment.