Skip to content

Commit

Permalink
Better returns for proj registration
Browse files Browse the repository at this point in the history
  • Loading branch information
ger-benjamin committed Sep 23, 2024
1 parent 47f701f commit fce9742
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
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]);
}
}

0 comments on commit fce9742

Please sign in to comment.