Skip to content

Commit

Permalink
Add getCurrentViewExtentCoordinates instance function farmOS#171
Browse files Browse the repository at this point in the history
  • Loading branch information
paul121 committed Feb 27, 2023
1 parent d3b616b commit c68a0c4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion src/instance/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -58,6 +58,7 @@ const createInstance = ({ target, options = {} }) => {
attachBehavior,
attachBehaviorsByWeight,
measureGeometry,
getCurrentViewExtentCoordinates,
transform,
transformExtent,
};
Expand Down
17 changes: 16 additions & 1 deletion src/instance/methods/projection.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
import { transformExtent } from 'ol/proj';

// Export OpenLayers transform functions
export { transform, transformExtent } from 'ol/proj';
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);
}

0 comments on commit c68a0c4

Please sign in to comment.