Remove static members from Modify
This commit is contained in:
@@ -16,7 +16,6 @@ import {always, primaryAction, altKeyOnly, singleClick} from '../events/conditio
|
|||||||
import {boundingExtent, buffer, createOrUpdateFromCoordinate} from '../extent.js';
|
import {boundingExtent, buffer, createOrUpdateFromCoordinate} from '../extent.js';
|
||||||
import GeometryType from '../geom/GeometryType.js';
|
import GeometryType from '../geom/GeometryType.js';
|
||||||
import Point from '../geom/Point.js';
|
import Point from '../geom/Point.js';
|
||||||
import ModifyEventType from '../interaction/ModifyEventType.js';
|
|
||||||
import PointerInteraction, {handleEvent as handlePointerEvent} from '../interaction/Pointer.js';
|
import PointerInteraction, {handleEvent as handlePointerEvent} from '../interaction/Pointer.js';
|
||||||
import VectorLayer from '../layer/Vector.js';
|
import VectorLayer from '../layer/Vector.js';
|
||||||
import VectorSource from '../source/Vector.js';
|
import VectorSource from '../source/Vector.js';
|
||||||
@@ -24,6 +23,61 @@ import VectorEventType from '../source/VectorEventType.js';
|
|||||||
import RBush from '../structs/RBush.js';
|
import RBush from '../structs/RBush.js';
|
||||||
import {createEditingStyle} from '../style/Style.js';
|
import {createEditingStyle} from '../style/Style.js';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @enum {string}
|
||||||
|
*/
|
||||||
|
const ModifyEventType = {
|
||||||
|
/**
|
||||||
|
* Triggered upon feature modification start
|
||||||
|
* @event ModifyEvent#modifystart
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
MODIFYSTART: 'modifystart',
|
||||||
|
/**
|
||||||
|
* Triggered upon feature modification end
|
||||||
|
* @event ModifyEvent#modifyend
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
MODIFYEND: 'modifyend'
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @classdesc
|
||||||
|
* Events emitted by {@link ol.interaction.Modify} instances are instances of
|
||||||
|
* this type.
|
||||||
|
*
|
||||||
|
* @constructor
|
||||||
|
* @extends {ol.events.Event}
|
||||||
|
* @implements {oli.ModifyEvent}
|
||||||
|
* @param {ModifyEventType} type Type.
|
||||||
|
* @param {ol.Collection.<ol.Feature>} features The features modified.
|
||||||
|
* @param {ol.MapBrowserPointerEvent} mapBrowserPointerEvent Associated
|
||||||
|
* {@link ol.MapBrowserPointerEvent}.
|
||||||
|
*/
|
||||||
|
export const ModifyEvent = function(type, features, mapBrowserPointerEvent) {
|
||||||
|
|
||||||
|
Event.call(this, type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The features being modified.
|
||||||
|
* @type {ol.Collection.<ol.Feature>}
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
this.features = features;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Associated {@link ol.MapBrowserEvent}.
|
||||||
|
* @type {ol.MapBrowserEvent}
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
this.mapBrowserEvent = mapBrowserPointerEvent;
|
||||||
|
};
|
||||||
|
|
||||||
|
inherits(ModifyEvent, Event);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @classdesc
|
* @classdesc
|
||||||
* Interaction for modifying feature geometries. To modify features that have
|
* Interaction for modifying feature geometries. To modify features that have
|
||||||
@@ -40,7 +94,7 @@ import {createEditingStyle} from '../style/Style.js';
|
|||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.interaction.Pointer}
|
* @extends {ol.interaction.Pointer}
|
||||||
* @param {olx.interaction.ModifyOptions} options Options.
|
* @param {olx.interaction.ModifyOptions} options Options.
|
||||||
* @fires ol.interaction.Modify.Event
|
* @fires ol.interaction.ModifyEvent
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
const Modify = function(options) {
|
const Modify = function(options) {
|
||||||
@@ -161,7 +215,7 @@ const Modify = function(options) {
|
|||||||
wrapX: !!options.wrapX
|
wrapX: !!options.wrapX
|
||||||
}),
|
}),
|
||||||
style: options.style ? options.style :
|
style: options.style ? options.style :
|
||||||
Modify.getDefaultStyleFunction(),
|
getDefaultStyleFunction(),
|
||||||
updateWhileAnimating: true,
|
updateWhileAnimating: true,
|
||||||
updateWhileInteracting: true
|
updateWhileInteracting: true
|
||||||
});
|
});
|
||||||
@@ -229,16 +283,18 @@ inherits(Modify, PointerInteraction);
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @define {number} The segment index assigned to a circle's center when
|
* The segment index assigned to a circle's center when
|
||||||
* breaking up a cicrle into ModifySegmentDataType segments.
|
* breaking up a cicrle into ModifySegmentDataType segments.
|
||||||
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
Modify.MODIFY_SEGMENT_CIRCLE_CENTER_INDEX = 0;
|
const CIRCLE_CENTER_INDEX = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @define {number} The segment index assigned to a circle's circumference when
|
* The segment index assigned to a circle's circumference when
|
||||||
* breaking up a circle into ModifySegmentDataType segments.
|
* breaking up a circle into ModifySegmentDataType segments.
|
||||||
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX = 1;
|
const CIRCLE_CIRCUMFERENCE_INDEX = 1;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -266,7 +322,7 @@ Modify.prototype.addFeature_ = function(feature) {
|
|||||||
Modify.prototype.willModifyFeatures_ = function(evt) {
|
Modify.prototype.willModifyFeatures_ = function(evt) {
|
||||||
if (!this.modified_) {
|
if (!this.modified_) {
|
||||||
this.modified_ = true;
|
this.modified_ = true;
|
||||||
this.dispatchEvent(new Modify.Event(
|
this.dispatchEvent(new ModifyEvent(
|
||||||
ModifyEventType.MODIFYSTART, this.features_, evt));
|
ModifyEventType.MODIFYSTART, this.features_, evt));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -525,9 +581,9 @@ Modify.prototype.writeMultiPolygonGeometry_ = function(feature, geometry) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* We convert a circle into two segments. The segment at index
|
* We convert a circle into two segments. The segment at index
|
||||||
* {@link ol.interaction.Modify.MODIFY_SEGMENT_CIRCLE_CENTER_INDEX} is the
|
* {@link CIRCLE_CENTER_INDEX} is the
|
||||||
* circle's center (a point). The segment at index
|
* circle's center (a point). The segment at index
|
||||||
* {@link ol.interaction.Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX} is
|
* {@link CIRCLE_CIRCUMFERENCE_INDEX} is
|
||||||
* the circumference, and is not a line segment.
|
* the circumference, and is not a line segment.
|
||||||
*
|
*
|
||||||
* @param {ol.Feature} feature Feature.
|
* @param {ol.Feature} feature Feature.
|
||||||
@@ -539,13 +595,13 @@ Modify.prototype.writeCircleGeometry_ = function(feature, geometry) {
|
|||||||
const centerSegmentData = /** @type {ol.ModifySegmentDataType} */ ({
|
const centerSegmentData = /** @type {ol.ModifySegmentDataType} */ ({
|
||||||
feature: feature,
|
feature: feature,
|
||||||
geometry: geometry,
|
geometry: geometry,
|
||||||
index: Modify.MODIFY_SEGMENT_CIRCLE_CENTER_INDEX,
|
index: CIRCLE_CENTER_INDEX,
|
||||||
segment: [coordinates, coordinates]
|
segment: [coordinates, coordinates]
|
||||||
});
|
});
|
||||||
const circumferenceSegmentData = /** @type {ol.ModifySegmentDataType} */ ({
|
const circumferenceSegmentData = /** @type {ol.ModifySegmentDataType} */ ({
|
||||||
feature: feature,
|
feature: feature,
|
||||||
geometry: geometry,
|
geometry: geometry,
|
||||||
index: Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX,
|
index: CIRCLE_CIRCUMFERENCE_INDEX,
|
||||||
segment: [coordinates, coordinates]
|
segment: [coordinates, coordinates]
|
||||||
});
|
});
|
||||||
const featureSegments = [centerSegmentData, circumferenceSegmentData];
|
const featureSegments = [centerSegmentData, circumferenceSegmentData];
|
||||||
@@ -631,7 +687,7 @@ function handleDownEvent(evt) {
|
|||||||
componentSegments[uid] = new Array(2);
|
componentSegments[uid] = new Array(2);
|
||||||
}
|
}
|
||||||
if (segmentDataMatch.geometry.getType() === GeometryType.CIRCLE &&
|
if (segmentDataMatch.geometry.getType() === GeometryType.CIRCLE &&
|
||||||
segmentDataMatch.index === Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX) {
|
segmentDataMatch.index === CIRCLE_CIRCUMFERENCE_INDEX) {
|
||||||
|
|
||||||
const closestVertex = closestOnSegmentData(pixelCoordinate, segmentDataMatch);
|
const closestVertex = closestOnSegmentData(pixelCoordinate, segmentDataMatch);
|
||||||
if (coordinatesEqual(closestVertex, vertex) && !componentSegments[uid][0]) {
|
if (coordinatesEqual(closestVertex, vertex) && !componentSegments[uid][0]) {
|
||||||
@@ -727,7 +783,7 @@ function handleDragEvent(evt) {
|
|||||||
break;
|
break;
|
||||||
case GeometryType.CIRCLE:
|
case GeometryType.CIRCLE:
|
||||||
segment[0] = segment[1] = vertex;
|
segment[0] = segment[1] = vertex;
|
||||||
if (segmentData.index === Modify.MODIFY_SEGMENT_CIRCLE_CENTER_INDEX) {
|
if (segmentData.index === CIRCLE_CENTER_INDEX) {
|
||||||
this.changingFeature_ = true;
|
this.changingFeature_ = true;
|
||||||
geometry.setCenter(vertex);
|
geometry.setCenter(vertex);
|
||||||
this.changingFeature_ = false;
|
this.changingFeature_ = false;
|
||||||
@@ -775,7 +831,7 @@ function handleUpEvent(evt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.modified_) {
|
if (this.modified_) {
|
||||||
this.dispatchEvent(new Modify.Event(
|
this.dispatchEvent(new ModifyEvent(
|
||||||
ModifyEventType.MODIFYEND, this.features_, evt));
|
ModifyEventType.MODIFYEND, this.features_, evt));
|
||||||
this.modified_ = false;
|
this.modified_ = false;
|
||||||
}
|
}
|
||||||
@@ -856,7 +912,7 @@ Modify.prototype.handlePointerAtPixel_ = function(pixel, map) {
|
|||||||
const vertexSegments = {};
|
const vertexSegments = {};
|
||||||
|
|
||||||
if (node.geometry.getType() === GeometryType.CIRCLE &&
|
if (node.geometry.getType() === GeometryType.CIRCLE &&
|
||||||
node.index === Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX) {
|
node.index === CIRCLE_CIRCUMFERENCE_INDEX) {
|
||||||
|
|
||||||
this.snappedToVertex_ = true;
|
this.snappedToVertex_ = true;
|
||||||
this.createOrUpdateVertexFeature_(vertex);
|
this.createOrUpdateVertexFeature_(vertex);
|
||||||
@@ -912,7 +968,7 @@ function pointDistanceToSegmentDataSquared(pointCoordinates, segmentData) {
|
|||||||
if (geometry.getType() === GeometryType.CIRCLE) {
|
if (geometry.getType() === GeometryType.CIRCLE) {
|
||||||
const circleGeometry = /** @type {ol.geom.Circle} */ (geometry);
|
const circleGeometry = /** @type {ol.geom.Circle} */ (geometry);
|
||||||
|
|
||||||
if (segmentData.index === Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX) {
|
if (segmentData.index === CIRCLE_CIRCUMFERENCE_INDEX) {
|
||||||
const distanceToCenterSquared =
|
const distanceToCenterSquared =
|
||||||
squaredCoordinateDistance(circleGeometry.getCenter(), pointCoordinates);
|
squaredCoordinateDistance(circleGeometry.getCenter(), pointCoordinates);
|
||||||
const distanceToCircumference =
|
const distanceToCircumference =
|
||||||
@@ -936,7 +992,7 @@ function closestOnSegmentData(pointCoordinates, segmentData) {
|
|||||||
const geometry = segmentData.geometry;
|
const geometry = segmentData.geometry;
|
||||||
|
|
||||||
if (geometry.getType() === GeometryType.CIRCLE &&
|
if (geometry.getType() === GeometryType.CIRCLE &&
|
||||||
segmentData.index === Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX) {
|
segmentData.index === CIRCLE_CIRCUMFERENCE_INDEX) {
|
||||||
return geometry.getClosestPoint(pointCoordinates);
|
return geometry.getClosestPoint(pointCoordinates);
|
||||||
}
|
}
|
||||||
return closestOnSegment(pointCoordinates, segmentData.segment);
|
return closestOnSegment(pointCoordinates, segmentData.segment);
|
||||||
@@ -1018,7 +1074,7 @@ Modify.prototype.removePoint = function() {
|
|||||||
const evt = this.lastPointerEvent_;
|
const evt = this.lastPointerEvent_;
|
||||||
this.willModifyFeatures_(evt);
|
this.willModifyFeatures_(evt);
|
||||||
this.removeVertex_();
|
this.removeVertex_();
|
||||||
this.dispatchEvent(new Modify.Event(ModifyEventType.MODIFYEND, this.features_, evt));
|
this.dispatchEvent(new ModifyEvent(ModifyEventType.MODIFYEND, this.features_, evt));
|
||||||
this.modified_ = false;
|
this.modified_ = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1179,46 +1235,12 @@ Modify.prototype.updateSegmentIndices_ = function(
|
|||||||
/**
|
/**
|
||||||
* @return {ol.StyleFunction} Styles.
|
* @return {ol.StyleFunction} Styles.
|
||||||
*/
|
*/
|
||||||
Modify.getDefaultStyleFunction = function() {
|
function getDefaultStyleFunction() {
|
||||||
const style = createEditingStyle();
|
const style = createEditingStyle();
|
||||||
return function(feature, resolution) {
|
return function(feature, resolution) {
|
||||||
return style[GeometryType.POINT];
|
return style[GeometryType.POINT];
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @classdesc
|
|
||||||
* Events emitted by {@link ol.interaction.Modify} instances are instances of
|
|
||||||
* this type.
|
|
||||||
*
|
|
||||||
* @constructor
|
|
||||||
* @extends {ol.events.Event}
|
|
||||||
* @implements {oli.ModifyEvent}
|
|
||||||
* @param {ol.interaction.ModifyEventType} type Type.
|
|
||||||
* @param {ol.Collection.<ol.Feature>} features The features modified.
|
|
||||||
* @param {ol.MapBrowserPointerEvent} mapBrowserPointerEvent Associated
|
|
||||||
* {@link ol.MapBrowserPointerEvent}.
|
|
||||||
*/
|
|
||||||
Modify.Event = function(type, features, mapBrowserPointerEvent) {
|
|
||||||
|
|
||||||
Event.call(this, type);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The features being modified.
|
|
||||||
* @type {ol.Collection.<ol.Feature>}
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
this.features = features;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Associated {@link ol.MapBrowserEvent}.
|
|
||||||
* @type {ol.MapBrowserEvent}
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
this.mapBrowserEvent = mapBrowserPointerEvent;
|
|
||||||
};
|
|
||||||
|
|
||||||
inherits(Modify.Event, Event);
|
|
||||||
|
|
||||||
export default Modify;
|
export default Modify;
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
/**
|
|
||||||
* @module ol/interaction/ModifyEventType
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @enum {string}
|
|
||||||
*/
|
|
||||||
export default {
|
|
||||||
/**
|
|
||||||
* Triggered upon feature modification start
|
|
||||||
* @event ol.interaction.Modify.Event#modifystart
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
MODIFYSTART: 'modifystart',
|
|
||||||
/**
|
|
||||||
* Triggered upon feature modification end
|
|
||||||
* @event ol.interaction.Modify.Event#modifyend
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
MODIFYEND: 'modifyend'
|
|
||||||
};
|
|
||||||
@@ -9,7 +9,7 @@ import Circle from '../../../../src/ol/geom/Circle.js';
|
|||||||
import LineString from '../../../../src/ol/geom/LineString.js';
|
import LineString from '../../../../src/ol/geom/LineString.js';
|
||||||
import Point from '../../../../src/ol/geom/Point.js';
|
import Point from '../../../../src/ol/geom/Point.js';
|
||||||
import Polygon from '../../../../src/ol/geom/Polygon.js';
|
import Polygon from '../../../../src/ol/geom/Polygon.js';
|
||||||
import Modify from '../../../../src/ol/interaction/Modify.js';
|
import Modify, {ModifyEvent} from '../../../../src/ol/interaction/Modify.js';
|
||||||
import VectorLayer from '../../../../src/ol/layer/Vector.js';
|
import VectorLayer from '../../../../src/ol/layer/Vector.js';
|
||||||
import PointerEvent from '../../../../src/ol/pointer/PointerEvent.js';
|
import PointerEvent from '../../../../src/ol/pointer/PointerEvent.js';
|
||||||
import VectorSource from '../../../../src/ol/source/Vector.js';
|
import VectorSource from '../../../../src/ol/source/Vector.js';
|
||||||
@@ -101,7 +101,7 @@ describe('ol.interaction.Modify', function() {
|
|||||||
* modifications. Helper function to
|
* modifications. Helper function to
|
||||||
* @param {ol.Feature} feature Modified feature.
|
* @param {ol.Feature} feature Modified feature.
|
||||||
* @param {ol.interaction.Modify} interaction The interaction.
|
* @param {ol.interaction.Modify} interaction The interaction.
|
||||||
* @return {Array<ol.interaction.Modify.Event|string>} events
|
* @return {Array<ModifyEvent|string>} events
|
||||||
*/
|
*/
|
||||||
function trackEvents(feature, interaction) {
|
function trackEvents(feature, interaction) {
|
||||||
const events = [];
|
const events = [];
|
||||||
@@ -121,7 +121,7 @@ describe('ol.interaction.Modify', function() {
|
|||||||
* Validates the event array to verify proper event sequence. Checks
|
* Validates the event array to verify proper event sequence. Checks
|
||||||
* that first and last event are correct ModifyEvents and that feature
|
* that first and last event are correct ModifyEvents and that feature
|
||||||
* modifications event are in between.
|
* modifications event are in between.
|
||||||
* @param {Array<ol.interaction.Modify.Event|string>} events The events.
|
* @param {Array<ModifyEvent|string>} events The events.
|
||||||
* @param {Array<ol.Feature>} features The features.
|
* @param {Array<ol.Feature>} features The features.
|
||||||
*/
|
*/
|
||||||
function validateEvents(events, features) {
|
function validateEvents(events, features) {
|
||||||
@@ -130,11 +130,11 @@ describe('ol.interaction.Modify', function() {
|
|||||||
const endevent = events[events.length - 1];
|
const endevent = events[events.length - 1];
|
||||||
|
|
||||||
// first event should be modifystary
|
// first event should be modifystary
|
||||||
expect(startevent).to.be.an(Modify.Event);
|
expect(startevent).to.be.a(ModifyEvent);
|
||||||
expect(startevent.type).to.eql('modifystart');
|
expect(startevent.type).to.eql('modifystart');
|
||||||
|
|
||||||
// last event should be modifyend
|
// last event should be modifyend
|
||||||
expect(endevent).to.be.an(Modify.Event);
|
expect(endevent).to.be.a(ModifyEvent);
|
||||||
expect(endevent.type).to.eql('modifyend');
|
expect(endevent.type).to.eql('modifyend');
|
||||||
|
|
||||||
// make sure we get change events to events array
|
// make sure we get change events to events array
|
||||||
|
|||||||
Reference in New Issue
Block a user