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

Better returns for proj registration #9480

Merged
merged 1 commit into from
Sep 23, 2024
Merged
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
7 changes: 3 additions & 4 deletions src/proj/EPSG_2056.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import create from 'ngeo/proj/utils';
import {createProjection} from 'ngeo/proj/utils';

export const code = 'EPSG:2056';

Expand All @@ -37,8 +37,7 @@ const def = [
];
const extent = [2420000, 1030000, 2900000, 1350000];

const projections = {};
projections[code] = {'definition': def, 'extent': extent};
export const proj = create(projections);
const projection = {'definition': def, 'extent': extent};
export const proj = createProjection(code, projection);

export default code;
7 changes: 3 additions & 4 deletions src/proj/EPSG_21781.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import create from 'ngeo/proj/utils';
import {createProjection} from 'ngeo/proj/utils';

export const code = 'EPSG:21781';

Expand All @@ -37,8 +37,7 @@ const def = [
];
const extent = [420000, 30000, 900000, 350000];

const projections = {};
projections[code] = {'definition': def, 'extent': extent};
export const proj = create(projections);
const projection = {'definition': def, 'extent': extent};
export const proj = createProjection(code, projection);

export default code;
36 changes: 22 additions & 14 deletions src/proj/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,33 @@
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import {get as getProjection, add as addProjection} from 'ol/proj';
import {get as getProjection} from 'ol/proj';
import {register} from 'ol/proj/proj4';
import proj4 from 'proj4';

/** @type {import('gmf/options').gmfProjectionsOptions} */
export default function createProjections(projections) {
for (const code in projections) {
proj4.defs(code, projections[code].definition.join(' ').trim());
const match = /^EPSG:(\d+)$/.exec(code);
if (match !== null) {
proj4.defs(
'http://www.opengis.net/gml/srs/epsg.xml#' + match[1], //NOSONAR
proj4.defs(code),
);
}
/**
* @type {string} the projection code.
* @type {import('gmf/options').Projection} the projection settings.
* @returns {import('ol/proj/Projection').default} the registered projection.
*/
export function createProjection(code, projection) {
proj4.defs(code, projection.definition.join(' ').trim());
const match = /^EPSG:(\d+)$/.exec(code);
if (match !== null) {
proj4.defs(
'http://www.opengis.net/gml/srs/epsg.xml#' + match[1], //NOSONAR
proj4.defs(code),
);
}
register(proj4);
const proj = getProjection(code);
proj.setExtent(projection.extent);
return proj;
}

/** @type {import('gmf/options').gmfProjectionsOptions} */
export default function createProjections(projections) {
for (const code in projections) {
const proj = getProjection(code);
proj.setExtent(projections[code].extent);
createProjection(code, projections[code]);
}
}
Loading