Merge pull request #7800 from tschaub/named-exports

More named exports
This commit is contained in:
Tim Schaub
2018-02-09 21:43:24 -07:00
committed by GitHub
55 changed files with 427 additions and 473 deletions

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';
@@ -480,8 +480,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;
};
@@ -1215,7 +1215,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';
@@ -470,8 +470,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

@@ -14,7 +14,7 @@ import _ol_render_canvas_ from '../../render/canvas.js';
import CanvasReplayGroup from '../../render/canvas/ReplayGroup.js';
import RendererType from '../Type.js';
import CanvasLayerRenderer from '../canvas/Layer.js';
import _ol_renderer_vector_ from '../vector.js';
import {defaultOrder as defaultRenderOrder, getTolerance as getRenderTolerance, getSquaredTolerance as getSquaredRenderTolerance, renderFeature} from '../vector.js';
/**
* @constructor
@@ -321,7 +321,7 @@ CanvasVectorLayerRenderer.prototype.prepareFrame = function(frameState, layerSta
let vectorLayerRenderOrder = vectorLayer.getRenderOrder();
if (vectorLayerRenderOrder === undefined) {
vectorLayerRenderOrder = _ol_renderer_vector_.defaultOrder;
vectorLayerRenderOrder = defaultRenderOrder;
}
const extent = buffer(frameStateExtent,
@@ -355,14 +355,14 @@ CanvasVectorLayerRenderer.prototype.prepareFrame = function(frameState, layerSta
this.dirty_ = false;
const replayGroup = new CanvasReplayGroup(
_ol_renderer_vector_.getTolerance(resolution, pixelRatio), extent, resolution,
getRenderTolerance(resolution, pixelRatio), extent, resolution,
pixelRatio, vectorSource.getOverlaps(), this.declutterTree_, vectorLayer.getRenderBuffer());
vectorSource.loadFeatures(extent, resolution, projection);
/**
* @param {ol.Feature} feature Feature.
* @this {ol.renderer.canvas.VectorLayer}
*/
const renderFeature = function(feature) {
const render = function(feature) {
let styles;
let styleFunction = feature.getStyleFunction();
if (styleFunction) {
@@ -391,10 +391,10 @@ CanvasVectorLayerRenderer.prototype.prepareFrame = function(frameState, layerSta
}, this);
features.sort(vectorLayerRenderOrder);
for (let i = 0, ii = features.length; i < ii; ++i) {
renderFeature(features[i]);
render(features[i]);
}
} else {
vectorSource.forEachFeatureInExtent(extent, renderFeature, this);
vectorSource.forEachFeatureInExtent(extent, render, this);
}
replayGroup.finish();
@@ -425,15 +425,15 @@ CanvasVectorLayerRenderer.prototype.renderFeature = function(feature, resolution
let loading = false;
if (Array.isArray(styles)) {
for (let i = 0, ii = styles.length; i < ii; ++i) {
loading = _ol_renderer_vector_.renderFeature(
loading = renderFeature(
replayGroup, feature, styles[i],
_ol_renderer_vector_.getSquaredTolerance(resolution, pixelRatio),
getSquaredRenderTolerance(resolution, pixelRatio),
this.handleStyleImageChange_, this) || loading;
}
} else {
loading = _ol_renderer_vector_.renderFeature(
loading = renderFeature(
replayGroup, feature, styles,
_ol_renderer_vector_.getSquaredTolerance(resolution, pixelRatio),
getSquaredRenderTolerance(resolution, pixelRatio),
this.handleStyleImageChange_, this);
}
return loading;

View File

@@ -18,7 +18,7 @@ import CanvasReplayGroup from '../../render/canvas/ReplayGroup.js';
import _ol_render_replay_ from '../../render/replay.js';
import RendererType from '../Type.js';
import CanvasTileLayerRenderer from '../canvas/TileLayer.js';
import _ol_renderer_vector_ from '../vector.js';
import {getSquaredTolerance as getSquaredRenderTolerance, renderFeature} from '../vector.js';
import _ol_transform_ from '../../transform.js';
/**
@@ -192,14 +192,14 @@ CanvasVectorTileLayerRenderer.prototype.createReplayGroup_ = function(
replayState.dirty = false;
const replayGroup = new CanvasReplayGroup(0, sharedExtent, resolution,
pixelRatio, source.getOverlaps(), this.declutterTree_, layer.getRenderBuffer());
const squaredTolerance = _ol_renderer_vector_.getSquaredTolerance(
const squaredTolerance = getSquaredRenderTolerance(
resolution, pixelRatio);
/**
* @param {ol.Feature|ol.render.Feature} feature Feature.
* @this {ol.renderer.canvas.VectorTileLayer}
*/
const renderFeature = function(feature) {
const render = function(feature) {
let styles;
let styleFunction = feature.getStyleFunction();
if (styleFunction) {
@@ -234,7 +234,7 @@ CanvasVectorTileLayerRenderer.prototype.createReplayGroup_ = function(
feature.getGeometry().transform(tileProjection, projection);
}
if (!bufferedExtent || intersects(bufferedExtent, feature.getGeometry().getExtent())) {
renderFeature.call(this, feature);
render.call(this, feature);
}
}
replayGroup.finish();
@@ -466,12 +466,12 @@ CanvasVectorTileLayerRenderer.prototype.renderFeature = function(feature, square
let loading = false;
if (Array.isArray(styles)) {
for (let i = 0, ii = styles.length; i < ii; ++i) {
loading = _ol_renderer_vector_.renderFeature(
loading = renderFeature(
replayGroup, feature, styles[i], squaredTolerance,
this.handleStyleImageChange_, this) || loading;
}
} else {
loading = _ol_renderer_vector_.renderFeature(
loading = renderFeature(
replayGroup, feature, styles, squaredTolerance,
this.handleStyleImageChange_, this);
}

View File

@@ -5,7 +5,6 @@ import {getUid} from '../index.js';
import ImageState from '../ImageState.js';
import GeometryType from '../geom/GeometryType.js';
import ReplayType from '../render/ReplayType.js';
const _ol_renderer_vector_ = {};
/**
@@ -15,14 +14,32 @@ const _ol_renderer_vector_ = {};
const SIMPLIFY_TOLERANCE = 0.5;
/**
* @const
* @type {Object.<ol.geom.GeometryType,
* function(ol.render.ReplayGroup, ol.geom.Geometry,
* ol.style.Style, Object)>}
*/
const GEOMETRY_RENDERERS = {
'Point': renderPointGeometry,
'LineString': renderLineStringGeometry,
'Polygon': renderPolygonGeometry,
'MultiPoint': renderMultiPointGeometry,
'MultiLineString': renderMultiLineStringGeometry,
'MultiPolygon': renderMultiPolygonGeometry,
'GeometryCollection': renderGeometryCollectionGeometry,
'Circle': renderCircleGeometry
};
/**
* @param {ol.Feature|ol.render.Feature} feature1 Feature 1.
* @param {ol.Feature|ol.render.Feature} feature2 Feature 2.
* @return {number} Order.
*/
_ol_renderer_vector_.defaultOrder = function(feature1, feature2) {
export function defaultOrder(feature1, feature2) {
return getUid(feature1) - getUid(feature2);
};
}
/**
@@ -30,10 +47,10 @@ _ol_renderer_vector_.defaultOrder = function(feature1, feature2) {
* @param {number} pixelRatio Pixel ratio.
* @return {number} Squared pixel tolerance.
*/
_ol_renderer_vector_.getSquaredTolerance = function(resolution, pixelRatio) {
const tolerance = _ol_renderer_vector_.getTolerance(resolution, pixelRatio);
export function getSquaredTolerance(resolution, pixelRatio) {
const tolerance = getTolerance(resolution, pixelRatio);
return tolerance * tolerance;
};
}
/**
@@ -41,9 +58,9 @@ _ol_renderer_vector_.getSquaredTolerance = function(resolution, pixelRatio) {
* @param {number} pixelRatio Pixel ratio.
* @return {number} Pixel tolerance.
*/
_ol_renderer_vector_.getTolerance = function(resolution, pixelRatio) {
export function getTolerance(resolution, pixelRatio) {
return SIMPLIFY_TOLERANCE * resolution / pixelRatio;
};
}
/**
@@ -51,9 +68,8 @@ _ol_renderer_vector_.getTolerance = function(resolution, pixelRatio) {
* @param {ol.geom.Circle} geometry Geometry.
* @param {ol.style.Style} style Style.
* @param {ol.Feature} feature Feature.
* @private
*/
_ol_renderer_vector_.renderCircleGeometry_ = function(replayGroup, geometry, style, feature) {
function renderCircleGeometry(replayGroup, geometry, style, feature) {
const fillStyle = style.getFill();
const strokeStyle = style.getStroke();
if (fillStyle || strokeStyle) {
@@ -67,7 +83,7 @@ _ol_renderer_vector_.renderCircleGeometry_ = function(replayGroup, geometry, sty
textReplay.setTextStyle(textStyle, replayGroup.addDeclutter(false));
textReplay.drawText(geometry, feature);
}
};
}
/**
@@ -80,8 +96,7 @@ _ol_renderer_vector_.renderCircleGeometry_ = function(replayGroup, geometry, sty
* @return {boolean} `true` if style is loading.
* @template T
*/
_ol_renderer_vector_.renderFeature = function(
replayGroup, feature, style, squaredTolerance, listener, thisArg) {
export function renderFeature(replayGroup, feature, style, squaredTolerance, listener, thisArg) {
let loading = false;
const imageStyle = style.getImage();
if (imageStyle) {
@@ -97,11 +112,10 @@ _ol_renderer_vector_.renderFeature = function(
loading = true;
}
}
_ol_renderer_vector_.renderFeature_(replayGroup, feature, style,
squaredTolerance);
renderFeatureInternal(replayGroup, feature, style, squaredTolerance);
return loading;
};
}
/**
@@ -109,10 +123,8 @@ _ol_renderer_vector_.renderFeature = function(
* @param {ol.Feature|ol.render.Feature} feature Feature.
* @param {ol.style.Style} style Style.
* @param {number} squaredTolerance Squared tolerance.
* @private
*/
_ol_renderer_vector_.renderFeature_ = function(
replayGroup, feature, style, squaredTolerance) {
function renderFeatureInternal(replayGroup, feature, style, squaredTolerance) {
const geometry = style.getGeometryFunction()(feature);
if (!geometry) {
return;
@@ -120,13 +132,12 @@ _ol_renderer_vector_.renderFeature_ = function(
const simplifiedGeometry = geometry.getSimplifiedGeometry(squaredTolerance);
const renderer = style.getRenderer();
if (renderer) {
_ol_renderer_vector_.renderGeometry_(replayGroup, simplifiedGeometry, style, feature);
renderGeometry(replayGroup, simplifiedGeometry, style, feature);
} else {
const geometryRenderer =
_ol_renderer_vector_.GEOMETRY_RENDERERS_[simplifiedGeometry.getType()];
const geometryRenderer = GEOMETRY_RENDERERS[simplifiedGeometry.getType()];
geometryRenderer(replayGroup, simplifiedGeometry, style, feature);
}
};
}
/**
@@ -134,19 +145,18 @@ _ol_renderer_vector_.renderFeature_ = function(
* @param {ol.geom.Geometry} geometry Geometry.
* @param {ol.style.Style} style Style.
* @param {ol.Feature|ol.render.Feature} feature Feature.
* @private
*/
_ol_renderer_vector_.renderGeometry_ = function(replayGroup, geometry, style, feature) {
function renderGeometry(replayGroup, geometry, style, feature) {
if (geometry.getType() == GeometryType.GEOMETRY_COLLECTION) {
const geometries = /** @type {ol.geom.GeometryCollection} */ (geometry).getGeometries();
for (let i = 0, ii = geometries.length; i < ii; ++i) {
_ol_renderer_vector_.renderGeometry_(replayGroup, geometries[i], style, feature);
renderGeometry(replayGroup, geometries[i], style, feature);
}
return;
}
const replay = replayGroup.getReplay(style.getZIndex(), ReplayType.DEFAULT);
replay.drawCustom(/** @type {ol.geom.SimpleGeometry} */ (geometry), feature, style.getRenderer());
};
}
/**
@@ -154,17 +164,16 @@ _ol_renderer_vector_.renderGeometry_ = function(replayGroup, geometry, style, fe
* @param {ol.geom.GeometryCollection} geometry Geometry.
* @param {ol.style.Style} style Style.
* @param {ol.Feature} feature Feature.
* @private
*/
_ol_renderer_vector_.renderGeometryCollectionGeometry_ = function(replayGroup, geometry, style, feature) {
function renderGeometryCollectionGeometry(replayGroup, geometry, style, feature) {
const geometries = geometry.getGeometriesArray();
let i, ii;
for (i = 0, ii = geometries.length; i < ii; ++i) {
const geometryRenderer =
_ol_renderer_vector_.GEOMETRY_RENDERERS_[geometries[i].getType()];
GEOMETRY_RENDERERS[geometries[i].getType()];
geometryRenderer(replayGroup, geometries[i], style, feature);
}
};
}
/**
@@ -172,9 +181,8 @@ _ol_renderer_vector_.renderGeometryCollectionGeometry_ = function(replayGroup, g
* @param {ol.geom.LineString|ol.render.Feature} geometry Geometry.
* @param {ol.style.Style} style Style.
* @param {ol.Feature|ol.render.Feature} feature Feature.
* @private
*/
_ol_renderer_vector_.renderLineStringGeometry_ = function(replayGroup, geometry, style, feature) {
function renderLineStringGeometry(replayGroup, geometry, style, feature) {
const strokeStyle = style.getStroke();
if (strokeStyle) {
const lineStringReplay = replayGroup.getReplay(style.getZIndex(), ReplayType.LINE_STRING);
@@ -187,7 +195,7 @@ _ol_renderer_vector_.renderLineStringGeometry_ = function(replayGroup, geometry,
textReplay.setTextStyle(textStyle, replayGroup.addDeclutter(false));
textReplay.drawText(geometry, feature);
}
};
}
/**
@@ -195,9 +203,8 @@ _ol_renderer_vector_.renderLineStringGeometry_ = function(replayGroup, geometry,
* @param {ol.geom.MultiLineString|ol.render.Feature} geometry Geometry.
* @param {ol.style.Style} style Style.
* @param {ol.Feature|ol.render.Feature} feature Feature.
* @private
*/
_ol_renderer_vector_.renderMultiLineStringGeometry_ = function(replayGroup, geometry, style, feature) {
function renderMultiLineStringGeometry(replayGroup, geometry, style, feature) {
const strokeStyle = style.getStroke();
if (strokeStyle) {
const lineStringReplay = replayGroup.getReplay(style.getZIndex(), ReplayType.LINE_STRING);
@@ -210,7 +217,7 @@ _ol_renderer_vector_.renderMultiLineStringGeometry_ = function(replayGroup, geom
textReplay.setTextStyle(textStyle, replayGroup.addDeclutter(false));
textReplay.drawText(geometry, feature);
}
};
}
/**
@@ -218,9 +225,8 @@ _ol_renderer_vector_.renderMultiLineStringGeometry_ = function(replayGroup, geom
* @param {ol.geom.MultiPolygon} geometry Geometry.
* @param {ol.style.Style} style Style.
* @param {ol.Feature} feature Feature.
* @private
*/
_ol_renderer_vector_.renderMultiPolygonGeometry_ = function(replayGroup, geometry, style, feature) {
function renderMultiPolygonGeometry(replayGroup, geometry, style, feature) {
const fillStyle = style.getFill();
const strokeStyle = style.getStroke();
if (strokeStyle || fillStyle) {
@@ -234,7 +240,7 @@ _ol_renderer_vector_.renderMultiPolygonGeometry_ = function(replayGroup, geometr
textReplay.setTextStyle(textStyle, replayGroup.addDeclutter(false));
textReplay.drawText(geometry, feature);
}
};
}
/**
@@ -242,9 +248,8 @@ _ol_renderer_vector_.renderMultiPolygonGeometry_ = function(replayGroup, geometr
* @param {ol.geom.Point|ol.render.Feature} geometry Geometry.
* @param {ol.style.Style} style Style.
* @param {ol.Feature|ol.render.Feature} feature Feature.
* @private
*/
_ol_renderer_vector_.renderPointGeometry_ = function(replayGroup, geometry, style, feature) {
function renderPointGeometry(replayGroup, geometry, style, feature) {
const imageStyle = style.getImage();
if (imageStyle) {
if (imageStyle.getImageState() != ImageState.LOADED) {
@@ -260,7 +265,7 @@ _ol_renderer_vector_.renderPointGeometry_ = function(replayGroup, geometry, styl
textReplay.setTextStyle(textStyle, replayGroup.addDeclutter(!!imageStyle));
textReplay.drawText(geometry, feature);
}
};
}
/**
@@ -268,9 +273,8 @@ _ol_renderer_vector_.renderPointGeometry_ = function(replayGroup, geometry, styl
* @param {ol.geom.MultiPoint|ol.render.Feature} geometry Geometry.
* @param {ol.style.Style} style Style.
* @param {ol.Feature|ol.render.Feature} feature Feature.
* @private
*/
_ol_renderer_vector_.renderMultiPointGeometry_ = function(replayGroup, geometry, style, feature) {
function renderMultiPointGeometry(replayGroup, geometry, style, feature) {
const imageStyle = style.getImage();
if (imageStyle) {
if (imageStyle.getImageState() != ImageState.LOADED) {
@@ -286,7 +290,7 @@ _ol_renderer_vector_.renderMultiPointGeometry_ = function(replayGroup, geometry,
textReplay.setTextStyle(textStyle, replayGroup.addDeclutter(!!imageStyle));
textReplay.drawText(geometry, feature);
}
};
}
/**
@@ -294,9 +298,8 @@ _ol_renderer_vector_.renderMultiPointGeometry_ = function(replayGroup, geometry,
* @param {ol.geom.Polygon|ol.render.Feature} geometry Geometry.
* @param {ol.style.Style} style Style.
* @param {ol.Feature|ol.render.Feature} feature Feature.
* @private
*/
_ol_renderer_vector_.renderPolygonGeometry_ = function(replayGroup, geometry, style, feature) {
function renderPolygonGeometry(replayGroup, geometry, style, feature) {
const fillStyle = style.getFill();
const strokeStyle = style.getStroke();
if (fillStyle || strokeStyle) {
@@ -310,24 +313,4 @@ _ol_renderer_vector_.renderPolygonGeometry_ = function(replayGroup, geometry, st
textReplay.setTextStyle(textStyle, replayGroup.addDeclutter(false));
textReplay.drawText(geometry, feature);
}
};
/**
* @const
* @private
* @type {Object.<ol.geom.GeometryType,
* function(ol.render.ReplayGroup, ol.geom.Geometry,
* ol.style.Style, Object)>}
*/
_ol_renderer_vector_.GEOMETRY_RENDERERS_ = {
'Point': _ol_renderer_vector_.renderPointGeometry_,
'LineString': _ol_renderer_vector_.renderLineStringGeometry_,
'Polygon': _ol_renderer_vector_.renderPolygonGeometry_,
'MultiPoint': _ol_renderer_vector_.renderMultiPointGeometry_,
'MultiLineString': _ol_renderer_vector_.renderMultiLineStringGeometry_,
'MultiPolygon': _ol_renderer_vector_.renderMultiPolygonGeometry_,
'GeometryCollection': _ol_renderer_vector_.renderGeometryCollectionGeometry_,
'Circle': _ol_renderer_vector_.renderCircleGeometry_
};
export default _ol_renderer_vector_;
}

View File

@@ -7,7 +7,7 @@ import ViewHint from '../../ViewHint.js';
import {buffer, containsExtent, createEmpty} from '../../extent.js';
import WebGLReplayGroup from '../../render/webgl/ReplayGroup.js';
import RendererType from '../Type.js';
import _ol_renderer_vector_ from '../vector.js';
import {defaultOrder as defaultRenderOrder, getTolerance as getRenderTolerance, getSquaredTolerance as getSquaredRenderTolerance, renderFeature} from '../vector.js';
import WebGLLayerRenderer from '../webgl/Layer.js';
import _ol_transform_ from '../../transform.js';
@@ -235,7 +235,7 @@ WebGLVectorLayerRenderer.prototype.prepareFrame = function(frameState, layerStat
let vectorLayerRenderOrder = vectorLayer.getRenderOrder();
if (vectorLayerRenderOrder === undefined) {
vectorLayerRenderOrder = _ol_renderer_vector_.defaultOrder;
vectorLayerRenderOrder = defaultRenderOrder;
}
const extent = buffer(frameStateExtent,
@@ -257,14 +257,14 @@ WebGLVectorLayerRenderer.prototype.prepareFrame = function(frameState, layerStat
this.dirty_ = false;
const replayGroup = new WebGLReplayGroup(
_ol_renderer_vector_.getTolerance(resolution, pixelRatio),
getRenderTolerance(resolution, pixelRatio),
extent, vectorLayer.getRenderBuffer());
vectorSource.loadFeatures(extent, resolution, projection);
/**
* @param {ol.Feature} feature Feature.
* @this {ol.renderer.webgl.VectorLayer}
*/
const renderFeature = function(feature) {
const render = function(feature) {
let styles;
let styleFunction = feature.getStyleFunction();
if (styleFunction) {
@@ -292,9 +292,9 @@ WebGLVectorLayerRenderer.prototype.prepareFrame = function(frameState, layerStat
features.push(feature);
}, this);
features.sort(vectorLayerRenderOrder);
features.forEach(renderFeature.bind(this));
features.forEach(render.bind(this));
} else {
vectorSource.forEachFeatureInExtent(extent, renderFeature, this);
vectorSource.forEachFeatureInExtent(extent, render, this);
}
replayGroup.finish(context);
@@ -324,15 +324,15 @@ WebGLVectorLayerRenderer.prototype.renderFeature = function(feature, resolution,
let loading = false;
if (Array.isArray(styles)) {
for (let i = styles.length - 1, ii = 0; i >= ii; --i) {
loading = _ol_renderer_vector_.renderFeature(
loading = renderFeature(
replayGroup, feature, styles[i],
_ol_renderer_vector_.getSquaredTolerance(resolution, pixelRatio),
getSquaredRenderTolerance(resolution, pixelRatio),
this.handleStyleImageChange_, this) || loading;
}
} else {
loading = _ol_renderer_vector_.renderFeature(
loading = renderFeature(
replayGroup, feature, styles,
_ol_renderer_vector_.getSquaredTolerance(resolution, pixelRatio),
getSquaredRenderTolerance(resolution, pixelRatio),
this.handleStyleImageChange_, this) || loading;
}
return loading;

View File

@@ -5,7 +5,6 @@ import {createCanvasContext2D} from './dom.js';
import {containsCoordinate, createEmpty, extend, getHeight, getTopLeft, getWidth} from './extent.js';
import {solveLinearSystem} from './math.js';
import {getPointResolution, transform} from './proj.js';
const _ol_reproj_ = {};
/**
@@ -20,7 +19,7 @@ const _ol_reproj_ = {};
* @param {number} targetResolution Target resolution.
* @return {number} The best resolution to use. Can be +-Infinity, NaN or 0.
*/
_ol_reproj_.calculateSourceResolution = function(sourceProj, targetProj,
export function calculateSourceResolution(sourceProj, targetProj,
targetCenter, targetResolution) {
const sourceCenter = transform(targetCenter, targetProj, sourceProj);
@@ -51,7 +50,7 @@ _ol_reproj_.calculateSourceResolution = function(sourceProj, targetProj,
}
return sourceResolution;
};
}
/**
@@ -63,14 +62,13 @@ _ol_reproj_.calculateSourceResolution = function(sourceProj, targetProj,
* @param {number} x X coordinate of the point (in pixels).
* @param {number} y Y coordinate of the point (in pixels).
* @return {ol.Coordinate} New point 1 px farther from the centroid.
* @private
*/
_ol_reproj_.enlargeClipPoint_ = function(centroidX, centroidY, x, y) {
function enlargeClipPoint(centroidX, centroidY, x, y) {
const dX = x - centroidX;
const dY = y - centroidY;
const distance = Math.sqrt(dX * dX + dY * dY);
return [Math.round(x + dX / distance), Math.round(y + dY / distance)];
};
}
/**
@@ -91,7 +89,7 @@ _ol_reproj_.enlargeClipPoint_ = function(centroidX, centroidY, x, y) {
* @param {boolean=} opt_renderEdges Render reprojection edges.
* @return {HTMLCanvasElement} Canvas with reprojected data.
*/
_ol_reproj_.render = function(width, height, pixelRatio,
export function render(width, height, pixelRatio,
sourceResolution, sourceExtent, targetResolution, targetExtent,
triangulation, sources, gutter, opt_renderEdges) {
@@ -193,9 +191,9 @@ _ol_reproj_.render = function(width, height, pixelRatio,
context.beginPath();
const centroidX = (u0 + u1 + u2) / 3;
const centroidY = (v0 + v1 + v2) / 3;
const p0 = _ol_reproj_.enlargeClipPoint_(centroidX, centroidY, u0, v0);
const p1 = _ol_reproj_.enlargeClipPoint_(centroidX, centroidY, u1, v1);
const p2 = _ol_reproj_.enlargeClipPoint_(centroidX, centroidY, u2, v2);
const p0 = enlargeClipPoint(centroidX, centroidY, u0, v0);
const p1 = enlargeClipPoint(centroidX, centroidY, u1, v1);
const p2 = enlargeClipPoint(centroidX, centroidY, u2, v2);
context.moveTo(p1[0], p1[1]);
context.lineTo(p0[0], p0[1]);
@@ -241,5 +239,4 @@ _ol_reproj_.render = function(width, height, pixelRatio,
context.restore();
}
return context.canvas;
};
export default _ol_reproj_;
}

View File

@@ -8,7 +8,7 @@ import ImageState from '../ImageState.js';
import {listen, unlistenByKey} from '../events.js';
import EventType from '../events/EventType.js';
import {getCenter, getIntersection, getHeight, getWidth} from '../extent.js';
import _ol_reproj_ from '../reproj.js';
import {calculateSourceResolution, render as renderReprojected} from '../reproj.js';
import Triangulation from '../reproj/Triangulation.js';
/**
@@ -46,7 +46,7 @@ const ReprojImage = function(sourceProj, targetProj,
getIntersection(targetExtent, maxTargetExtent) : targetExtent;
const targetCenter = getCenter(limitedTargetExtent);
const sourceResolution = _ol_reproj_.calculateSourceResolution(
const sourceResolution = calculateSourceResolution(
sourceProj, targetProj, targetCenter, targetResolution);
const errorThresholdInPixels = ERROR_THRESHOLD;
@@ -148,7 +148,7 @@ ReprojImage.prototype.reproject_ = function() {
const width = getWidth(this.targetExtent_) / this.targetResolution_;
const height = getHeight(this.targetExtent_) / this.targetResolution_;
this.canvas_ = _ol_reproj_.render(width, height, this.sourcePixelRatio_,
this.canvas_ = renderReprojected(width, height, this.sourcePixelRatio_,
this.sourceImage_.getResolution(), this.maxSourceExtent_,
this.targetResolution_, this.targetExtent_, this.triangulation_, [{
extent: this.sourceImage_.getExtent(),

View File

@@ -9,7 +9,7 @@ import {listen, unlistenByKey} from '../events.js';
import EventType from '../events/EventType.js';
import {getArea, getCenter, getIntersection} from '../extent.js';
import {clamp} from '../math.js';
import _ol_reproj_ from '../reproj.js';
import {calculateSourceResolution, render as renderReprojected} from '../reproj.js';
import Triangulation from '../reproj/Triangulation.js';
/**
@@ -125,7 +125,7 @@ const ReprojTile = function(sourceProj, sourceTileGrid,
this.wrappedTileCoord_[0]);
const targetCenter = getCenter(limitedTargetExtent);
const sourceResolution = _ol_reproj_.calculateSourceResolution(
const sourceResolution = calculateSourceResolution(
sourceProj, targetProj, targetCenter, targetResolution);
if (!isFinite(sourceResolution) || sourceResolution <= 0) {
@@ -237,7 +237,7 @@ ReprojTile.prototype.reproject_ = function() {
const targetExtent = this.targetTileGrid_.getTileCoordExtent(
this.wrappedTileCoord_);
this.canvas_ = _ol_reproj_.render(width, height, this.pixelRatio_,
this.canvas_ = renderReprojected(width, height, this.pixelRatio_,
sourceResolution, this.sourceTileGrid_.getExtent(),
targetResolution, targetExtent, this.triangulation_, sources,
this.gutter_, this.renderEdges_);

View File

@@ -9,7 +9,7 @@ import {get as getProjection, getTransformFromProjections} from '../proj.js';
import SourceState from '../source/State.js';
import TileImage from '../source/TileImage.js';
import _ol_tilecoord_ from '../tilecoord.js';
import _ol_tilegrid_ from '../tilegrid.js';
import {createXYZ, extentFromProjection} from '../tilegrid.js';
/**
* @classdesc
@@ -129,10 +129,10 @@ BingMaps.prototype.handleImageryMetadataResponse = function(response) {
const maxZoom = this.maxZoom_ == -1 ? resource.zoomMax : this.maxZoom_;
const sourceProjection = this.getProjection();
const extent = _ol_tilegrid_.extentFromProjection(sourceProjection);
const extent = extentFromProjection(sourceProjection);
const tileSize = resource.imageWidth == resource.imageHeight ?
resource.imageWidth : [resource.imageWidth, resource.imageHeight];
const tileGrid = _ol_tilegrid_.createXYZ({
const tileGrid = createXYZ({
extent: extent,
minZoom: resource.zoomMin,
maxZoom: maxZoom,

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

@@ -11,7 +11,7 @@ import EventType from '../events/EventType.js';
import {containsExtent, getCenter, getForViewAndSize, getHeight, getWidth} from '../extent.js';
import {assign} from '../obj.js';
import {get as getProjection, transform} from '../proj.js';
import _ol_reproj_ from '../reproj.js';
import {calculateSourceResolution} from '../reproj.js';
import ImageSource from '../source/Image.js';
import WMSServerType from '../source/WMSServerType.js';
import {compareVersions} from '../string.js';
@@ -141,7 +141,7 @@ ImageWMS.prototype.getGetFeatureInfoUrl = function(coordinate, resolution, proje
const sourceProjectionObj = this.getProjection();
if (sourceProjectionObj && sourceProjectionObj !== projectionObj) {
resolution = _ol_reproj_.calculateSourceResolution(sourceProjectionObj, projectionObj, coordinate, resolution);
resolution = calculateSourceResolution(sourceProjectionObj, projectionObj, coordinate, resolution);
coordinate = transform(coordinate, projectionObj, sourceProjectionObj);
}

View File

@@ -9,7 +9,7 @@ import {equivalent} from '../proj.js';
import {toSize, scale as scaleSize} from '../size.js';
import Source from '../source/Source.js';
import _ol_tilecoord_ from '../tilecoord.js';
import _ol_tilegrid_ from '../tilegrid.js';
import {wrapX, getForProjection as getTileGridForProjection} from '../tilegrid.js';
/**
* @classdesc
@@ -215,7 +215,7 @@ TileSource.prototype.getTileGrid = function() {
*/
TileSource.prototype.getTileGridForProjection = function(projection) {
if (!this.tileGrid) {
return _ol_tilegrid_.getForProjection(projection);
return getTileGridForProjection(projection);
} else {
return this.tileGrid;
}
@@ -281,7 +281,7 @@ TileSource.prototype.getTileCoordForTileUrlFunction = function(tileCoord, opt_pr
opt_projection : this.getProjection();
const tileGrid = this.getTileGridForProjection(projection);
if (this.getWrapX() && projection.isGlobal()) {
tileCoord = _ol_tilegrid_.wrapX(tileGrid, tileCoord, projection);
tileCoord = wrapX(tileGrid, tileCoord, projection);
}
return _ol_tilecoord_.withinExtentAndZ(tileCoord, tileGrid) ? tileCoord : null;
};

View File

@@ -12,7 +12,7 @@ import {equivalent, get as getProjection} from '../proj.js';
import ReprojTile from '../reproj/Tile.js';
import UrlTile from '../source/UrlTile.js';
import _ol_tilecoord_ from '../tilecoord.js';
import _ol_tilegrid_ from '../tilegrid.js';
import {getForProjection as getTileGridForProjection} from '../tilegrid.js';
/**
* @classdesc
@@ -174,7 +174,7 @@ TileImage.prototype.getTileGridForProjection = function(projection) {
const projKey = getUid(projection).toString();
if (!(projKey in this.tileGridForProjection)) {
this.tileGridForProjection[projKey] =
_ol_tilegrid_.getForProjection(projection);
getTileGridForProjection(projection);
}
return /** @type {!ol.tilegrid.TileGrid} */ (this.tileGridForProjection[projKey]);
}

View File

@@ -15,7 +15,7 @@ import {jsonp as requestJSONP} from '../net.js';
import {get as getProjection, getTransformFromProjections} from '../proj.js';
import SourceState from '../source/State.js';
import TileImage from '../source/TileImage.js';
import _ol_tilegrid_ from '../tilegrid.js';
import {createXYZ, extentFromProjection} from '../tilegrid.js';
/**
* @classdesc
@@ -126,8 +126,8 @@ TileJSON.prototype.handleTileJSONResponse = function(tileJSON) {
const minZoom = tileJSON.minzoom || 0;
const maxZoom = tileJSON.maxzoom || 22;
const tileGrid = _ol_tilegrid_.createXYZ({
extent: _ol_tilegrid_.extentFromProjection(sourceProjection),
const tileGrid = createXYZ({
extent: extentFromProjection(sourceProjection),
maxZoom: maxZoom,
minZoom: minZoom
});

View File

@@ -14,7 +14,7 @@ import {get as getProjection, getTransformFromProjections} from '../proj.js';
import SourceState from '../source/State.js';
import TileSource from '../source/Tile.js';
import _ol_tilecoord_ from '../tilecoord.js';
import _ol_tilegrid_ from '../tilegrid.js';
import {createXYZ, extentFromProjection} from '../tilegrid.js';
/**
* @classdesc
@@ -176,8 +176,8 @@ UTFGrid.prototype.handleTileJSONResponse = function(tileJSON) {
const minZoom = tileJSON.minzoom || 0;
const maxZoom = tileJSON.maxzoom || 22;
const tileGrid = _ol_tilegrid_.createXYZ({
extent: _ol_tilegrid_.extentFromProjection(sourceProjection),
const tileGrid = createXYZ({
extent: extentFromProjection(sourceProjection),
maxZoom: maxZoom,
minZoom: minZoom
});

View File

@@ -9,7 +9,7 @@ import {buffer, createEmpty} from '../extent.js';
import {assign} from '../obj.js';
import {modulo} from '../math.js';
import {get as getProjection, transform, transformExtent} from '../proj.js';
import _ol_reproj_ from '../reproj.js';
import {calculateSourceResolution} from '../reproj.js';
import {toSize, buffer as bufferSize, scale as scaleSize} from '../size.js';
import TileImage from '../source/TileImage.js';
import WMSServerType from '../source/WMSServerType.js';
@@ -135,7 +135,7 @@ TileWMS.prototype.getGetFeatureInfoUrl = function(coordinate, resolution, projec
}
if (sourceProjectionObj && sourceProjectionObj !== projectionObj) {
tileResolution = _ol_reproj_.calculateSourceResolution(sourceProjectionObj, projectionObj, coordinate, tileResolution);
tileResolution = calculateSourceResolution(sourceProjectionObj, projectionObj, coordinate, tileResolution);
tileExtent = transformExtent(tileExtent, projectionObj, sourceProjectionObj);
coordinate = transform(coordinate, projectionObj, sourceProjectionObj);
}

View File

@@ -8,7 +8,7 @@ import VectorTile from '../VectorTile.js';
import {toSize} from '../size.js';
import UrlTile from '../source/UrlTile.js';
import _ol_tilecoord_ from '../tilecoord.js';
import _ol_tilegrid_ from '../tilegrid.js';
import {createXYZ, extentFromProjection, createForProjection} from '../tilegrid.js';
/**
* @classdesc
@@ -29,9 +29,9 @@ import _ol_tilegrid_ from '../tilegrid.js';
const VectorTileSource = function(options) {
const projection = options.projection || 'EPSG:3857';
const extent = options.extent || _ol_tilegrid_.extentFromProjection(projection);
const extent = options.extent || extentFromProjection(projection);
const tileGrid = options.tileGrid || _ol_tilegrid_.createXYZ({
const tileGrid = options.tileGrid || createXYZ({
extent: extent,
maxZoom: options.maxZoom || 22,
minZoom: options.minZoom,
@@ -143,7 +143,7 @@ VectorTileSource.prototype.getTileGridForProjection = function(projection) {
// A tile grid that matches the tile size of the source tile grid is more
// likely to have 1:1 relationships between source tiles and rendered tiles.
const sourceTileGrid = this.tileGrid;
tileGrid = this.tileGrids_[code] = _ol_tilegrid_.createForProjection(projection, undefined,
tileGrid = this.tileGrids_[code] = createForProjection(projection, undefined,
sourceTileGrid ? sourceTileGrid.getTileSize(sourceTileGrid.getMinZoom()) : undefined);
}
return tileGrid;

View File

@@ -3,7 +3,7 @@
*/
import {inherits} from '../index.js';
import TileImage from '../source/TileImage.js';
import _ol_tilegrid_ from '../tilegrid.js';
import {createXYZ, extentFromProjection} from '../tilegrid.js';
/**
* @classdesc
@@ -33,8 +33,8 @@ const XYZ = function(opt_options) {
options.projection : 'EPSG:3857';
const tileGrid = options.tileGrid !== undefined ? options.tileGrid :
_ol_tilegrid_.createXYZ({
extent: _ol_tilegrid_.extentFromProjection(projection),
createXYZ({
extent: extentFromProjection(projection),
maxZoom: options.maxZoom,
minZoom: options.minZoom,
tileSize: options.tileSize

View File

@@ -9,21 +9,20 @@ import {assign} from './obj.js';
import {get as getProjection, METERS_PER_UNIT} from './proj.js';
import Units from './proj/Units.js';
import TileGrid from './tilegrid/TileGrid.js';
const _ol_tilegrid_ = {};
/**
* @param {ol.proj.Projection} projection Projection.
* @return {!ol.tilegrid.TileGrid} Default tile grid for the passed projection.
*/
_ol_tilegrid_.getForProjection = function(projection) {
export function getForProjection(projection) {
let tileGrid = projection.getDefaultTileGrid();
if (!tileGrid) {
tileGrid = _ol_tilegrid_.createForProjection(projection);
tileGrid = createForProjection(projection);
projection.setDefaultTileGrid(tileGrid);
}
return tileGrid;
};
}
/**
@@ -32,10 +31,10 @@ _ol_tilegrid_.getForProjection = function(projection) {
* @param {ol.proj.Projection} projection Projection.
* @return {ol.TileCoord} Tile coordinate.
*/
_ol_tilegrid_.wrapX = function(tileGrid, tileCoord, projection) {
export function wrapX(tileGrid, tileCoord, projection) {
const z = tileCoord[0];
const center = tileGrid.getTileCoordCenter(tileCoord);
const projectionExtent = _ol_tilegrid_.extentFromProjection(projection);
const projectionExtent = extentFromProjection(projection);
if (!containsCoordinate(projectionExtent, center)) {
const worldWidth = getWidth(projectionExtent);
const worldsAway = Math.ceil((projectionExtent[0] - center[0]) / worldWidth);
@@ -44,7 +43,7 @@ _ol_tilegrid_.wrapX = function(tileGrid, tileCoord, projection) {
} else {
return tileCoord;
}
};
}
/**
@@ -57,10 +56,10 @@ _ol_tilegrid_.wrapX = function(tileGrid, tileCoord, projection) {
* ol.extent.Corner.TOP_LEFT).
* @return {!ol.tilegrid.TileGrid} TileGrid instance.
*/
_ol_tilegrid_.createForExtent = function(extent, opt_maxZoom, opt_tileSize, opt_corner) {
export function createForExtent(extent, opt_maxZoom, opt_tileSize, opt_corner) {
const corner = opt_corner !== undefined ? opt_corner : Corner.TOP_LEFT;
const resolutions = _ol_tilegrid_.resolutionsFromExtent(
const resolutions = resolutionsFromExtent(
extent, opt_maxZoom, opt_tileSize);
return new TileGrid({
@@ -69,7 +68,7 @@ _ol_tilegrid_.createForExtent = function(extent, opt_maxZoom, opt_tileSize, opt_
resolutions: resolutions,
tileSize: opt_tileSize
});
};
}
/**
@@ -78,19 +77,19 @@ _ol_tilegrid_.createForExtent = function(extent, opt_maxZoom, opt_tileSize, opt_
* @return {!ol.tilegrid.TileGrid} Tile grid instance.
* @api
*/
_ol_tilegrid_.createXYZ = function(opt_options) {
export function createXYZ(opt_options) {
const options = /** @type {olx.tilegrid.TileGridOptions} */ ({});
assign(options, opt_options !== undefined ?
opt_options : /** @type {olx.tilegrid.XYZOptions} */ ({}));
if (options.extent === undefined) {
options.extent = getProjection('EPSG:3857').getExtent();
}
options.resolutions = _ol_tilegrid_.resolutionsFromExtent(
options.resolutions = resolutionsFromExtent(
options.extent, options.maxZoom, options.tileSize);
delete options.maxZoom;
return new TileGrid(options);
};
}
/**
@@ -102,7 +101,7 @@ _ol_tilegrid_.createXYZ = function(opt_options) {
* DEFAULT_TILE_SIZE).
* @return {!Array.<number>} Resolutions array.
*/
_ol_tilegrid_.resolutionsFromExtent = function(extent, opt_maxZoom, opt_tileSize) {
function resolutionsFromExtent(extent, opt_maxZoom, opt_tileSize) {
const maxZoom = opt_maxZoom !== undefined ?
opt_maxZoom : DEFAULT_MAX_ZOOM;
@@ -120,7 +119,7 @@ _ol_tilegrid_.resolutionsFromExtent = function(extent, opt_maxZoom, opt_tileSize
resolutions[z] = maxResolution / Math.pow(2, z);
}
return resolutions;
};
}
/**
@@ -133,11 +132,11 @@ _ol_tilegrid_.resolutionsFromExtent = function(extent, opt_maxZoom, opt_tileSize
* ol.extent.Corner.BOTTOM_LEFT).
* @return {!ol.tilegrid.TileGrid} TileGrid instance.
*/
_ol_tilegrid_.createForProjection = function(projection, opt_maxZoom, opt_tileSize, opt_corner) {
const extent = _ol_tilegrid_.extentFromProjection(projection);
return _ol_tilegrid_.createForExtent(
export function createForProjection(projection, opt_maxZoom, opt_tileSize, opt_corner) {
const extent = extentFromProjection(projection);
return createForExtent(
extent, opt_maxZoom, opt_tileSize, opt_corner);
};
}
/**
@@ -146,7 +145,7 @@ _ol_tilegrid_.createForProjection = function(projection, opt_maxZoom, opt_tileSi
* @param {ol.ProjectionLike} projection Projection.
* @return {ol.Extent} Extent.
*/
_ol_tilegrid_.extentFromProjection = function(projection) {
export function extentFromProjection(projection) {
projection = getProjection(projection);
let extent = projection.getExtent();
if (!extent) {
@@ -155,5 +154,4 @@ _ol_tilegrid_.extentFromProjection = function(projection) {
extent = createOrUpdate(-half, -half, half, half);
}
return extent;
};
export default _ol_tilegrid_;
}