Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix translate interactions on openlayers and other issues on 2709 #2753

Merged
merged 4 commits into from
Mar 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 36 additions & 9 deletions web/client/components/map/openlayers/DrawSupport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class DrawSupport extends React.Component {
default : return;
}
}

}

render() {
Expand Down Expand Up @@ -530,25 +531,28 @@ class DrawSupport extends React.Component {
this.addDrawInteraction(newProps.drawMethod, newProps.options.startingPoint, newProps.options.maxPoints);
if (newProps.options && newProps.options.editEnabled) {
this.addSelectInteraction();

if (this.translateInteraction) {
this.props.map.removeInteraction(this.translateInteraction);
}

this.translateInteraction = new ol.interaction.Translate({
features: this.selectInteraction.getFeatures()
});
this.translateInteraction.setActive(false);

this.translateInteraction.on('translateend', this.updateFeatureExtent);
this.props.map.addInteraction(this.translateInteraction);


this.addTranslateListener();
if (this.modifyInteraction) {
this.props.map.removeInteraction(this.modifyInteraction);
}

this.modifyInteraction = new ol.interaction.Modify({
features: this.selectInteraction.getFeatures()
features: this.selectInteraction.getFeatures(),
condition: (e) => {
return ol.events.condition.primaryAction(e) && !ol.events.condition.altKeyOnly(e);
}
});

this.props.map.addInteraction(this.modifyInteraction);
Expand All @@ -572,11 +576,10 @@ class DrawSupport extends React.Component {
this.addFeatures(props);
}
if (newProps.options.editEnabled) {

this.addModifyInteraction();
// removed for polygon because of the issue https://github.com/geosolutions-it/MapStore2/issues/2378
if (getSimpleGeomType(newProps.drawMethod) !== "Polygon" && getSimpleGeomType(newProps.drawMethod) !== "GeometryCollection") {
this.addTranslateInteraction();
}
this.addTranslateInteraction();
}

if (newProps.options.drawEnabled) {
Expand Down Expand Up @@ -804,15 +807,20 @@ class DrawSupport extends React.Component {
this.props.map.removeInteraction(this.modifyInteraction);
}
this.modifyInteraction = new ol.interaction.Modify({
features: new ol.Collection(this.drawLayer.getSource().getFeatures())
features: new ol.Collection(this.drawLayer.getSource().getFeatures()),
condition: (e) => {
return ol.events.condition.primaryAction(e) && !ol.events.condition.altKeyOnly(e);
}
});
this.modifyInteraction.on('modifyend', (e) => {

const geojsonFormat = new ol.format.GeoJSON();
let features = e.features.getArray().map((f) => {
// transform back circles in polygons
let newFt = f.clone();
newFt.getGeometry().setGeometries(this.replaceCirclesWithPolygons(newFt));
if (newFt.getGeometry().getType() === "GeometryCollection") {
newFt.getGeometry().setGeometries(this.replaceCirclesWithPolygons(newFt));
}
return reprojectGeoJson(geojsonFormat.writeFeatureObject(newFt), this.props.map.getView().getProjection().getCode(), "EPSG:4326");
});

Expand All @@ -828,18 +836,22 @@ class DrawSupport extends React.Component {
this.translateInteraction = new ol.interaction.Translate({
features: new ol.Collection(this.drawLayer.getSource().getFeatures())
});
this.translateInteraction.setActive(false);
this.translateInteraction.on('translateend', (e) => {

const geojsonFormat = new ol.format.GeoJSON();
let features = e.features.getArray().map(f => {
// transform back circles in polygons
let newFt = f.clone();
newFt.getGeometry().setGeometries(this.replaceCirclesWithPolygons(newFt));
if (newFt.getGeometry().getType() === "GeometryCollection") {
newFt.getGeometry().setGeometries(this.replaceCirclesWithPolygons(newFt));
}
return reprojectGeoJson(geojsonFormat.writeFeatureObject(newFt), this.props.map.getView().getProjection().getCode(), "EPSG:4326");
});

this.props.onGeometryChanged(features, this.props.drawOwner, this.props.drawOwner, false, this.props.drawMethod === "Text", this.props.drawMethod === "Circle");
});
this.addTranslateListener();
this.props.map.addInteraction(this.translateInteraction);
}

Expand Down Expand Up @@ -915,6 +927,9 @@ class DrawSupport extends React.Component {
* @return {ol.geom.SimpleGeometry[]} geometries
*/
replaceCirclesWithPolygons = (feature) => {
if (feature.getGeometry && !feature.getGeometry().getGeometries) {
return feature;
}
let geoms = feature.getGeometry().getGeometries();
return geoms.map((g, i) => {
if (g.getType() !== "Circle") {
Expand Down Expand Up @@ -947,5 +962,17 @@ class DrawSupport extends React.Component {
});
}

addTranslateListener = () => {
document.addEventListener("keydown", (event) => {
if (event.altKey && event.code === "AltLeft") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would allow also AltRight

this.translateInteraction.setActive(true);
}
});
document.addEventListener("keyup", (event) => {
if (event.code === "AltLeft") {
this.translateInteraction.setActive(false);
}
});
}
}
module.exports = DrawSupport;
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ describe('Test DrawSupport', () => {
<DrawSupport features={[feature]} map={fakeMap} drawStatus="drawOrEdit" drawMethod="Polygon" options={{
drawEnabled: false, editEnabled: true}}
/>, document.getElementById("container"));
expect(support.translateInteraction).toNotExist();
expect(support.translateInteraction).toExist();
});

it('end drawing', () => {
Expand Down Expand Up @@ -1439,7 +1439,7 @@ describe('Test DrawSupport', () => {
}}
/>, document.getElementById("container"));
expect(spyAddLayer.calls.length).toBe(1);
expect(spyAddInteraction.calls.length).toBe(2);
expect(spyAddInteraction.calls.length).toBe(3);
});

it('draw or edit, endevent', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class AnnotationsEditor extends React.Component {
<Toolbar
btnDefaultProps={{ className: 'square-button-md', bsStyle: 'primary'}}
buttons={[ {
glyph: 'back',
glyph: 'arrow-left',
tooltipId: "annotations.back",
visible: this.props.showBack,
onClick: () => {this.props.onCancel(); this.props.onCleanHighlight(); }
Expand Down Expand Up @@ -236,7 +236,7 @@ class AnnotationsEditor extends React.Component {
<Toolbar
btnDefaultProps={{ className: 'square-button-md', bsStyle: 'primary'}}
buttons={[ {
glyph: 'back',
glyph: 'arrow-left',
tooltipId: "annotations.back",
visible: true,
onClick: () => {
Expand Down
1 change: 1 addition & 0 deletions web/client/reducers/annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ function annotations(state = { validationErrors: {} }, action) {
styling: false,
drawing: false,
filter: null,
editedFields: {},
originalStyle: null
});
}
Expand Down
5 changes: 5 additions & 0 deletions web/client/themes/default/less/annotations.less
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@
}
}
}
.mapstore-annotations-info-viewer-item.mapstore-annotations-info-viewer-description {
.quill {
overflow: -webkit-paged-y;
}
}

.ms-color-selector {
overflow: hidden;
Expand Down