From d3b616b9487fd84617322abc705ba7e200d0a784 Mon Sep 17 00:00:00 2001 From: Paul Weidner Date: Sun, 26 Feb 2023 22:27:25 -0800 Subject: [PATCH 1/2] Include transform and transformExtent methods #171 --- CHANGELOG.md | 4 ++++ src/instance/instance.js | 3 +++ src/instance/methods/projection.js | 2 ++ 3 files changed, 9 insertions(+) create mode 100644 src/instance/methods/projection.js diff --git a/CHANGELOG.md b/CHANGELOG.md index db5689f..5aa9ce7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Include transform and transformExtent OL methods. #171 + ## [v2.1.0] - 2022-11-15 ### Added diff --git a/src/instance/instance.js b/src/instance/instance.js index 11c90b1..eda45bd 100644 --- a/src/instance/instance.js +++ b/src/instance/instance.js @@ -8,6 +8,7 @@ import defaults from './defaults'; // Import instance methods. import addLayer, { getLayerByName } from './methods/layer'; import addPopup from './methods/popup'; +import { transform, transformExtent } from './methods/projection'; import { zoomToVectors, zoomToLayer } from './methods/zoom'; import { addBehavior, attachBehavior, attachBehaviorsByWeight } from './methods/behavior'; import { measureGeometry } from '../utils/measure'; @@ -57,6 +58,8 @@ const createInstance = ({ target, options = {} }) => { attachBehavior, attachBehaviorsByWeight, measureGeometry, + transform, + transformExtent, }; return instance; diff --git a/src/instance/methods/projection.js b/src/instance/methods/projection.js new file mode 100644 index 0000000..27d8993 --- /dev/null +++ b/src/instance/methods/projection.js @@ -0,0 +1,2 @@ +// Export OpenLayers transform functions +export { transform, transformExtent } from 'ol/proj'; \ No newline at end of file From c68a0c4a50cf7b191492ef2a4c50c1c8ea86d016 Mon Sep 17 00:00:00 2001 From: Paul Weidner Date: Sun, 26 Feb 2023 22:56:29 -0800 Subject: [PATCH 2/2] Add getCurrentViewExtentCoordinates instance function #171 --- CHANGELOG.md | 1 + src/instance/instance.js | 3 ++- src/instance/methods/projection.js | 17 ++++++++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5aa9ce7..e933d76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Include transform and transformExtent OL methods. #171 +- Add getCurrentViewExtentCoordinates instance function. #171 ## [v2.1.0] - 2022-11-15 diff --git a/src/instance/instance.js b/src/instance/instance.js index eda45bd..418585e 100644 --- a/src/instance/instance.js +++ b/src/instance/instance.js @@ -8,7 +8,7 @@ import defaults from './defaults'; // Import instance methods. import addLayer, { getLayerByName } from './methods/layer'; import addPopup from './methods/popup'; -import { transform, transformExtent } from './methods/projection'; +import { getCurrentViewExtentCoordinates, transform, transformExtent } from './methods/projection'; import { zoomToVectors, zoomToLayer } from './methods/zoom'; import { addBehavior, attachBehavior, attachBehaviorsByWeight } from './methods/behavior'; import { measureGeometry } from '../utils/measure'; @@ -58,6 +58,7 @@ const createInstance = ({ target, options = {} }) => { attachBehavior, attachBehaviorsByWeight, measureGeometry, + getCurrentViewExtentCoordinates, transform, transformExtent, }; diff --git a/src/instance/methods/projection.js b/src/instance/methods/projection.js index 27d8993..e7c225a 100644 --- a/src/instance/methods/projection.js +++ b/src/instance/methods/projection.js @@ -1,2 +1,17 @@ +import { transformExtent } from 'ol/proj'; + // Export OpenLayers transform functions -export { transform, transformExtent } from 'ol/proj'; \ No newline at end of file +export { transform, transformExtent } from 'ol/proj'; + +/** + * Returns the map's current view extent in the specified projection coordinates. + * @param {import('ol/proj').ProjectionLike} source Source projection-like. + * Defaults to 'EPSG:3857'. + * @param {import('ol/proj').ProjectionLike} destination Destination projection-like. + * Defaults to 'EPSG:4326'. + * @return {import('ol/extent').Extent} The transformed extent. + */ +export function getCurrentViewExtentCoordinates(source = 'EPSG:3857', destination = 'EPSG:4326') { + const extent = this.map.getView().calculateExtent(this.map.getSize()); + return transformExtent(extent, source, destination); +}