Named exports from ol/coordinate

This commit is contained in:
Tim Schaub
2018-02-09 14:31:20 -07:00
parent ce12dc1253
commit b97554f2f3
16 changed files with 126 additions and 160 deletions
+4 -4
View File
@@ -3,7 +3,7 @@
*/
import {inherits} from '../index.js';
import ViewHint from '../ViewHint.js';
import _ol_coordinate_ from '../coordinate.js';
import {scale as scaleCoordinate, rotate as rotateCoordinate, add as addCoordinate} from '../coordinate.js';
import {easeOut} from '../easing.js';
import {noModifierKeys} from '../events/condition.js';
import {FALSE} from '../functions.js';
@@ -81,9 +81,9 @@ DragPan.handleDragEvent_ = function(mapBrowserEvent) {
const view = map.getView();
const viewState = view.getState();
let center = [deltaX, deltaY];
_ol_coordinate_.scale(center, viewState.resolution);
_ol_coordinate_.rotate(center, viewState.rotation);
_ol_coordinate_.add(center, viewState.center);
scaleCoordinate(center, viewState.resolution);
rotateCoordinate(center, viewState.rotation);
addCoordinate(center, viewState.center);
center = view.constrainCenter(center);
view.setCenter(center);
}
+3 -3
View File
@@ -7,7 +7,7 @@ import Feature from '../Feature.js';
import MapBrowserEventType from '../MapBrowserEventType.js';
import MapBrowserPointerEvent from '../MapBrowserPointerEvent.js';
import BaseObject from '../Object.js';
import _ol_coordinate_ from '../coordinate.js';
import {squaredDistance as squaredCoordinateDistance} from '../coordinate.js';
import {listen} from '../events.js';
import Event from '../events/Event.js';
import {noModifierKeys, always, shiftKeyOnly} from '../events/condition.js';
@@ -158,7 +158,7 @@ const Draw = function(options) {
geometryFunction = function(coordinates, opt_geometry) {
const circle = opt_geometry ? /** @type {ol.geom.Circle} */ (opt_geometry) :
new Circle([NaN, NaN]);
const squaredLength = _ol_coordinate_.squaredDistance(
const squaredLength = squaredCoordinateDistance(
coordinates[0], coordinates[1]);
circle.setCenterAndRadius(coordinates[0], Math.sqrt(squaredLength));
return circle;
@@ -853,7 +853,7 @@ Draw.createRegularPolygon = function(opt_sides, opt_angle) {
const center = coordinates[0];
const end = coordinates[1];
const radius = Math.sqrt(
_ol_coordinate_.squaredDistance(center, end));
squaredCoordinateDistance(center, end));
const geometry = opt_geometry ? /** @type {ol.geom.Polygon} */ (opt_geometry) :
fromCircle(new Circle(center), opt_sides);
const angle = opt_angle ? opt_angle :
+7 -7
View File
@@ -5,7 +5,7 @@ import {inherits} from '../index.js';
import Feature from '../Feature.js';
import MapBrowserEventType from '../MapBrowserEventType.js';
import MapBrowserPointerEvent from '../MapBrowserPointerEvent.js';
import _ol_coordinate_ from '../coordinate.js';
import {squaredDistanceToSegment, closestOnSegment, distance as coordinateDistance, squaredDistance as squaredCoordinateDistance} from '../coordinate.js';
import Event from '../events/Event.js';
import {boundingExtent, getArea} from '../extent.js';
import GeometryType from '../geom/GeometryType.js';
@@ -316,8 +316,8 @@ ExtentInteraction.getSegments_ = function(extent) {
ExtentInteraction.prototype.snapToVertex_ = function(pixel, map) {
const pixelCoordinate = map.getCoordinateFromPixel(pixel);
const sortByDistance = function(a, b) {
return _ol_coordinate_.squaredDistanceToSegment(pixelCoordinate, a) -
_ol_coordinate_.squaredDistanceToSegment(pixelCoordinate, b);
return squaredDistanceToSegment(pixelCoordinate, a) -
squaredDistanceToSegment(pixelCoordinate, b);
};
const extent = this.getExtent();
if (extent) {
@@ -326,17 +326,17 @@ ExtentInteraction.prototype.snapToVertex_ = function(pixel, map) {
segments.sort(sortByDistance);
const closestSegment = segments[0];
let vertex = (_ol_coordinate_.closestOnSegment(pixelCoordinate,
let vertex = (closestOnSegment(pixelCoordinate,
closestSegment));
const vertexPixel = map.getPixelFromCoordinate(vertex);
//if the distance is within tolerance, snap to the segment
if (_ol_coordinate_.distance(pixel, vertexPixel) <= this.pixelTolerance_) {
if (coordinateDistance(pixel, vertexPixel) <= this.pixelTolerance_) {
//test if we should further snap to a vertex
const pixel1 = map.getPixelFromCoordinate(closestSegment[0]);
const pixel2 = map.getPixelFromCoordinate(closestSegment[1]);
const squaredDist1 = _ol_coordinate_.squaredDistance(vertexPixel, pixel1);
const squaredDist2 = _ol_coordinate_.squaredDistance(vertexPixel, pixel2);
const squaredDist1 = squaredCoordinateDistance(vertexPixel, pixel1);
const squaredDist2 = squaredCoordinateDistance(vertexPixel, pixel2);
const dist = Math.sqrt(Math.min(squaredDist1, squaredDist2));
this.snappedToVertex_ = dist <= this.pixelTolerance_;
if (this.snappedToVertex_) {
+2 -2
View File
@@ -2,7 +2,7 @@
* @module ol/interaction/KeyboardPan
*/
import {inherits} from '../index.js';
import _ol_coordinate_ from '../coordinate.js';
import {rotate as rotateCoordinate} from '../coordinate.js';
import EventType from '../events/EventType.js';
import KeyCode from '../events/KeyCode.js';
import {noModifierKeys, targetNotEditable} from '../events/condition.js';
@@ -100,7 +100,7 @@ KeyboardPan.handleEvent = function(mapBrowserEvent) {
deltaY = mapUnitsDelta;
}
const delta = [deltaX, deltaY];
_ol_coordinate_.rotate(delta, view.getRotation());
rotateCoordinate(delta, view.getRotation());
Interaction.pan(view, delta, this.duration_);
mapBrowserEvent.preventDefault();
stopEvent = true;
+15 -15
View File
@@ -8,7 +8,7 @@ import Feature from '../Feature.js';
import MapBrowserEventType from '../MapBrowserEventType.js';
import MapBrowserPointerEvent from '../MapBrowserPointerEvent.js';
import {equals} from '../array.js';
import _ol_coordinate_ from '../coordinate.js';
import {equals as coordinatesEqual, distance as coordinateDistance, squaredDistance as squaredCoordinateDistance, squaredDistanceToSegment, closestOnSegment} from '../coordinate.js';
import {listen, unlisten} from '../events.js';
import Event from '../events/Event.js';
import EventType from '../events/EventType.js';
@@ -637,15 +637,15 @@ Modify.handleDownEvent_ = function(evt) {
segmentDataMatch.index === Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX) {
const closestVertex = Modify.closestOnSegmentData_(pixelCoordinate, segmentDataMatch);
if (_ol_coordinate_.equals(closestVertex, vertex) && !componentSegments[uid][0]) {
if (coordinatesEqual(closestVertex, vertex) && !componentSegments[uid][0]) {
this.dragSegments_.push([segmentDataMatch, 0]);
componentSegments[uid][0] = segmentDataMatch;
}
} else if (_ol_coordinate_.equals(segment[0], vertex) &&
} else if (coordinatesEqual(segment[0], vertex) &&
!componentSegments[uid][0]) {
this.dragSegments_.push([segmentDataMatch, 0]);
componentSegments[uid][0] = segmentDataMatch;
} else if (_ol_coordinate_.equals(segment[1], vertex) &&
} else if (coordinatesEqual(segment[1], vertex) &&
!componentSegments[uid][1]) {
// prevent dragging closed linestrings by the connecting node
@@ -737,7 +737,7 @@ Modify.handleDragEvent_ = function(evt) {
this.changingFeature_ = false;
} else { // We're dragging the circle's circumference:
this.changingFeature_ = true;
geometry.setRadius(_ol_coordinate_.distance(geometry.getCenter(), vertex));
geometry.setRadius(coordinateDistance(geometry.getCenter(), vertex));
this.changingFeature_ = false;
}
break;
@@ -859,7 +859,7 @@ Modify.prototype.handlePointerAtPixel_ = function(pixel, map) {
const closestSegment = node.segment;
let vertex = Modify.closestOnSegmentData_(pixelCoordinate, node);
const vertexPixel = map.getPixelFromCoordinate(vertex);
let dist = _ol_coordinate_.distance(pixel, vertexPixel);
let dist = coordinateDistance(pixel, vertexPixel);
if (dist <= this.pixelTolerance_) {
const vertexSegments = {};
@@ -871,8 +871,8 @@ Modify.prototype.handlePointerAtPixel_ = function(pixel, map) {
} else {
const pixel1 = map.getPixelFromCoordinate(closestSegment[0]);
const pixel2 = map.getPixelFromCoordinate(closestSegment[1]);
const squaredDist1 = _ol_coordinate_.squaredDistance(vertexPixel, pixel1);
const squaredDist2 = _ol_coordinate_.squaredDistance(vertexPixel, pixel2);
const squaredDist1 = squaredCoordinateDistance(vertexPixel, pixel1);
const squaredDist2 = squaredCoordinateDistance(vertexPixel, pixel2);
dist = Math.sqrt(Math.min(squaredDist1, squaredDist2));
this.snappedToVertex_ = dist <= this.pixelTolerance_;
if (this.snappedToVertex_) {
@@ -883,10 +883,10 @@ Modify.prototype.handlePointerAtPixel_ = function(pixel, map) {
let segment;
for (let i = 1, ii = nodes.length; i < ii; ++i) {
segment = nodes[i].segment;
if ((_ol_coordinate_.equals(closestSegment[0], segment[0]) &&
_ol_coordinate_.equals(closestSegment[1], segment[1]) ||
(_ol_coordinate_.equals(closestSegment[0], segment[1]) &&
_ol_coordinate_.equals(closestSegment[1], segment[0])))) {
if ((coordinatesEqual(closestSegment[0], segment[0]) &&
coordinatesEqual(closestSegment[1], segment[1]) ||
(coordinatesEqual(closestSegment[0], segment[1]) &&
coordinatesEqual(closestSegment[1], segment[0])))) {
vertexSegments[getUid(segment)] = true;
} else {
break;
@@ -923,13 +923,13 @@ Modify.pointDistanceToSegmentDataSquared_ = function(pointCoordinates, segmentDa
if (segmentData.index === Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX) {
const distanceToCenterSquared =
_ol_coordinate_.squaredDistance(circleGeometry.getCenter(), pointCoordinates);
squaredCoordinateDistance(circleGeometry.getCenter(), pointCoordinates);
const distanceToCircumference =
Math.sqrt(distanceToCenterSquared) - circleGeometry.getRadius();
return distanceToCircumference * distanceToCircumference;
}
}
return _ol_coordinate_.squaredDistanceToSegment(pointCoordinates, segmentData.segment);
return squaredDistanceToSegment(pointCoordinates, segmentData.segment);
};
/**
@@ -948,7 +948,7 @@ Modify.closestOnSegmentData_ = function(pointCoordinates, segmentData) {
segmentData.index === Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX) {
return geometry.getClosestPoint(pointCoordinates);
}
return _ol_coordinate_.closestOnSegment(pointCoordinates, segmentData.segment);
return closestOnSegment(pointCoordinates, segmentData.segment);
};
+10 -10
View File
@@ -4,7 +4,7 @@
import {getUid, inherits} from '../index.js';
import Collection from '../Collection.js';
import CollectionEventType from '../CollectionEventType.js';
import _ol_coordinate_ from '../coordinate.js';
import {distance as coordinateDistance, squaredDistance as squaredCoordinateDistance, closestOnCircle, closestOnSegment, squaredDistanceToSegment} from '../coordinate.js';
import {listen, unlistenByKey} from '../events.js';
import EventType from '../events/EventType.js';
import {boundingExtent, createEmpty} from '../extent.js';
@@ -371,8 +371,8 @@ Snap.prototype.snapTo = function(pixel, pixelCoordinate, map) {
if (this.vertex_ && !this.edge_) {
pixel1 = map.getPixelFromCoordinate(closestSegment[0]);
pixel2 = map.getPixelFromCoordinate(closestSegment[1]);
squaredDist1 = _ol_coordinate_.squaredDistance(pixel, pixel1);
squaredDist2 = _ol_coordinate_.squaredDistance(pixel, pixel2);
squaredDist1 = squaredCoordinateDistance(pixel, pixel1);
squaredDist2 = squaredCoordinateDistance(pixel, pixel2);
dist = Math.sqrt(Math.min(squaredDist1, squaredDist2));
snappedToVertex = dist <= this.pixelTolerance_;
if (snappedToVertex) {
@@ -383,20 +383,20 @@ Snap.prototype.snapTo = function(pixel, pixelCoordinate, map) {
}
} else if (this.edge_) {
if (isCircle) {
vertex = _ol_coordinate_.closestOnCircle(pixelCoordinate,
vertex = closestOnCircle(pixelCoordinate,
/** @type {ol.geom.Circle} */ (segments[0].feature.getGeometry()));
} else {
vertex = (_ol_coordinate_.closestOnSegment(pixelCoordinate,
vertex = (closestOnSegment(pixelCoordinate,
closestSegment));
}
vertexPixel = map.getPixelFromCoordinate(vertex);
if (_ol_coordinate_.distance(pixel, vertexPixel) <= this.pixelTolerance_) {
if (coordinateDistance(pixel, vertexPixel) <= this.pixelTolerance_) {
snapped = true;
if (this.vertex_ && !isCircle) {
pixel1 = map.getPixelFromCoordinate(closestSegment[0]);
pixel2 = map.getPixelFromCoordinate(closestSegment[1]);
squaredDist1 = _ol_coordinate_.squaredDistance(vertexPixel, pixel1);
squaredDist2 = _ol_coordinate_.squaredDistance(vertexPixel, pixel2);
squaredDist1 = squaredCoordinateDistance(vertexPixel, pixel1);
squaredDist2 = squaredCoordinateDistance(vertexPixel, pixel2);
dist = Math.sqrt(Math.min(squaredDist1, squaredDist2));
snappedToVertex = dist <= this.pixelTolerance_;
if (snappedToVertex) {
@@ -622,9 +622,9 @@ Snap.handleUpEvent_ = function(evt) {
* @this {ol.interaction.Snap}
*/
Snap.sortByDistance = function(a, b) {
return _ol_coordinate_.squaredDistanceToSegment(
return squaredDistanceToSegment(
this.pixelCoordinate_, a.segment) -
_ol_coordinate_.squaredDistanceToSegment(
squaredDistanceToSegment(
this.pixelCoordinate_, b.segment);
};
export default Snap;