Rename _ol_interaction_Extent_ to ExtentInteraction
This commit is contained in:
@@ -2,7 +2,7 @@ import Map from '../src/ol/Map.js';
|
|||||||
import View from '../src/ol/View.js';
|
import View from '../src/ol/View.js';
|
||||||
import _ol_events_condition_ from '../src/ol/events/condition.js';
|
import _ol_events_condition_ from '../src/ol/events/condition.js';
|
||||||
import GeoJSON from '../src/ol/format/GeoJSON.js';
|
import GeoJSON from '../src/ol/format/GeoJSON.js';
|
||||||
import _ol_interaction_Extent_ from '../src/ol/interaction/Extent.js';
|
import ExtentInteraction from '../src/ol/interaction/Extent.js';
|
||||||
import TileLayer from '../src/ol/layer/Tile.js';
|
import TileLayer from '../src/ol/layer/Tile.js';
|
||||||
import VectorLayer from '../src/ol/layer/Vector.js';
|
import VectorLayer from '../src/ol/layer/Vector.js';
|
||||||
import OSM from '../src/ol/source/OSM.js';
|
import OSM from '../src/ol/source/OSM.js';
|
||||||
@@ -29,7 +29,7 @@ var map = new Map({
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
var extent = new _ol_interaction_Extent_({
|
var extent = new ExtentInteraction({
|
||||||
condition: _ol_events_condition_.platformModifierKeyOnly
|
condition: _ol_events_condition_.platformModifierKeyOnly
|
||||||
});
|
});
|
||||||
map.addInteraction(extent);
|
map.addInteraction(extent);
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import _ol_style_Style_ from '../style/Style.js';
|
|||||||
* @param {olx.interaction.ExtentOptions=} opt_options Options.
|
* @param {olx.interaction.ExtentOptions=} opt_options Options.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
var _ol_interaction_Extent_ = function(opt_options) {
|
var ExtentInteraction = function(opt_options) {
|
||||||
|
|
||||||
var options = opt_options || {};
|
var options = opt_options || {};
|
||||||
|
|
||||||
@@ -82,10 +82,10 @@ var _ol_interaction_Extent_ = function(opt_options) {
|
|||||||
|
|
||||||
/* Inherit ol.interaction.Pointer */
|
/* Inherit ol.interaction.Pointer */
|
||||||
PointerInteraction.call(this, {
|
PointerInteraction.call(this, {
|
||||||
handleDownEvent: _ol_interaction_Extent_.handleDownEvent_,
|
handleDownEvent: ExtentInteraction.handleDownEvent_,
|
||||||
handleDragEvent: _ol_interaction_Extent_.handleDragEvent_,
|
handleDragEvent: ExtentInteraction.handleDragEvent_,
|
||||||
handleEvent: _ol_interaction_Extent_.handleEvent_,
|
handleEvent: ExtentInteraction.handleEvent_,
|
||||||
handleUpEvent: _ol_interaction_Extent_.handleUpEvent_
|
handleUpEvent: ExtentInteraction.handleUpEvent_
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -98,7 +98,7 @@ var _ol_interaction_Extent_ = function(opt_options) {
|
|||||||
useSpatialIndex: false,
|
useSpatialIndex: false,
|
||||||
wrapX: !!opt_options.wrapX
|
wrapX: !!opt_options.wrapX
|
||||||
}),
|
}),
|
||||||
style: opt_options.boxStyle ? opt_options.boxStyle : _ol_interaction_Extent_.getDefaultExtentStyleFunction_(),
|
style: opt_options.boxStyle ? opt_options.boxStyle : ExtentInteraction.getDefaultExtentStyleFunction_(),
|
||||||
updateWhileAnimating: true,
|
updateWhileAnimating: true,
|
||||||
updateWhileInteracting: true
|
updateWhileInteracting: true
|
||||||
});
|
});
|
||||||
@@ -113,7 +113,7 @@ var _ol_interaction_Extent_ = function(opt_options) {
|
|||||||
useSpatialIndex: false,
|
useSpatialIndex: false,
|
||||||
wrapX: !!opt_options.wrapX
|
wrapX: !!opt_options.wrapX
|
||||||
}),
|
}),
|
||||||
style: opt_options.pointerStyle ? opt_options.pointerStyle : _ol_interaction_Extent_.getDefaultPointerStyleFunction_(),
|
style: opt_options.pointerStyle ? opt_options.pointerStyle : ExtentInteraction.getDefaultPointerStyleFunction_(),
|
||||||
updateWhileAnimating: true,
|
updateWhileAnimating: true,
|
||||||
updateWhileInteracting: true
|
updateWhileInteracting: true
|
||||||
});
|
});
|
||||||
@@ -123,7 +123,7 @@ var _ol_interaction_Extent_ = function(opt_options) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inherits(_ol_interaction_Extent_, PointerInteraction);
|
inherits(ExtentInteraction, PointerInteraction);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.MapBrowserEvent} mapBrowserEvent Event.
|
* @param {ol.MapBrowserEvent} mapBrowserEvent Event.
|
||||||
@@ -131,7 +131,7 @@ inherits(_ol_interaction_Extent_, PointerInteraction);
|
|||||||
* @this {ol.interaction.Extent}
|
* @this {ol.interaction.Extent}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_interaction_Extent_.handleEvent_ = function(mapBrowserEvent) {
|
ExtentInteraction.handleEvent_ = function(mapBrowserEvent) {
|
||||||
if (!(mapBrowserEvent instanceof MapBrowserPointerEvent)) {
|
if (!(mapBrowserEvent instanceof MapBrowserPointerEvent)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -151,7 +151,7 @@ _ol_interaction_Extent_.handleEvent_ = function(mapBrowserEvent) {
|
|||||||
* @this {ol.interaction.Extent}
|
* @this {ol.interaction.Extent}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_interaction_Extent_.handleDownEvent_ = function(mapBrowserEvent) {
|
ExtentInteraction.handleDownEvent_ = function(mapBrowserEvent) {
|
||||||
var pixel = mapBrowserEvent.pixel;
|
var pixel = mapBrowserEvent.pixel;
|
||||||
var map = mapBrowserEvent.map;
|
var map = mapBrowserEvent.map;
|
||||||
|
|
||||||
@@ -183,15 +183,15 @@ _ol_interaction_Extent_.handleDownEvent_ = function(mapBrowserEvent) {
|
|||||||
|
|
||||||
//snap to point
|
//snap to point
|
||||||
if (x !== null && y !== null) {
|
if (x !== null && y !== null) {
|
||||||
this.pointerHandler_ = _ol_interaction_Extent_.getPointHandler_(getOpposingPoint(vertex));
|
this.pointerHandler_ = ExtentInteraction.getPointHandler_(getOpposingPoint(vertex));
|
||||||
//snap to edge
|
//snap to edge
|
||||||
} else if (x !== null) {
|
} else if (x !== null) {
|
||||||
this.pointerHandler_ = _ol_interaction_Extent_.getEdgeHandler_(
|
this.pointerHandler_ = ExtentInteraction.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_ = _ol_interaction_Extent_.getEdgeHandler_(
|
this.pointerHandler_ = ExtentInteraction.getEdgeHandler_(
|
||||||
getOpposingPoint([extent[0], y]),
|
getOpposingPoint([extent[0], y]),
|
||||||
getOpposingPoint([extent[2], y])
|
getOpposingPoint([extent[2], y])
|
||||||
);
|
);
|
||||||
@@ -200,7 +200,7 @@ _ol_interaction_Extent_.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_ = _ol_interaction_Extent_.getPointHandler_(vertex);
|
this.pointerHandler_ = ExtentInteraction.getPointHandler_(vertex);
|
||||||
}
|
}
|
||||||
return true; //event handled; start downup sequence
|
return true; //event handled; start downup sequence
|
||||||
};
|
};
|
||||||
@@ -211,7 +211,7 @@ _ol_interaction_Extent_.handleDownEvent_ = function(mapBrowserEvent) {
|
|||||||
* @this {ol.interaction.Extent}
|
* @this {ol.interaction.Extent}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_interaction_Extent_.handleDragEvent_ = function(mapBrowserEvent) {
|
ExtentInteraction.handleDragEvent_ = function(mapBrowserEvent) {
|
||||||
if (this.pointerHandler_) {
|
if (this.pointerHandler_) {
|
||||||
var pixelCoordinate = mapBrowserEvent.coordinate;
|
var pixelCoordinate = mapBrowserEvent.coordinate;
|
||||||
this.setExtent(this.pointerHandler_(pixelCoordinate));
|
this.setExtent(this.pointerHandler_(pixelCoordinate));
|
||||||
@@ -226,7 +226,7 @@ _ol_interaction_Extent_.handleDragEvent_ = function(mapBrowserEvent) {
|
|||||||
* @this {ol.interaction.Extent}
|
* @this {ol.interaction.Extent}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_interaction_Extent_.handleUpEvent_ = function(mapBrowserEvent) {
|
ExtentInteraction.handleUpEvent_ = function(mapBrowserEvent) {
|
||||||
this.pointerHandler_ = null;
|
this.pointerHandler_ = null;
|
||||||
//If bbox is zero area, set to null;
|
//If bbox is zero area, set to null;
|
||||||
var extent = this.getExtent();
|
var extent = this.getExtent();
|
||||||
@@ -242,7 +242,7 @@ _ol_interaction_Extent_.handleUpEvent_ = function(mapBrowserEvent) {
|
|||||||
* @return {ol.StyleFunction} Default Extent style
|
* @return {ol.StyleFunction} Default Extent style
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_interaction_Extent_.getDefaultExtentStyleFunction_ = function() {
|
ExtentInteraction.getDefaultExtentStyleFunction_ = function() {
|
||||||
var style = _ol_style_Style_.createDefaultEditing();
|
var style = _ol_style_Style_.createDefaultEditing();
|
||||||
return function(feature, resolution) {
|
return function(feature, resolution) {
|
||||||
return style[GeometryType.POLYGON];
|
return style[GeometryType.POLYGON];
|
||||||
@@ -255,7 +255,7 @@ _ol_interaction_Extent_.getDefaultExtentStyleFunction_ = function() {
|
|||||||
* @return {ol.StyleFunction} Default pointer style
|
* @return {ol.StyleFunction} Default pointer style
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_interaction_Extent_.getDefaultPointerStyleFunction_ = function() {
|
ExtentInteraction.getDefaultPointerStyleFunction_ = function() {
|
||||||
var style = _ol_style_Style_.createDefaultEditing();
|
var style = _ol_style_Style_.createDefaultEditing();
|
||||||
return function(feature, resolution) {
|
return function(feature, resolution) {
|
||||||
return style[GeometryType.POINT];
|
return style[GeometryType.POINT];
|
||||||
@@ -267,7 +267,7 @@ _ol_interaction_Extent_.getDefaultPointerStyleFunction_ = function() {
|
|||||||
* @returns {function (ol.Coordinate): ol.Extent} event handler
|
* @returns {function (ol.Coordinate): ol.Extent} event handler
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_interaction_Extent_.getPointHandler_ = function(fixedPoint) {
|
ExtentInteraction.getPointHandler_ = function(fixedPoint) {
|
||||||
return function(point) {
|
return function(point) {
|
||||||
return boundingExtent([fixedPoint, point]);
|
return boundingExtent([fixedPoint, point]);
|
||||||
};
|
};
|
||||||
@@ -279,7 +279,7 @@ _ol_interaction_Extent_.getPointHandler_ = function(fixedPoint) {
|
|||||||
* @returns {function (ol.Coordinate): ol.Extent|null} event handler
|
* @returns {function (ol.Coordinate): ol.Extent|null} event handler
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_interaction_Extent_.getEdgeHandler_ = function(fixedP1, fixedP2) {
|
ExtentInteraction.getEdgeHandler_ = function(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]]]);
|
||||||
@@ -298,7 +298,7 @@ _ol_interaction_Extent_.getEdgeHandler_ = function(fixedP1, fixedP2) {
|
|||||||
* @returns {Array<Array<ol.Coordinate>>} extent line segments
|
* @returns {Array<Array<ol.Coordinate>>} extent line segments
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_interaction_Extent_.getSegments_ = function(extent) {
|
ExtentInteraction.getSegments_ = function(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]]],
|
||||||
@@ -313,7 +313,7 @@ _ol_interaction_Extent_.getSegments_ = function(extent) {
|
|||||||
* @returns {ol.Coordinate|null} snapped vertex on extent
|
* @returns {ol.Coordinate|null} snapped vertex on extent
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_interaction_Extent_.prototype.snapToVertex_ = function(pixel, map) {
|
ExtentInteraction.prototype.snapToVertex_ = function(pixel, map) {
|
||||||
var pixelCoordinate = map.getCoordinateFromPixel(pixel);
|
var pixelCoordinate = map.getCoordinateFromPixel(pixel);
|
||||||
var sortByDistance = function(a, b) {
|
var sortByDistance = function(a, b) {
|
||||||
return _ol_coordinate_.squaredDistanceToSegment(pixelCoordinate, a) -
|
return _ol_coordinate_.squaredDistanceToSegment(pixelCoordinate, a) -
|
||||||
@@ -322,7 +322,7 @@ _ol_interaction_Extent_.prototype.snapToVertex_ = function(pixel, map) {
|
|||||||
var extent = this.getExtent();
|
var 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
|
||||||
var segments = _ol_interaction_Extent_.getSegments_(extent);
|
var segments = ExtentInteraction.getSegments_(extent);
|
||||||
segments.sort(sortByDistance);
|
segments.sort(sortByDistance);
|
||||||
var closestSegment = segments[0];
|
var closestSegment = segments[0];
|
||||||
|
|
||||||
@@ -353,7 +353,7 @@ _ol_interaction_Extent_.prototype.snapToVertex_ = function(pixel, map) {
|
|||||||
* @param {ol.MapBrowserEvent} mapBrowserEvent pointer move event
|
* @param {ol.MapBrowserEvent} mapBrowserEvent pointer move event
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_interaction_Extent_.prototype.handlePointerMove_ = function(mapBrowserEvent) {
|
ExtentInteraction.prototype.handlePointerMove_ = function(mapBrowserEvent) {
|
||||||
var pixel = mapBrowserEvent.pixel;
|
var pixel = mapBrowserEvent.pixel;
|
||||||
var map = mapBrowserEvent.map;
|
var map = mapBrowserEvent.map;
|
||||||
|
|
||||||
@@ -369,7 +369,7 @@ _ol_interaction_Extent_.prototype.handlePointerMove_ = function(mapBrowserEvent)
|
|||||||
* @returns {ol.Feature} extent as featrue
|
* @returns {ol.Feature} extent as featrue
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_interaction_Extent_.prototype.createOrUpdateExtentFeature_ = function(extent) {
|
ExtentInteraction.prototype.createOrUpdateExtentFeature_ = function(extent) {
|
||||||
var extentFeature = this.extentFeature_;
|
var extentFeature = this.extentFeature_;
|
||||||
|
|
||||||
if (!extentFeature) {
|
if (!extentFeature) {
|
||||||
@@ -396,7 +396,7 @@ _ol_interaction_Extent_.prototype.createOrUpdateExtentFeature_ = function(extent
|
|||||||
* @returns {ol.Feature} vertex as feature
|
* @returns {ol.Feature} vertex as feature
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_ol_interaction_Extent_.prototype.createOrUpdatePointerFeature_ = function(vertex) {
|
ExtentInteraction.prototype.createOrUpdatePointerFeature_ = function(vertex) {
|
||||||
var vertexFeature = this.vertexFeature_;
|
var vertexFeature = this.vertexFeature_;
|
||||||
if (!vertexFeature) {
|
if (!vertexFeature) {
|
||||||
vertexFeature = new Feature(new Point(vertex));
|
vertexFeature = new Feature(new Point(vertex));
|
||||||
@@ -413,7 +413,7 @@ _ol_interaction_Extent_.prototype.createOrUpdatePointerFeature_ = function(verte
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
_ol_interaction_Extent_.prototype.setMap = function(map) {
|
ExtentInteraction.prototype.setMap = function(map) {
|
||||||
this.extentOverlay_.setMap(map);
|
this.extentOverlay_.setMap(map);
|
||||||
this.vertexOverlay_.setMap(map);
|
this.vertexOverlay_.setMap(map);
|
||||||
PointerInteraction.prototype.setMap.call(this, map);
|
PointerInteraction.prototype.setMap.call(this, map);
|
||||||
@@ -425,7 +425,7 @@ _ol_interaction_Extent_.prototype.setMap = function(map) {
|
|||||||
* @return {ol.Extent} Drawn extent in the view projection.
|
* @return {ol.Extent} Drawn extent in the view projection.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
_ol_interaction_Extent_.prototype.getExtent = function() {
|
ExtentInteraction.prototype.getExtent = function() {
|
||||||
return this.extent_;
|
return this.extent_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -435,11 +435,11 @@ _ol_interaction_Extent_.prototype.getExtent = function() {
|
|||||||
* @param {ol.Extent} extent Extent
|
* @param {ol.Extent} extent Extent
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
_ol_interaction_Extent_.prototype.setExtent = function(extent) {
|
ExtentInteraction.prototype.setExtent = function(extent) {
|
||||||
//Null extent means no bbox
|
//Null extent means no bbox
|
||||||
this.extent_ = extent ? extent : null;
|
this.extent_ = extent ? extent : null;
|
||||||
this.createOrUpdateExtentFeature_(extent);
|
this.createOrUpdateExtentFeature_(extent);
|
||||||
this.dispatchEvent(new _ol_interaction_Extent_.Event(this.extent_));
|
this.dispatchEvent(new ExtentInteraction.Event(this.extent_));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -453,7 +453,7 @@ _ol_interaction_Extent_.prototype.setExtent = function(extent) {
|
|||||||
* @param {ol.Extent} extent the new extent
|
* @param {ol.Extent} extent the new extent
|
||||||
* @extends {ol.events.Event}
|
* @extends {ol.events.Event}
|
||||||
*/
|
*/
|
||||||
_ol_interaction_Extent_.Event = function(extent) {
|
ExtentInteraction.Event = function(extent) {
|
||||||
Event.call(this, _ol_interaction_ExtentEventType_.EXTENTCHANGED);
|
Event.call(this, _ol_interaction_ExtentEventType_.EXTENTCHANGED);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -464,5 +464,5 @@ _ol_interaction_Extent_.Event = function(extent) {
|
|||||||
this.extent = extent;
|
this.extent = extent;
|
||||||
|
|
||||||
};
|
};
|
||||||
inherits(_ol_interaction_Extent_.Event, Event);
|
inherits(ExtentInteraction.Event, Event);
|
||||||
export default _ol_interaction_Extent_;
|
export default ExtentInteraction;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import Map from '../../../../src/ol/Map.js';
|
import Map from '../../../../src/ol/Map.js';
|
||||||
import MapBrowserPointerEvent from '../../../../src/ol/MapBrowserPointerEvent.js';
|
import MapBrowserPointerEvent from '../../../../src/ol/MapBrowserPointerEvent.js';
|
||||||
import View from '../../../../src/ol/View.js';
|
import View from '../../../../src/ol/View.js';
|
||||||
import _ol_interaction_Extent_ from '../../../../src/ol/interaction/Extent.js';
|
import ExtentInteraction from '../../../../src/ol/interaction/Extent.js';
|
||||||
import _ol_pointer_PointerEvent_ from '../../../../src/ol/pointer/PointerEvent.js';
|
import _ol_pointer_PointerEvent_ from '../../../../src/ol/pointer/PointerEvent.js';
|
||||||
|
|
||||||
describe('ol.interaction.Extent', function() {
|
describe('ol.interaction.Extent', function() {
|
||||||
@@ -24,7 +24,7 @@ describe('ol.interaction.Extent', function() {
|
|||||||
});
|
});
|
||||||
map.renderSync();
|
map.renderSync();
|
||||||
|
|
||||||
interaction = new _ol_interaction_Extent_();
|
interaction = new ExtentInteraction();
|
||||||
map.addInteraction(interaction);
|
map.addInteraction(interaction);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ describe('ol.interaction.Extent', function() {
|
|||||||
|
|
||||||
it('can be configured with an extent', function() {
|
it('can be configured with an extent', function() {
|
||||||
expect(function() {
|
expect(function() {
|
||||||
new _ol_interaction_Extent_({
|
new ExtentInteraction({
|
||||||
extent: [-10, -10, 10, 10]
|
extent: [-10, -10, 10, 10]
|
||||||
});
|
});
|
||||||
}).to.not.throwException();
|
}).to.not.throwException();
|
||||||
|
|||||||
Reference in New Issue
Block a user