• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jumpinjackie / mapguide-react-layout / 15160437878

21 May 2025 11:00AM UTC coverage: 21.631% (-42.6%) from 64.24%
15160437878

Pull #1552

github

web-flow
Merge 8b7153d9e into 236e2ea07
Pull Request #1552: Feature/package updates 2505

839 of 1165 branches covered (72.02%)

11 of 151 new or added lines in 25 files covered. (7.28%)

1332 existing lines in 50 files now uncovered.

4794 of 22163 relevant lines covered (21.63%)

6.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/api/registry/projections.ts
1
import proj4 from "proj4";
×
2
import { MgError } from '../error';
×
3
import { tr } from '../i18n';
×
4
import { strIsNullOrEmpty } from '../../utils/string';
×
5
import { register } from 'ol/proj/proj4';
×
6
import { debug } from '../../utils/logger';
×
7

8
/**
9
 * Performs a projection definititon lookup for the given EPSG code
10
 *
11
 * @export
12
 * @param {string | number} epsg
13
 * @param {string} locale
14
 * @param {string} mapDef
15
 * @returns {Promise<any>}
16
 * @since 0.13
17
 * @since 0.14.10 - Renamed to resolveProjectionFromEpsgCodeAsync from resolveProjectionFromEpsgIoAsync as this no longer hits epsg.io
18
 */
NEW
19
export async function resolveProjectionFromEpsgCodeAsync(epsg: string | number, locale: string, mapDef: string): Promise<any> {
×
NEW
20
    const r = await fetch(`https://spatialreference.org/ref/epsg/${epsg}/proj4.txt`);
×
NEW
21
    if (r.ok) {
×
NEW
22
        const defn = await r.text();
×
NEW
23
        proj4.defs(`EPSG:${epsg}`, defn);
×
NEW
24
        debug(`Registered projection EPSG:${epsg} from spatialreference.org`);
×
25
        return proj4.defs[`EPSG:${epsg}`];
×
26
    } else {
×
27
        throw new MgError(tr("INIT_ERROR_UNREGISTERED_EPSG_CODE", locale, { epsg: epsg, mapDefinition: mapDef }));
×
28
    }
×
29
}
×
30

31
/**
32
 * Ensures the given projection (by EPSG code) exists and if not invokes the given factory function (or does an epsg lookup)
33
 * to fetch the definition to be registered.
34
 * 
35
 * Once registered, it will update the projection set within OpenLayers
36
 * 
37
 * @export
38
 * @param {number} epsgCode
39
 * @param {() => Promise<string>} [factoryIfNotFound] A custom factory function to provide the required proj4js string for this projection. If not specified, an external epsg lookup will be done instead
40
 * @param {string} alias
41
 * @returns {Promise<string>}
42
 * @since 0.13
43
 */
44
export async function ensureProjection(epsgCode: number, locale: string, alias?: string, factoryIfNotFound?: () => Promise<string>): Promise<[number, string]> {
×
45
    let resolvedName: string;
×
46
    let bAdded = false;
×
47
    const name = `EPSG:${epsgCode}`;
×
48
    if (proj4.defs[name]) {
×
49
        resolvedName = name;
×
50
    } else {
×
51
        if (factoryIfNotFound) {
×
52
            proj4.defs[name] = factoryIfNotFound();
×
53
            bAdded = true;
×
54
            resolvedName = name;
×
55
        } else {
×
NEW
56
            await resolveProjectionFromEpsgCodeAsync(epsgCode, locale, "");
×
57
            resolvedName = name;
×
58
        }
×
59
    }
×
60
    //Register the alias if specified
61
    if (!strIsNullOrEmpty(alias) && !proj4.defs[alias]) {
×
62
        proj4.defs[alias] = proj4.defs[resolvedName];
×
63
        bAdded = true;
×
64
    }
×
65
    //Need to call re-register if proj4.defs got changed so OL can pick it up
66
    if (bAdded) {
×
67
        register(proj4);
×
68
    }
×
69
    return [epsgCode, resolvedName];
×
70
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc