Add features property to vertex feature
This commit is contained in:
@@ -108,8 +108,11 @@ const ModifyEventType = {
|
|||||||
* @property {number} [pixelTolerance=10] Pixel tolerance for considering the
|
* @property {number} [pixelTolerance=10] Pixel tolerance for considering the
|
||||||
* pointer close enough to a segment or vertex for editing.
|
* pointer close enough to a segment or vertex for editing.
|
||||||
* @property {import("../style/Style.js").StyleLike} [style]
|
* @property {import("../style/Style.js").StyleLike} [style]
|
||||||
* Style used for the features being modified. By default the default edit
|
* Style used for the modification point. For linestrings and polygons, this will
|
||||||
* style is used (see {@link module:ol/style}).
|
* be the affected vertex, for circles a point along the circle, and for points the actual
|
||||||
|
* point. If not configured, the default edit style is used (see {@link module:ol/style}).
|
||||||
|
* When using a style function, the point feature passed to the function will have a `features`
|
||||||
|
* property - an array whose entries are the features that are being modified.
|
||||||
* @property {VectorSource} [source] The vector source with
|
* @property {VectorSource} [source] The vector source with
|
||||||
* features to modify. If a vector source is not provided, a layer or feature collection
|
* features to modify. If a vector source is not provided, a layer or feature collection
|
||||||
* must be provided with the `layer` or `features` option.
|
* must be provided with the `layer` or `features` option.
|
||||||
@@ -765,10 +768,11 @@ class Modify extends PointerInteraction {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {import("../coordinate.js").Coordinate} coordinates Coordinates.
|
* @param {import("../coordinate.js").Coordinate} coordinates Coordinates.
|
||||||
|
* @param {Array<Feature>} features The features being modified.
|
||||||
* @return {Feature} Vertex feature.
|
* @return {Feature} Vertex feature.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
createOrUpdateVertexFeature_(coordinates) {
|
createOrUpdateVertexFeature_(coordinates, features) {
|
||||||
let vertexFeature = this.vertexFeature_;
|
let vertexFeature = this.vertexFeature_;
|
||||||
if (!vertexFeature) {
|
if (!vertexFeature) {
|
||||||
vertexFeature = new Feature(new Point(coordinates));
|
vertexFeature = new Feature(new Point(coordinates));
|
||||||
@@ -778,6 +782,7 @@ class Modify extends PointerInteraction {
|
|||||||
const geometry = vertexFeature.getGeometry();
|
const geometry = vertexFeature.getGeometry();
|
||||||
geometry.setCoordinates(coordinates);
|
geometry.setCoordinates(coordinates);
|
||||||
}
|
}
|
||||||
|
vertexFeature.set('features', features);
|
||||||
return vertexFeature;
|
return vertexFeature;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -830,9 +835,14 @@ class Modify extends PointerInteraction {
|
|||||||
evt.coordinate[0] + this.delta_[0],
|
evt.coordinate[0] + this.delta_[0],
|
||||||
evt.coordinate[1] + this.delta_[1],
|
evt.coordinate[1] + this.delta_[1],
|
||||||
];
|
];
|
||||||
|
const features = [];
|
||||||
for (let i = 0, ii = this.dragSegments_.length; i < ii; ++i) {
|
for (let i = 0, ii = this.dragSegments_.length; i < ii; ++i) {
|
||||||
const dragSegment = this.dragSegments_[i];
|
const dragSegment = this.dragSegments_[i];
|
||||||
const segmentData = dragSegment[0];
|
const segmentData = dragSegment[0];
|
||||||
|
const feature = segmentData.feature;
|
||||||
|
if (features.indexOf(feature) === -1) {
|
||||||
|
features.push(feature);
|
||||||
|
}
|
||||||
const depth = segmentData.depth;
|
const depth = segmentData.depth;
|
||||||
const geometry = segmentData.geometry;
|
const geometry = segmentData.geometry;
|
||||||
let coordinates;
|
let coordinates;
|
||||||
@@ -912,7 +922,7 @@ class Modify extends PointerInteraction {
|
|||||||
this.setGeometryCoordinates_(geometry, coordinates);
|
this.setGeometryCoordinates_(geometry, coordinates);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.createOrUpdateVertexFeature_(vertex);
|
this.createOrUpdateVertexFeature_(vertex, features);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1160,7 +1170,7 @@ class Modify extends PointerInteraction {
|
|||||||
node.index === CIRCLE_CIRCUMFERENCE_INDEX
|
node.index === CIRCLE_CIRCUMFERENCE_INDEX
|
||||||
) {
|
) {
|
||||||
this.snappedToVertex_ = true;
|
this.snappedToVertex_ = true;
|
||||||
this.createOrUpdateVertexFeature_(vertex);
|
this.createOrUpdateVertexFeature_(vertex, [node.feature]);
|
||||||
} else {
|
} else {
|
||||||
const pixel1 = map.getPixelFromCoordinate(closestSegment[0]);
|
const pixel1 = map.getPixelFromCoordinate(closestSegment[0]);
|
||||||
const pixel2 = map.getPixelFromCoordinate(closestSegment[1]);
|
const pixel2 = map.getPixelFromCoordinate(closestSegment[1]);
|
||||||
@@ -1174,7 +1184,7 @@ class Modify extends PointerInteraction {
|
|||||||
? closestSegment[1]
|
? closestSegment[1]
|
||||||
: closestSegment[0];
|
: closestSegment[0];
|
||||||
}
|
}
|
||||||
this.createOrUpdateVertexFeature_(vertex);
|
this.createOrUpdateVertexFeature_(vertex, [node.feature]);
|
||||||
const geometries = {};
|
const geometries = {};
|
||||||
geometries[getUid(geometry)] = true;
|
geometries[getUid(geometry)] = true;
|
||||||
for (let i = 1, ii = nodes.length; i < ii; ++i) {
|
for (let i = 1, ii = nodes.length; i < ii; ++i) {
|
||||||
|
|||||||
@@ -942,8 +942,8 @@ describe('ol.interaction.Modify', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#setActive', function () {
|
describe('Vertex feature', function () {
|
||||||
it('removes the vertexFeature of deactivation', function () {
|
it('tracks features and removes the vertexFeature on deactivation', function () {
|
||||||
const modify = new Modify({
|
const modify = new Modify({
|
||||||
features: new Collection(features),
|
features: new Collection(features),
|
||||||
});
|
});
|
||||||
@@ -952,6 +952,7 @@ describe('ol.interaction.Modify', function () {
|
|||||||
|
|
||||||
simulateEvent('pointermove', 10, -20, null, 0);
|
simulateEvent('pointermove', 10, -20, null, 0);
|
||||||
expect(modify.vertexFeature_).to.not.be(null);
|
expect(modify.vertexFeature_).to.not.be(null);
|
||||||
|
expect(modify.vertexFeature_.get('features').length).to.be(1);
|
||||||
|
|
||||||
modify.setActive(false);
|
modify.setActive(false);
|
||||||
expect(modify.vertexFeature_).to.be(null);
|
expect(modify.vertexFeature_).to.be(null);
|
||||||
|
|||||||
Reference in New Issue
Block a user