Remove private static members from Extent interaction
This commit is contained in:
@@ -82,10 +82,10 @@ const ExtentInteraction = function(opt_options) {
|
|||||||
|
|
||||||
/* Inherit ol.interaction.Pointer */
|
/* Inherit ol.interaction.Pointer */
|
||||||
PointerInteraction.call(this, {
|
PointerInteraction.call(this, {
|
||||||
handleDownEvent: ExtentInteraction.handleDownEvent_,
|
handleDownEvent: handleDownEvent,
|
||||||
handleDragEvent: ExtentInteraction.handleDragEvent_,
|
handleDragEvent: handleDragEvent,
|
||||||
handleEvent: ExtentInteraction.handleEvent_,
|
handleEvent: handleEvent,
|
||||||
handleUpEvent: ExtentInteraction.handleUpEvent_
|
handleUpEvent: handleUpEvent
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -98,7 +98,7 @@ const ExtentInteraction = function(opt_options) {
|
|||||||
useSpatialIndex: false,
|
useSpatialIndex: false,
|
||||||
wrapX: !!opt_options.wrapX
|
wrapX: !!opt_options.wrapX
|
||||||
}),
|
}),
|
||||||
style: opt_options.boxStyle ? opt_options.boxStyle : ExtentInteraction.getDefaultExtentStyleFunction_(),
|
style: opt_options.boxStyle ? opt_options.boxStyle : getDefaultExtentStyleFunction(),
|
||||||
updateWhileAnimating: true,
|
updateWhileAnimating: true,
|
||||||
updateWhileInteracting: true
|
updateWhileInteracting: true
|
||||||
});
|
});
|
||||||
@@ -113,7 +113,7 @@ const ExtentInteraction = function(opt_options) {
|
|||||||
useSpatialIndex: false,
|
useSpatialIndex: false,
|
||||||
wrapX: !!opt_options.wrapX
|
wrapX: !!opt_options.wrapX
|
||||||
}),
|
}),
|
||||||
style: opt_options.pointerStyle ? opt_options.pointerStyle : ExtentInteraction.getDefaultPointerStyleFunction_(),
|
style: opt_options.pointerStyle ? opt_options.pointerStyle : getDefaultPointerStyleFunction(),
|
||||||
updateWhileAnimating: true,
|
updateWhileAnimating: true,
|
||||||
updateWhileInteracting: true
|
updateWhileInteracting: true
|
||||||
});
|
});
|
||||||
@@ -129,9 +129,8 @@ inherits(ExtentInteraction, PointerInteraction);
|
|||||||
* @param {ol.MapBrowserEvent} mapBrowserEvent Event.
|
* @param {ol.MapBrowserEvent} mapBrowserEvent Event.
|
||||||
* @return {boolean} Propagate event?
|
* @return {boolean} Propagate event?
|
||||||
* @this {ol.interaction.Extent}
|
* @this {ol.interaction.Extent}
|
||||||
* @private
|
|
||||||
*/
|
*/
|
||||||
ExtentInteraction.handleEvent_ = function(mapBrowserEvent) {
|
function handleEvent(mapBrowserEvent) {
|
||||||
if (!(mapBrowserEvent instanceof MapBrowserPointerEvent)) {
|
if (!(mapBrowserEvent instanceof MapBrowserPointerEvent)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -143,15 +142,14 @@ ExtentInteraction.handleEvent_ = function(mapBrowserEvent) {
|
|||||||
PointerInteraction.handleEvent.call(this, mapBrowserEvent);
|
PointerInteraction.handleEvent.call(this, mapBrowserEvent);
|
||||||
//return false to stop propagation
|
//return false to stop propagation
|
||||||
return false;
|
return false;
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
|
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
|
||||||
* @return {boolean} Event handled?
|
* @return {boolean} Event handled?
|
||||||
* @this {ol.interaction.Extent}
|
* @this {ol.interaction.Extent}
|
||||||
* @private
|
|
||||||
*/
|
*/
|
||||||
ExtentInteraction.handleDownEvent_ = function(mapBrowserEvent) {
|
function handleDownEvent(mapBrowserEvent) {
|
||||||
const pixel = mapBrowserEvent.pixel;
|
const pixel = mapBrowserEvent.pixel;
|
||||||
const map = mapBrowserEvent.map;
|
const map = mapBrowserEvent.map;
|
||||||
|
|
||||||
@@ -183,15 +181,15 @@ ExtentInteraction.handleDownEvent_ = function(mapBrowserEvent) {
|
|||||||
|
|
||||||
//snap to point
|
//snap to point
|
||||||
if (x !== null && y !== null) {
|
if (x !== null && y !== null) {
|
||||||
this.pointerHandler_ = ExtentInteraction.getPointHandler_(getOpposingPoint(vertex));
|
this.pointerHandler_ = getPointHandler(getOpposingPoint(vertex));
|
||||||
//snap to edge
|
//snap to edge
|
||||||
} else if (x !== null) {
|
} else if (x !== null) {
|
||||||
this.pointerHandler_ = ExtentInteraction.getEdgeHandler_(
|
this.pointerHandler_ = getEdgeHandler(
|
||||||
getOpposingPoint([x, extent[1]]),
|
getOpposingPoint([x, extent[1]]),
|
||||||
getOpposingPoint([x, extent[3]])
|
getOpposingPoint([x, extent[3]])
|
||||||
);
|
);
|
||||||
} else if (y !== null) {
|
} else if (y !== null) {
|
||||||
this.pointerHandler_ = ExtentInteraction.getEdgeHandler_(
|
this.pointerHandler_ = getEdgeHandler(
|
||||||
getOpposingPoint([extent[0], y]),
|
getOpposingPoint([extent[0], y]),
|
||||||
getOpposingPoint([extent[2], y])
|
getOpposingPoint([extent[2], y])
|
||||||
);
|
);
|
||||||
@@ -200,33 +198,31 @@ ExtentInteraction.handleDownEvent_ = function(mapBrowserEvent) {
|
|||||||
} else {
|
} else {
|
||||||
vertex = map.getCoordinateFromPixel(pixel);
|
vertex = map.getCoordinateFromPixel(pixel);
|
||||||
this.setExtent([vertex[0], vertex[1], vertex[0], vertex[1]]);
|
this.setExtent([vertex[0], vertex[1], vertex[0], vertex[1]]);
|
||||||
this.pointerHandler_ = ExtentInteraction.getPointHandler_(vertex);
|
this.pointerHandler_ = getPointHandler(vertex);
|
||||||
}
|
}
|
||||||
return true; //event handled; start downup sequence
|
return true; //event handled; start downup sequence
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
|
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
|
||||||
* @return {boolean} Event handled?
|
* @return {boolean} Event handled?
|
||||||
* @this {ol.interaction.Extent}
|
* @this {ol.interaction.Extent}
|
||||||
* @private
|
|
||||||
*/
|
*/
|
||||||
ExtentInteraction.handleDragEvent_ = function(mapBrowserEvent) {
|
function handleDragEvent(mapBrowserEvent) {
|
||||||
if (this.pointerHandler_) {
|
if (this.pointerHandler_) {
|
||||||
const pixelCoordinate = mapBrowserEvent.coordinate;
|
const pixelCoordinate = mapBrowserEvent.coordinate;
|
||||||
this.setExtent(this.pointerHandler_(pixelCoordinate));
|
this.setExtent(this.pointerHandler_(pixelCoordinate));
|
||||||
this.createOrUpdatePointerFeature_(pixelCoordinate);
|
this.createOrUpdatePointerFeature_(pixelCoordinate);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
|
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
|
||||||
* @return {boolean} Stop drag sequence?
|
* @return {boolean} Stop drag sequence?
|
||||||
* @this {ol.interaction.Extent}
|
* @this {ol.interaction.Extent}
|
||||||
* @private
|
|
||||||
*/
|
*/
|
||||||
ExtentInteraction.handleUpEvent_ = function(mapBrowserEvent) {
|
function handleUpEvent(mapBrowserEvent) {
|
||||||
this.pointerHandler_ = null;
|
this.pointerHandler_ = null;
|
||||||
//If bbox is zero area, set to null;
|
//If bbox is zero area, set to null;
|
||||||
const extent = this.getExtent();
|
const extent = this.getExtent();
|
||||||
@@ -234,52 +230,48 @@ ExtentInteraction.handleUpEvent_ = function(mapBrowserEvent) {
|
|||||||
this.setExtent(null);
|
this.setExtent(null);
|
||||||
}
|
}
|
||||||
return false; //Stop handling downup sequence
|
return false; //Stop handling downup sequence
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the default style for the drawn bbox
|
* Returns the default style for the drawn bbox
|
||||||
*
|
*
|
||||||
* @return {ol.StyleFunction} Default Extent style
|
* @return {ol.StyleFunction} Default Extent style
|
||||||
* @private
|
|
||||||
*/
|
*/
|
||||||
ExtentInteraction.getDefaultExtentStyleFunction_ = function() {
|
function getDefaultExtentStyleFunction() {
|
||||||
const style = Style.createDefaultEditing();
|
const style = Style.createDefaultEditing();
|
||||||
return function(feature, resolution) {
|
return function(feature, resolution) {
|
||||||
return style[GeometryType.POLYGON];
|
return style[GeometryType.POLYGON];
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the default style for the pointer
|
* Returns the default style for the pointer
|
||||||
*
|
*
|
||||||
* @return {ol.StyleFunction} Default pointer style
|
* @return {ol.StyleFunction} Default pointer style
|
||||||
* @private
|
|
||||||
*/
|
*/
|
||||||
ExtentInteraction.getDefaultPointerStyleFunction_ = function() {
|
function getDefaultPointerStyleFunction() {
|
||||||
const style = Style.createDefaultEditing();
|
const style = Style.createDefaultEditing();
|
||||||
return function(feature, resolution) {
|
return function(feature, resolution) {
|
||||||
return style[GeometryType.POINT];
|
return style[GeometryType.POINT];
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.Coordinate} fixedPoint corner that will be unchanged in the new extent
|
* @param {ol.Coordinate} fixedPoint corner that will be unchanged in the new extent
|
||||||
* @returns {function (ol.Coordinate): ol.Extent} event handler
|
* @returns {function (ol.Coordinate): ol.Extent} event handler
|
||||||
* @private
|
|
||||||
*/
|
*/
|
||||||
ExtentInteraction.getPointHandler_ = function(fixedPoint) {
|
function getPointHandler(fixedPoint) {
|
||||||
return function(point) {
|
return function(point) {
|
||||||
return boundingExtent([fixedPoint, point]);
|
return boundingExtent([fixedPoint, point]);
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.Coordinate} fixedP1 first corner that will be unchanged in the new extent
|
* @param {ol.Coordinate} fixedP1 first corner that will be unchanged in the new extent
|
||||||
* @param {ol.Coordinate} fixedP2 second corner that will be unchanged in the new extent
|
* @param {ol.Coordinate} fixedP2 second corner that will be unchanged in the new extent
|
||||||
* @returns {function (ol.Coordinate): ol.Extent|null} event handler
|
* @returns {function (ol.Coordinate): ol.Extent|null} event handler
|
||||||
* @private
|
|
||||||
*/
|
*/
|
||||||
ExtentInteraction.getEdgeHandler_ = function(fixedP1, fixedP2) {
|
function getEdgeHandler(fixedP1, fixedP2) {
|
||||||
if (fixedP1[0] == fixedP2[0]) {
|
if (fixedP1[0] == fixedP2[0]) {
|
||||||
return function(point) {
|
return function(point) {
|
||||||
return boundingExtent([fixedP1, [point[0], fixedP2[1]]]);
|
return boundingExtent([fixedP1, [point[0], fixedP2[1]]]);
|
||||||
@@ -291,21 +283,20 @@ ExtentInteraction.getEdgeHandler_ = function(fixedP1, fixedP2) {
|
|||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.Extent} extent extent
|
* @param {ol.Extent} extent extent
|
||||||
* @returns {Array<Array<ol.Coordinate>>} extent line segments
|
* @returns {Array<Array<ol.Coordinate>>} extent line segments
|
||||||
* @private
|
|
||||||
*/
|
*/
|
||||||
ExtentInteraction.getSegments_ = function(extent) {
|
function getSegments(extent) {
|
||||||
return [
|
return [
|
||||||
[[extent[0], extent[1]], [extent[0], extent[3]]],
|
[[extent[0], extent[1]], [extent[0], extent[3]]],
|
||||||
[[extent[0], extent[3]], [extent[2], extent[3]]],
|
[[extent[0], extent[3]], [extent[2], extent[3]]],
|
||||||
[[extent[2], extent[3]], [extent[2], extent[1]]],
|
[[extent[2], extent[3]], [extent[2], extent[1]]],
|
||||||
[[extent[2], extent[1]], [extent[0], extent[1]]]
|
[[extent[2], extent[1]], [extent[0], extent[1]]]
|
||||||
];
|
];
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.Pixel} pixel cursor location
|
* @param {ol.Pixel} pixel cursor location
|
||||||
@@ -322,7 +313,7 @@ ExtentInteraction.prototype.snapToVertex_ = function(pixel, map) {
|
|||||||
const extent = this.getExtent();
|
const extent = this.getExtent();
|
||||||
if (extent) {
|
if (extent) {
|
||||||
//convert extents to line segments and find the segment closest to pixelCoordinate
|
//convert extents to line segments and find the segment closest to pixelCoordinate
|
||||||
const segments = ExtentInteraction.getSegments_(extent);
|
const segments = getSegments(extent);
|
||||||
segments.sort(sortByDistance);
|
segments.sort(sortByDistance);
|
||||||
const closestSegment = segments[0];
|
const closestSegment = segments[0];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user