Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide methods to transform coordinates and extents #189

Open
wants to merge 2 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Include transform and transformExtent OL methods. #171
- Add getCurrentViewExtentCoordinates instance function. #171

## [v2.1.0] - 2022-11-15

### Added
Expand Down
4 changes: 4 additions & 0 deletions src/instance/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import defaults from './defaults';
// Import instance methods.
import addLayer, { getLayerByName } from './methods/layer';
import addPopup from './methods/popup';
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 @@ -57,6 +58,9 @@ const createInstance = ({ target, options = {} }) => {
attachBehavior,
attachBehaviorsByWeight,
measureGeometry,
getCurrentViewExtentCoordinates,
transform,
transformExtent,
};

return instance;
Expand Down
17 changes: 17 additions & 0 deletions src/instance/methods/projection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { transformExtent } from 'ol/proj';

// Export OpenLayers transform functions
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);
}