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

View File

@@ -2,12 +2,12 @@ import Map from '../src/ol/Map.js';
import View from '../src/ol/View.js';
import {defaults as defaultControls} from '../src/ol/control.js';
import MousePosition from '../src/ol/control/MousePosition.js';
import _ol_coordinate_ from '../src/ol/coordinate.js';
import {createStringXY} from '../src/ol/coordinate.js';
import TileLayer from '../src/ol/layer/Tile.js';
import OSM from '../src/ol/source/OSM.js';
const mousePositionControl = new MousePosition({
coordinateFormat: _ol_coordinate_.createStringXY(4),
coordinateFormat: createStringXY(4),
projection: 'EPSG:4326',
// comment the following two lines to have the mouse position
// be placed within the map.
@@ -41,6 +41,6 @@ projectionSelect.addEventListener('change', function(event) {
const precisionInput = document.getElementById('precision');
precisionInput.addEventListener('change', function(event) {
const format = _ol_coordinate_.createStringXY(event.target.valueAsNumber);
const format = createStringXY(event.target.valueAsNumber);
mousePositionControl.setCoordinateFormat(format);
});

View File

@@ -1,7 +1,7 @@
import Map from '../src/ol/Map.js';
import Overlay from '../src/ol/Overlay.js';
import View from '../src/ol/View.js';
import _ol_coordinate_ from '../src/ol/coordinate.js';
import {toStringHDMS} from '../src/ol/coordinate.js';
import TileLayer from '../src/ol/layer/Tile.js';
import {fromLonLat, toLonLat} from '../src/ol/proj.js';
import OSM from '../src/ol/source/OSM.js';
@@ -47,7 +47,7 @@ map.addOverlay(popup);
map.on('click', function(evt) {
const element = popup.getElement();
const coordinate = evt.coordinate;
const hdms = _ol_coordinate_.toStringHDMS(toLonLat(coordinate));
const hdms = toStringHDMS(toLonLat(coordinate));
$(element).popover('destroy');
popup.setPosition(coordinate);

View File

@@ -1,7 +1,7 @@
import Map from '../src/ol/Map.js';
import Overlay from '../src/ol/Overlay.js';
import View from '../src/ol/View.js';
import _ol_coordinate_ from '../src/ol/coordinate.js';
import {toStringHDMS} from '../src/ol/coordinate.js';
import TileLayer from '../src/ol/layer/Tile.js';
import {toLonLat} from '../src/ol/proj.js';
import TileJSON from '../src/ol/source/TileJSON.js';
@@ -64,7 +64,7 @@ const map = new Map({
*/
map.on('singleclick', function(evt) {
const coordinate = evt.coordinate;
const hdms = _ol_coordinate_.toStringHDMS(toLonLat(coordinate));
const hdms = toStringHDMS(toLonLat(coordinate));
content.innerHTML = '<p>You clicked here:</p><code>' + hdms +
'</code>';

View File

@@ -1,7 +1,7 @@
/**
* @module ol/Graticule
*/
import _ol_coordinate_ from './coordinate.js';
import {degreesToStringHDMS} from './coordinate.js';
import {intersects, getCenter} from './extent.js';
import GeometryLayout from './geom/GeometryLayout.js';
import LineString from './geom/LineString.js';
@@ -244,7 +244,7 @@ const Graticule = function(opt_options) {
this.parallelsLabels_ = null;
if (options.showLabels == true) {
const degreesToString = _ol_coordinate_.degreesToStringHDMS;
const degreesToString = degreesToStringHDMS;
/**
* @type {null|function(number):string}

View File

@@ -11,7 +11,7 @@ import ViewHint from './ViewHint.js';
import ViewProperty from './ViewProperty.js';
import {linearFindNearest} from './array.js';
import {assert} from './asserts.js';
import _ol_coordinate_ from './coordinate.js';
import {add as addCoordinate, rotate as rotateCoordinate, equals as coordinatesEqual} from './coordinate.js';
import {inAndOut} from './easing.js';
import {getForViewAndSize, getCenter, getHeight, getWidth, isEmpty} from './extent.js';
import GeometryType from './geom/GeometryType.js';
@@ -479,8 +479,8 @@ View.prototype.calculateCenterRotate = function(rotation, anchor) {
const currentCenter = this.getCenter();
if (currentCenter !== undefined) {
center = [currentCenter[0] - anchor[0], currentCenter[1] - anchor[1]];
_ol_coordinate_.rotate(center, rotation - this.getRotation());
_ol_coordinate_.add(center, anchor);
rotateCoordinate(center, rotation - this.getRotation());
addCoordinate(center, anchor);
}
return center;
};
@@ -1214,7 +1214,7 @@ View.createRotationConstraint_ = function(options) {
*/
View.isNoopAnimation = function(animation) {
if (animation.sourceCenter && animation.targetCenter) {
if (!_ol_coordinate_.equals(animation.sourceCenter, animation.targetCenter)) {
if (!coordinatesEqual(animation.sourceCenter, animation.targetCenter)) {
return false;
}
}

View File

@@ -12,7 +12,7 @@ import Overlay from '../Overlay.js';
import OverlayPositioning from '../OverlayPositioning.js';
import ViewProperty from '../ViewProperty.js';
import Control from '../control/Control.js';
import _ol_coordinate_ from '../coordinate.js';
import {rotateCoordinate, add as addCoordinate} from '../coordinate.js';
import {CLASS_CONTROL, CLASS_UNSELECTABLE} from '../css.js';
import {replaceNode} from '../dom.js';
import {listen, listenOnce, unlisten} from '../events.js';
@@ -468,8 +468,8 @@ OverviewMap.prototype.calculateCoordinateRotate_ = function(
coordinate[0] - currentCenter[0],
coordinate[1] - currentCenter[1]
];
_ol_coordinate_.rotate(coordinateRotate, rotation);
_ol_coordinate_.add(coordinateRotate, currentCenter);
rotateCoordinate(coordinateRotate, rotation);
addCoordinate(coordinateRotate, currentCenter);
}
return coordinateRotate;
};

View File

@@ -3,7 +3,6 @@
*/
import {modulo} from './math.js';
import {padNumber} from './string.js';
const _ol_coordinate_ = {};
/**
@@ -21,11 +20,11 @@ const _ol_coordinate_ = {};
* @return {ol.Coordinate} The input coordinate adjusted by the given delta.
* @api
*/
_ol_coordinate_.add = function(coordinate, delta) {
export function add(coordinate, delta) {
coordinate[0] += delta[0];
coordinate[1] += delta[1];
return coordinate;
};
}
/**
@@ -35,7 +34,7 @@ _ol_coordinate_.add = function(coordinate, delta) {
* @param {ol.geom.Circle} circle The circle.
* @return {ol.Coordinate} Closest point on the circumference
*/
_ol_coordinate_.closestOnCircle = function(coordinate, circle) {
export function closestOnCircle(coordinate, circle) {
const r = circle.getRadius();
const center = circle.getCenter();
const x0 = center[0];
@@ -54,7 +53,7 @@ _ol_coordinate_.closestOnCircle = function(coordinate, circle) {
const y = y0 + r * dy / d;
return [x, y];
};
}
/**
@@ -68,7 +67,7 @@ _ol_coordinate_.closestOnCircle = function(coordinate, circle) {
* @return {ol.Coordinate} The foot of the perpendicular of the coordinate to
* the segment.
*/
_ol_coordinate_.closestOnSegment = function(coordinate, segment) {
export function closestOnSegment(coordinate, segment) {
const x0 = coordinate[0];
const y0 = coordinate[1];
const start = segment[0];
@@ -93,7 +92,7 @@ _ol_coordinate_.closestOnSegment = function(coordinate, segment) {
y = y1 + along * dy;
}
return [x, y];
};
}
/**
@@ -119,17 +118,17 @@ _ol_coordinate_.closestOnSegment = function(coordinate, segment) {
* @return {ol.CoordinateFormatType} Coordinate format.
* @api
*/
_ol_coordinate_.createStringXY = function(opt_fractionDigits) {
export function createStringXY(opt_fractionDigits) {
return (
/**
* @param {ol.Coordinate|undefined} coordinate Coordinate.
* @return {string} String XY.
*/
function(coordinate) {
return _ol_coordinate_.toStringXY(coordinate, opt_fractionDigits);
return toStringXY(coordinate, opt_fractionDigits);
}
);
};
}
/**
@@ -139,7 +138,7 @@ _ol_coordinate_.createStringXY = function(opt_fractionDigits) {
* after the decimal point. Default is `0`.
* @return {string} String.
*/
_ol_coordinate_.degreesToStringHDMS = function(hemispheres, degrees, opt_fractionDigits) {
export function degreesToStringHDMS(hemispheres, degrees, opt_fractionDigits) {
const normalizedDegrees = modulo(degrees + 180, 360) - 180;
const x = Math.abs(3600 * normalizedDegrees);
const dflPrecision = opt_fractionDigits || 0;
@@ -163,7 +162,7 @@ _ol_coordinate_.degreesToStringHDMS = function(hemispheres, degrees, opt_fractio
return deg + '\u00b0 ' + padNumber(min, 2) + '\u2032 ' +
padNumber(sec, 2, dflPrecision) + '\u2033' +
(normalizedDegrees == 0 ? '' : ' ' + hemispheres.charAt(normalizedDegrees < 0 ? 1 : 0));
};
}
/**
@@ -193,7 +192,7 @@ _ol_coordinate_.degreesToStringHDMS = function(hemispheres, degrees, opt_fractio
* @return {string} Formatted coordinate.
* @api
*/
_ol_coordinate_.format = function(coordinate, template, opt_fractionDigits) {
export function format(coordinate, template, opt_fractionDigits) {
if (coordinate) {
return template
.replace('{x}', coordinate[0].toFixed(opt_fractionDigits))
@@ -201,15 +200,15 @@ _ol_coordinate_.format = function(coordinate, template, opt_fractionDigits) {
} else {
return '';
}
};
}
/**
* @param {ol.Coordinate} coordinate1 First coordinate.
* @param {ol.Coordinate} coordinate2 Second coordinate.
* @return {boolean} Whether the passed coordinates are equal.
* @return {boolean} The two coordinates are equal.
*/
_ol_coordinate_.equals = function(coordinate1, coordinate2) {
export function equals(coordinate1, coordinate2) {
let equals = true;
for (let i = coordinate1.length - 1; i >= 0; --i) {
if (coordinate1[i] != coordinate2[i]) {
@@ -218,7 +217,7 @@ _ol_coordinate_.equals = function(coordinate1, coordinate2) {
}
}
return equals;
};
}
/**
@@ -237,7 +236,7 @@ _ol_coordinate_.equals = function(coordinate1, coordinate2) {
* @return {ol.Coordinate} Coordinate.
* @api
*/
_ol_coordinate_.rotate = function(coordinate, angle) {
export function rotate(coordinate, angle) {
const cosAngle = Math.cos(angle);
const sinAngle = Math.sin(angle);
const x = coordinate[0] * cosAngle - coordinate[1] * sinAngle;
@@ -245,7 +244,7 @@ _ol_coordinate_.rotate = function(coordinate, angle) {
coordinate[0] = x;
coordinate[1] = y;
return coordinate;
};
}
/**
@@ -263,26 +262,11 @@ _ol_coordinate_.rotate = function(coordinate, angle) {
* @param {number} scale Scale factor.
* @return {ol.Coordinate} Coordinate.
*/
_ol_coordinate_.scale = function(coordinate, scale) {
export function scale(coordinate, scale) {
coordinate[0] *= scale;
coordinate[1] *= scale;
return coordinate;
};
/**
* Subtract `delta` to `coordinate`. `coordinate` is modified in place and
* returned by the function.
*
* @param {ol.Coordinate} coordinate Coordinate.
* @param {ol.Coordinate} delta Delta.
* @return {ol.Coordinate} Coordinate.
*/
_ol_coordinate_.sub = function(coordinate, delta) {
coordinate[0] -= delta[0];
coordinate[1] -= delta[1];
return coordinate;
};
}
/**
@@ -290,11 +274,11 @@ _ol_coordinate_.sub = function(coordinate, delta) {
* @param {ol.Coordinate} coord2 Second coordinate.
* @return {number} Squared distance between coord1 and coord2.
*/
_ol_coordinate_.squaredDistance = function(coord1, coord2) {
export function squaredDistance(coord1, coord2) {
const dx = coord1[0] - coord2[0];
const dy = coord1[1] - coord2[1];
return dx * dx + dy * dy;
};
}
/**
@@ -302,9 +286,9 @@ _ol_coordinate_.squaredDistance = function(coord1, coord2) {
* @param {ol.Coordinate} coord2 Second coordinate.
* @return {number} Distance between coord1 and coord2.
*/
_ol_coordinate_.distance = function(coord1, coord2) {
return Math.sqrt(_ol_coordinate_.squaredDistance(coord1, coord2));
};
export function distance(coord1, coord2) {
return Math.sqrt(squaredDistance(coord1, coord2));
}
/**
@@ -314,10 +298,10 @@ _ol_coordinate_.distance = function(coord1, coord2) {
* @param {Array.<ol.Coordinate>} segment Line segment (2 coordinates).
* @return {number} Squared distance from the point to the line segment.
*/
_ol_coordinate_.squaredDistanceToSegment = function(coordinate, segment) {
return _ol_coordinate_.squaredDistance(coordinate,
_ol_coordinate_.closestOnSegment(coordinate, segment));
};
export function squaredDistanceToSegment(coordinate, segment) {
return squaredDistance(coordinate,
closestOnSegment(coordinate, segment));
}
/**
@@ -342,14 +326,14 @@ _ol_coordinate_.squaredDistanceToSegment = function(coordinate, segment) {
* @return {string} Hemisphere, degrees, minutes and seconds.
* @api
*/
_ol_coordinate_.toStringHDMS = function(coordinate, opt_fractionDigits) {
export function toStringHDMS(coordinate, opt_fractionDigits) {
if (coordinate) {
return _ol_coordinate_.degreesToStringHDMS('NS', coordinate[1], opt_fractionDigits) + ' ' +
_ol_coordinate_.degreesToStringHDMS('EW', coordinate[0], opt_fractionDigits);
return degreesToStringHDMS('NS', coordinate[1], opt_fractionDigits) + ' ' +
degreesToStringHDMS('EW', coordinate[0], opt_fractionDigits);
} else {
return '';
}
};
}
/**
@@ -373,7 +357,6 @@ _ol_coordinate_.toStringHDMS = function(coordinate, opt_fractionDigits) {
* @return {string} XY.
* @api
*/
_ol_coordinate_.toStringXY = function(coordinate, opt_fractionDigits) {
return _ol_coordinate_.format(coordinate, '{x}, {y}', opt_fractionDigits);
};
export default _ol_coordinate_;
export function toStringXY(coordinate, opt_fractionDigits) {
return format(coordinate, '{x}, {y}', opt_fractionDigits);
}

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);
}

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 :

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_) {

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;

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);
};

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;

View File

@@ -2,7 +2,7 @@
* @module ol/renderer/canvas/IntermediateCanvas
*/
import {inherits, nullFunction} from '../../index.js';
import _ol_coordinate_ from '../../coordinate.js';
import {scale as scaleCoordinate} from '../../coordinate.js';
import {createCanvasContext2D} from '../../dom.js';
import {containsExtent, intersects} from '../../extent.js';
import CanvasLayerRenderer from '../canvas/Layer.js';
@@ -129,7 +129,7 @@ IntermediateCanvasRenderer.prototype.forEachLayerAtCoordinate = function(coordin
return CanvasLayerRenderer.prototype.forEachLayerAtCoordinate.apply(this, arguments);
} else {
const pixel = _ol_transform_.apply(this.coordinateToCanvasPixelTransform, coordinate.slice());
_ol_coordinate_.scale(pixel, frameState.viewState.resolution / this.renderedResolution);
scaleCoordinate(pixel, frameState.viewState.resolution / this.renderedResolution);
if (!this.hitCanvasContext_) {
this.hitCanvasContext_ = createCanvasContext2D(1, 1);

View File

@@ -5,7 +5,7 @@
import {getUid, inherits} from '../index.js';
import {assert} from '../asserts.js';
import Feature from '../Feature.js';
import _ol_coordinate_ from '../coordinate.js';
import {scale as scaleCoordinate, add as addCoordinate} from '../coordinate.js';
import EventType from '../events/EventType.js';
import {buffer, createEmpty, createOrUpdateFromCoordinate} from '../extent.js';
import Point from '../geom/Point.js';
@@ -184,12 +184,12 @@ Cluster.prototype.createCluster = function(features) {
for (let i = features.length - 1; i >= 0; --i) {
const geometry = this.geometryFunction(features[i]);
if (geometry) {
_ol_coordinate_.add(centroid, geometry.getCoordinates());
addCoordinate(centroid, geometry.getCoordinates());
} else {
features.splice(i, 1);
}
}
_ol_coordinate_.scale(centroid, 1 / features.length);
scaleCoordinate(centroid, 1 / features.length);
const cluster = new Feature(new Point(centroid));
cluster.set('features', features);

View File

@@ -1,4 +1,4 @@
import _ol_coordinate_ from '../../../src/ol/coordinate.js';
import {add as addCoordinate, scale as scaleCoordinate, rotate as rotateCoordinate, equals as coordinatesEqual, format as formatCoordinate, closestOnCircle, closestOnSegment, createStringXY, squaredDistanceToSegment, toStringXY, toStringHDMS} from '../../../src/ol/coordinate.js';
import Circle from '../../../src/ol/geom/Circle.js';
@@ -13,19 +13,19 @@ describe('ol.coordinate', function() {
});
it('returns a coordinate', function() {
const returnedCoordinate = _ol_coordinate_.add(coordinate, delta);
const returnedCoordinate = addCoordinate(coordinate, delta);
expect(returnedCoordinate).to.be.an('array');
expect(returnedCoordinate).to.have.length(2);
});
it('adds the delta', function() {
const returnedCoordinate = _ol_coordinate_.add(coordinate, delta);
const returnedCoordinate = addCoordinate(coordinate, delta);
expect(returnedCoordinate[0]).to.eql(48.73);
expect(returnedCoordinate[1]).to.eql(10.1);
});
it('modifies in place', function() {
_ol_coordinate_.add(coordinate, delta);
addCoordinate(coordinate, delta);
expect(coordinate[0]).to.eql(48.73);
expect(coordinate[1]).to.eql(10.1);
});
@@ -37,8 +37,8 @@ describe('ol.coordinate', function() {
const bonn2 = [50.73000, 7.10000];
it('compares correctly', function() {
const bonnEqualsBonn = _ol_coordinate_.equals(bonn1, bonn2);
const bonnEqualsCologne = _ol_coordinate_.equals(bonn1, cologne);
const bonnEqualsBonn = coordinatesEqual(bonn1, bonn2);
const bonnEqualsCologne = coordinatesEqual(bonn1, cologne);
expect(bonnEqualsBonn).to.be(true);
expect(bonnEqualsCologne).to.be(false);
});
@@ -51,12 +51,12 @@ describe('ol.coordinate', function() {
});
it('rounds the values', function() {
const string = _ol_coordinate_.format(coordinate, '{x} {y}', 0);
const string = formatCoordinate(coordinate, '{x} {y}', 0);
expect(string).to.eql('7 47');
});
it('handles the optional fractionDigits param', function() {
const string = _ol_coordinate_.format(coordinate, '{x} {y}', 3);
const string = formatCoordinate(coordinate, '{x} {y}', 3);
expect(string).to.eql('6.612 46.792');
});
});
@@ -70,7 +70,7 @@ describe('ol.coordinate', function() {
});
it('returns a CoordinateFormatType', function() {
created = _ol_coordinate_.createStringXY();
created = createStringXY();
expect(created).to.be.a('function');
formatted = created(coordinate);
@@ -79,7 +79,7 @@ describe('ol.coordinate', function() {
});
it('respects opt_fractionDigits', function() {
created = _ol_coordinate_.createStringXY(3);
created = createStringXY(3);
expect(created).to.be.a('function');
formatted = created(coordinate);
@@ -92,11 +92,11 @@ describe('ol.coordinate', function() {
const center = [5, 10];
const circle = new Circle(center, 10);
it('can find the closest point on circle', function() {
expect(_ol_coordinate_.closestOnCircle([-20, 10], circle))
expect(closestOnCircle([-20, 10], circle))
.to.eql([-5, 10]);
});
it('can handle coordinate equal circle center', function() {
expect(_ol_coordinate_.closestOnCircle(center, circle))
expect(closestOnCircle(center, circle))
.to.eql([15, 10]);
});
});
@@ -106,27 +106,27 @@ describe('ol.coordinate', function() {
function() {
const point = [2, 5];
const segment = [[-5, 0], [10, 0]];
expect(_ol_coordinate_.closestOnSegment(point, segment))
expect(closestOnSegment(point, segment))
.to.eql([2, 0]);
});
it('can handle points where the foot of the perpendicular is not closest',
function() {
const point = [0, -6];
const segment = [[-5, 0], [0, -1]];
expect(_ol_coordinate_.closestOnSegment(point, segment))
expect(closestOnSegment(point, segment))
.to.eql([0, -1]);
});
});
describe('#format', function() {
it('can deal with undefined coordinate', function() {
expect(_ol_coordinate_.format()).to.be('');
expect(formatCoordinate()).to.be('');
});
it('formats a coordinate into a template (default precision is 0)',
function() {
const coord = [7.85, 47.983333];
const template = 'Coordinate is ({x}|{y}).';
const got = _ol_coordinate_.format(coord, template);
const got = formatCoordinate(coord, template);
const expected = 'Coordinate is (8|48).';
expect(got).to.be(expected);
});
@@ -134,7 +134,7 @@ describe('ol.coordinate', function() {
function() {
const coord = [7.85, 47.983333];
const template = 'Coordinate is ({x}|{y}).';
const got = _ol_coordinate_.format(coord, template, 2);
const got = formatCoordinate(coord, template, 2);
const expected = 'Coordinate is (7.85|47.98).';
expect(got).to.be(expected);
});
@@ -144,14 +144,14 @@ describe('ol.coordinate', function() {
it('can rotate point in place', function() {
const coord = [7.85, 47.983333];
const rotateRadians = Math.PI / 2; // 90 degrees
_ol_coordinate_.rotate(coord, rotateRadians);
rotateCoordinate(coord, rotateRadians);
expect(coord[0].toFixed(6)).to.eql('-47.983333');
expect(coord[1].toFixed(6)).to.eql('7.850000');
});
it('returns the rotated point', function() {
const coord = [7.85, 47.983333];
const rotateRadians = Math.PI / 2; // 90 degrees
const rotated = _ol_coordinate_.rotate(coord, rotateRadians);
const rotated = rotateCoordinate(coord, rotateRadians);
expect(rotated[0].toFixed(7)).to.eql('-47.9833330');
expect(rotated[1].toFixed(7)).to.eql('7.8500000');
});
@@ -161,49 +161,32 @@ describe('ol.coordinate', function() {
it('can scale point in place', function() {
const coord = [7.85, 47.983333];
const scale = 1.2;
_ol_coordinate_.scale(coord, scale);
scaleCoordinate(coord, scale);
expect(coord[0].toFixed(7)).to.eql('9.4200000');
expect(coord[1].toFixed(7)).to.eql('57.5799996');
});
it('returns the scaled point', function() {
const coord = [7.85, 47.983333];
const scale = 1.2;
const scaledCoord = _ol_coordinate_.scale(coord, scale);
const scaledCoord = scaleCoordinate(coord, scale);
expect(scaledCoord[0].toFixed(7)).to.eql('9.4200000');
expect(scaledCoord[1].toFixed(7)).to.eql('57.5799996');
});
});
describe('#sub', function() {
it('can subtract from point in place', function() {
const coord = [47, 11];
const delta = [1, -1];
_ol_coordinate_.sub(coord, delta);
expect(coord[0]).to.eql(46);
expect(coord[1]).to.eql(12);
});
it('can subtract from point in place', function() {
const coord = [47, 11];
const delta = [1, -1];
const subtracted = _ol_coordinate_.sub(coord, delta);
expect(subtracted[0]).to.eql(46);
expect(subtracted[1]).to.eql(12);
});
});
describe('#squaredDistanceToSegment', function() {
it('can handle points where the foot of the perpendicular is closest',
function() {
const point = [2, 5];
const segment = [[-5, 0], [10, 0]];
expect(_ol_coordinate_.squaredDistanceToSegment(point, segment))
expect(squaredDistanceToSegment(point, segment))
.to.eql(25);
});
it('can handle points where the foot of the perpendicular is not closest',
function() {
const point = [0, -6];
const segment = [[-5, 0], [0, -1]];
expect(_ol_coordinate_.squaredDistanceToSegment(point, segment))
expect(squaredDistanceToSegment(point, segment))
.to.eql(25);
});
@@ -211,19 +194,19 @@ describe('ol.coordinate', function() {
describe('#toStringHDMS', function() {
it('returns the empty string on undefined input', function() {
const got = _ol_coordinate_.toStringHDMS();
const got = toStringHDMS();
const expected = '';
expect(got).to.be(expected);
});
it('formats with zero fractional digits as default', function() {
const coord = [7.85, 47.983333];
const got = _ol_coordinate_.toStringHDMS(coord);
const got = toStringHDMS(coord);
const expected = '47° 59 00″ N 7° 51 00″ E';
expect(got).to.be(expected);
});
it('formats with given fractional digits, if passed', function() {
const coord = [7.85, 47.983333];
const got = _ol_coordinate_.toStringHDMS(coord, 3);
const got = toStringHDMS(coord, 3);
const expected = '47° 58 59.999″ N 7° 51 00.000″ E';
expect(got).to.be(expected);
});
@@ -232,13 +215,13 @@ describe('ol.coordinate', function() {
describe('#toStringXY', function() {
it('formats with zero fractional digits as default', function() {
const coord = [7.85, 47.983333];
const got = _ol_coordinate_.toStringXY(coord);
const got = toStringXY(coord);
const expected = '8, 48';
expect(got).to.be(expected);
});
it('formats with given fractional digits, if passed', function() {
const coord = [7.85, 47.983333];
const got = _ol_coordinate_.toStringXY(coord, 2);
const got = toStringXY(coord, 2);
const expected = '7.85, 47.98';
expect(got).to.be(expected);
});