Skip to content

Commit

Permalink
Merge pull request #1071 from jlap/modify-rectangle-style-bug
Browse files Browse the repository at this point in the history
Fix styling issue with the modify rectangle.
  • Loading branch information
fredj committed Apr 27, 2016
2 parents 065171a + 8f5bc6b commit 240e98c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
11 changes: 11 additions & 0 deletions examples/modifyrectangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ app.MainController = function() {
};
})();

var vectorSource = new ol.source.Vector({
features: this.features
});
var vectorLayer = new ol.layer.Vector({
source: vectorSource
});

// Use vectorLayer.setMap(map) rather than map.addLayer(vectorLayer). This
// makes the vector layer "unmanaged", meaning that it is always on top.
vectorLayer.setMap(map);

/**
* @type {ngeo.interaction.ModifyRectangle}
* @export
Expand Down
29 changes: 5 additions & 24 deletions src/ol-ext/interaction/modifyrectangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,6 @@ ngeo.interaction.ModifyRectangle = function(options) {
// Get the style for the box and the points
var style = options.style ? options.style : ol.interaction.Modify.getDefaultStyleFunction();

/**
* @type {ol.layer.Vector}
* @private
*/
this.vectorBoxes_ = new ol.layer.Vector({
source: new ol.source.Vector({
wrapX: !!options.wrapX
}),
style: style,
updateWhileAnimating: true,
updateWhileInteracting: true
});

/**
* @type {ol.layer.Vector}
* @private
Expand Down Expand Up @@ -129,16 +116,12 @@ goog.inherits(ngeo.interaction.ModifyRectangle, ol.interaction.Pointer);
ngeo.interaction.ModifyRectangle.prototype.addFeature_ = function(feature) {
var featureGeom = feature.getGeometry();
if (featureGeom instanceof ol.geom.Polygon) {
var boxSource = this.vectorBoxes_.getSource();
var pointSource = this.vectorPoints_.getSource();

try {
boxSource.addFeature(feature);
} catch (e) {
// If the feature is in the source already, its corners were already
// created, no need to create them again.
// If the feature's corners are already set, no need to set them again
if (feature.get('corners')) {
return;
}
var pointSource = this.vectorPoints_.getSource();

// from each corners, create a point feature and add it to the point layer.
// each point is then associated with 2 siblings in order to update the
Expand Down Expand Up @@ -258,8 +241,7 @@ ngeo.interaction.ModifyRectangle.prototype.handleCornerGeometryChange_ = functio
}, this);
var boxCoordinates = goog.array.concat(corners, [corners[0]]);

var boxFeatures = this.vectorBoxes_.getSource().getFeatures();
goog.array.forEach(boxFeatures, function(boxFeature) {
this.features_.forEach(function(boxFeature) {
var geom = boxFeature.getGeometry();
goog.asserts.assertInstanceof(geom, ol.geom.Polygon);
geom.setCoordinates([boxCoordinates]);
Expand Down Expand Up @@ -297,7 +279,7 @@ ngeo.interaction.ModifyRectangle.prototype.removeFeature_ = function(feature) {

this.vectorPoints_.getSource().removeFeature(corners[i]);
}
this.vectorBoxes_.getSource().removeFeature(feature);
feature.set('corners', undefined);
this.feature_ = null;
corners.length = 0;
delete this.cache_[uid];
Expand All @@ -308,7 +290,6 @@ ngeo.interaction.ModifyRectangle.prototype.removeFeature_ = function(feature) {
* @inheritDoc
*/
ngeo.interaction.ModifyRectangle.prototype.setMap = function(map) {
this.vectorBoxes_.setMap(map);
this.vectorPoints_.setMap(map);
this.vectorPoints_.setVisible(false);
goog.base(this, 'setMap', map);
Expand Down

0 comments on commit 240e98c

Please sign in to comment.