fix: repeating sort function + js annotation
Sort function is now bind to this, and it uses a pixelCoordinate_ member. ol.interaction.Snap.handleEvent is removed js annotations are modified
This commit is contained in:
+3
-2
@@ -2684,7 +2684,7 @@ olx.interaction.SnapOptions;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Snap to this features
|
* Snap to these features. Either this option or source should be provided.
|
||||||
* @type {Array.<ol.Feature>|ol.Collection.<ol.Feature>|undefined}
|
* @type {Array.<ol.Feature>|ol.Collection.<ol.Feature>|undefined}
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -2701,8 +2701,9 @@ olx.interaction.SnapOptions.prototype.pixelTolerance;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Snap to features from this source
|
* Snap to features from this source. Either this option or features should be provided
|
||||||
* @type {ol.source.Vector|undefined}
|
* @type {ol.source.Vector|undefined}
|
||||||
|
* @api
|
||||||
*/
|
*/
|
||||||
olx.interaction.SnapOptions.prototype.source;
|
olx.interaction.SnapOptions.prototype.source;
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ goog.require('ol.structs.RBush');
|
|||||||
ol.interaction.Snap = function(opt_options) {
|
ol.interaction.Snap = function(opt_options) {
|
||||||
|
|
||||||
goog.base(this, {
|
goog.base(this, {
|
||||||
handleEvent: ol.interaction.Snap.handleEvent,
|
handleEvent: this.handleEvent_,
|
||||||
handleDownEvent: goog.functions.TRUE,
|
handleDownEvent: goog.functions.TRUE,
|
||||||
handleUpEvent: ol.interaction.Snap.handleUpEvent
|
handleUpEvent: ol.interaction.Snap.handleUpEvent
|
||||||
});
|
});
|
||||||
@@ -91,6 +91,13 @@ ol.interaction.Snap = function(opt_options) {
|
|||||||
*/
|
*/
|
||||||
this.indexedFeaturesExtents_ = {};
|
this.indexedFeaturesExtents_ = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for distance sorting in sortByDistance_
|
||||||
|
* @type {ol.Coordinate}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this.pixelCoordinate_ = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {number}
|
* @type {number}
|
||||||
* @private
|
* @private
|
||||||
@@ -98,6 +105,12 @@ ol.interaction.Snap = function(opt_options) {
|
|||||||
this.pixelTolerance_ = goog.isDef(options.pixelTolerance) ?
|
this.pixelTolerance_ = goog.isDef(options.pixelTolerance) ?
|
||||||
options.pixelTolerance : 10;
|
options.pixelTolerance : 10;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {Function}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this.sortByDistance_ = goog.bind(ol.interaction.Snap.sortByDistance, this);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Segment RTree for each layer
|
* Segment RTree for each layer
|
||||||
@@ -212,7 +225,7 @@ ol.interaction.Snap.prototype.handleEvent_ = function(evt) {
|
|||||||
evt.coordinate = result.vertex;
|
evt.coordinate = result.vertex;
|
||||||
evt.pixel = result.vertexPixel;
|
evt.pixel = result.vertexPixel;
|
||||||
}
|
}
|
||||||
return true;
|
return ol.interaction.Pointer.handleEvent.call(this, evt);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -360,8 +373,8 @@ ol.interaction.Snap.prototype.snapTo = function(pixel, pixelCoordinate, map) {
|
|||||||
var vertex = null;
|
var vertex = null;
|
||||||
var vertexPixel = null;
|
var vertexPixel = null;
|
||||||
if (segments.length > 0) {
|
if (segments.length > 0) {
|
||||||
segments.sort(goog.partial(
|
this.pixelCoordinate_ = pixelCoordinate;
|
||||||
ol.interaction.Snap.sortByDistance, pixelCoordinate));
|
segments.sort(this.sortByDistance_);
|
||||||
var closestSegment = segments[0].segment;
|
var closestSegment = segments[0].segment;
|
||||||
vertex = (ol.coordinate.closestOnSegment(pixelCoordinate,
|
vertex = (ol.coordinate.closestOnSegment(pixelCoordinate,
|
||||||
closestSegment));
|
closestSegment));
|
||||||
@@ -396,7 +409,6 @@ ol.interaction.Snap.prototype.snapTo = function(pixel, pixelCoordinate, map) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.interaction.Snap.prototype.updateFeature_ = function(feature) {
|
ol.interaction.Snap.prototype.updateFeature_ = function(feature) {
|
||||||
console.log(3);
|
|
||||||
this.removeFeature(feature, false);
|
this.removeFeature(feature, false);
|
||||||
this.addFeature(feature, false);
|
this.addFeature(feature, false);
|
||||||
};
|
};
|
||||||
@@ -568,7 +580,6 @@ ol.interaction.Snap.SegmentDataType;
|
|||||||
* @param {ol.MapBrowserPointerEvent} evt Event.
|
* @param {ol.MapBrowserPointerEvent} evt Event.
|
||||||
* @return {boolean} Stop drag sequence?
|
* @return {boolean} Stop drag sequence?
|
||||||
* @this {ol.interaction.Snap}
|
* @this {ol.interaction.Snap}
|
||||||
* @api
|
|
||||||
*/
|
*/
|
||||||
ol.interaction.Snap.handleUpEvent = function(evt) {
|
ol.interaction.Snap.handleUpEvent = function(evt) {
|
||||||
goog.array.forEach(goog.object.getValues(this.pendingFeatures_),
|
goog.array.forEach(goog.object.getValues(this.pendingFeatures_),
|
||||||
@@ -578,26 +589,16 @@ ol.interaction.Snap.handleUpEvent = function(evt) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
|
|
||||||
* @return {boolean} `false` to stop event propagation.
|
|
||||||
* @this {ol.interaction.Snap}
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
ol.interaction.Snap.handleEvent = function(mapBrowserEvent) {
|
|
||||||
return ol.interaction.Pointer.handleEvent.call(this, mapBrowserEvent) &&
|
|
||||||
this.handleEvent_(mapBrowserEvent);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort segments by distance, helper function
|
* Sort segments by distance, helper function
|
||||||
* @param {ol.Coordinate} pixelCoordinate Coordinate to determine distance
|
|
||||||
* @param {ol.interaction.Snap.SegmentDataType} a
|
* @param {ol.interaction.Snap.SegmentDataType} a
|
||||||
* @param {ol.interaction.Snap.SegmentDataType} b
|
* @param {ol.interaction.Snap.SegmentDataType} b
|
||||||
* @return {number}
|
* @return {number}
|
||||||
|
* @this {ol.interaction.Snap}
|
||||||
*/
|
*/
|
||||||
ol.interaction.Snap.sortByDistance = function(pixelCoordinate, a, b) {
|
ol.interaction.Snap.sortByDistance = function(a, b) {
|
||||||
return ol.coordinate.squaredDistanceToSegment(pixelCoordinate, a.segment) -
|
return ol.coordinate.squaredDistanceToSegment(
|
||||||
ol.coordinate.squaredDistanceToSegment(pixelCoordinate, b.segment);
|
this.pixelCoordinate_, a.segment) -
|
||||||
|
ol.coordinate.squaredDistanceToSegment(
|
||||||
|
this.pixelCoordinate_, b.segment);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user