From e6a491856d5897e82168daa1d5c8bba0987e6a8d Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Fri, 26 Jan 2018 15:21:16 +0100 Subject: [PATCH] Named exports from ol/geom/flat/geodesic --- src/ol/Graticule.js | 12 +++---- src/ol/geom/flat/geodesic.js | 61 +++++++++++++++++------------------- 2 files changed, 33 insertions(+), 40 deletions(-) diff --git a/src/ol/Graticule.js b/src/ol/Graticule.js index 0fe38b2e58..6265ef2b2a 100644 --- a/src/ol/Graticule.js +++ b/src/ol/Graticule.js @@ -6,7 +6,7 @@ import {intersects, getCenter} from './extent.js'; import GeometryLayout from './geom/GeometryLayout.js'; import LineString from './geom/LineString.js'; import Point from './geom/Point.js'; -import _ol_geom_flat_geodesic_ from './geom/flat/geodesic.js'; +import {meridian, parallel} from './geom/flat/geodesic.js'; import {clamp} from './math.js'; import {get as getProjection, equivalent as equivalentProjection, getTransform, transformExtent} from './proj.js'; import RenderEventType from './render/EventType.js'; @@ -565,9 +565,8 @@ Graticule.prototype.getMap = function() { * @param {number} index Index. * @private */ -Graticule.prototype.getMeridian_ = function(lon, minLat, maxLat, - squaredTolerance, index) { - const flatCoordinates = _ol_geom_flat_geodesic_.meridian(lon, +Graticule.prototype.getMeridian_ = function(lon, minLat, maxLat, squaredTolerance, index) { + const flatCoordinates = meridian(lon, minLat, maxLat, this.projection_, squaredTolerance); const lineString = this.meridians_[index] !== undefined ? this.meridians_[index] : new LineString(null); @@ -595,9 +594,8 @@ Graticule.prototype.getMeridians = function() { * @param {number} index Index. * @private */ -Graticule.prototype.getParallel_ = function(lat, minLon, maxLon, - squaredTolerance, index) { - const flatCoordinates = _ol_geom_flat_geodesic_.parallel(lat, +Graticule.prototype.getParallel_ = function(lat, minLon, maxLon, squaredTolerance, index) { + const flatCoordinates = parallel(lat, minLon, maxLon, this.projection_, squaredTolerance); const lineString = this.parallels_[index] !== undefined ? this.parallels_[index] : new LineString(null); diff --git a/src/ol/geom/flat/geodesic.js b/src/ol/geom/flat/geodesic.js index dfaeabedcf..3b6c5c0dee 100644 --- a/src/ol/geom/flat/geodesic.js +++ b/src/ol/geom/flat/geodesic.js @@ -3,18 +3,16 @@ */ import {squaredSegmentDistance, toRadians, toDegrees} from '../../math.js'; import {get as getProjection, getTransform} from '../../proj.js'; -const _ol_geom_flat_geodesic_ = {}; /** - * @private * @param {function(number): ol.Coordinate} interpolate Interpolate function. * @param {ol.TransformFunction} transform Transform from longitude/latitude to * projected coordinates. * @param {number} squaredTolerance Squared tolerance. * @return {Array.} Flat coordinates. */ -_ol_geom_flat_geodesic_.line_ = function(interpolate, transform, squaredTolerance) { +function line(interpolate, transform, squaredTolerance) { // FIXME reduce garbage generation // FIXME optimize stack operations @@ -77,22 +75,20 @@ _ol_geom_flat_geodesic_.line_ = function(interpolate, transform, squaredToleranc } return flatCoordinates; -}; +} /** -* Generate a great-circle arcs between two lat/lon points. -* @param {number} lon1 Longitude 1 in degrees. -* @param {number} lat1 Latitude 1 in degrees. -* @param {number} lon2 Longitude 2 in degrees. -* @param {number} lat2 Latitude 2 in degrees. + * Generate a great-circle arcs between two lat/lon points. + * @param {number} lon1 Longitude 1 in degrees. + * @param {number} lat1 Latitude 1 in degrees. + * @param {number} lon2 Longitude 2 in degrees. + * @param {number} lat2 Latitude 2 in degrees. * @param {ol.proj.Projection} projection Projection. -* @param {number} squaredTolerance Squared tolerance. -* @return {Array.} Flat coordinates. -*/ -_ol_geom_flat_geodesic_.greatCircleArc = function( - lon1, lat1, lon2, lat2, projection, squaredTolerance) { - + * @param {number} squaredTolerance Squared tolerance. + * @return {Array.} Flat coordinates. + */ +export function greatCircleArc(lon1, lat1, lon2, lat2, projection, squaredTolerance) { const geoProjection = getProjection('EPSG:4326'); const cosLat1 = Math.cos(toRadians(lat1)); @@ -103,11 +99,11 @@ _ol_geom_flat_geodesic_.greatCircleArc = function( const sinDeltaLon = Math.sin(toRadians(lon2 - lon1)); const d = sinLat1 * sinLat2 + cosLat1 * cosLat2 * cosDeltaLon; - return _ol_geom_flat_geodesic_.line_( + return line( /** - * @param {number} frac Fraction. - * @return {ol.Coordinate} Coordinate. - */ + * @param {number} frac Fraction. + * @return {ol.Coordinate} Coordinate. + */ function(frac) { if (1 <= d) { return [lon2, lat2]; @@ -124,7 +120,7 @@ _ol_geom_flat_geodesic_.greatCircleArc = function( cosD - sinLat1 * Math.sin(lat)); return [toDegrees(lon), toDegrees(lat)]; }, getTransform(geoProjection, projection), squaredTolerance); -}; +} /** @@ -136,18 +132,18 @@ _ol_geom_flat_geodesic_.greatCircleArc = function( * @param {number} squaredTolerance Squared tolerance. * @return {Array.} Flat coordinates. */ -_ol_geom_flat_geodesic_.meridian = function(lon, lat1, lat2, projection, squaredTolerance) { +export function meridian(lon, lat1, lat2, projection, squaredTolerance) { const epsg4326Projection = getProjection('EPSG:4326'); - return _ol_geom_flat_geodesic_.line_( + return line( /** - * @param {number} frac Fraction. - * @return {ol.Coordinate} Coordinate. - */ + * @param {number} frac Fraction. + * @return {ol.Coordinate} Coordinate. + */ function(frac) { return [lon, lat1 + ((lat2 - lat1) * frac)]; }, getTransform(epsg4326Projection, projection), squaredTolerance); -}; +} /** @@ -159,16 +155,15 @@ _ol_geom_flat_geodesic_.meridian = function(lon, lat1, lat2, projection, squared * @param {number} squaredTolerance Squared tolerance. * @return {Array.} Flat coordinates. */ -_ol_geom_flat_geodesic_.parallel = function(lat, lon1, lon2, projection, squaredTolerance) { +export function parallel(lat, lon1, lon2, projection, squaredTolerance) { const epsg4326Projection = getProjection('EPSG:4326'); - return _ol_geom_flat_geodesic_.line_( + return line( /** - * @param {number} frac Fraction. - * @return {ol.Coordinate} Coordinate. - */ + * @param {number} frac Fraction. + * @return {ol.Coordinate} Coordinate. + */ function(frac) { return [lon1 + ((lon2 - lon1) * frac), lat]; }, getTransform(epsg4326Projection, projection), squaredTolerance); -}; -export default _ol_geom_flat_geodesic_; +}