MCPcopy Index your code
hub / github.com/SuperMap/iClient-JavaScript / initMap

Function initMap

src/mapboxgl/mapping/InitMap.js:37–74  ·  view source on GitHub ↗
(url, options = {})

Source from the content-addressed store, hash-verified

35 * ```
36 * */
37export function initMap(url, options = {}) {
38 const initMapService = new InitMapServiceBase(MapService, url, options);
39 return initMapService.getMapInfo(async (res, resolve, reject) => {
40 try {
41 if (res.type === 'processCompleted') {
42 const {
43 dynamicProjection,
44 prjCoordSys: { epsgCode, type }
45 } = res.result;
46 if (isPlaneProjection(type)) {
47 reject(new Error('mapbox-gl cannot support plane coordinate system.'));
48 return;
49 }
50 if (epsgCode !== 3857 && !dynamicProjection && !mapboxgl.CRS) {
51 reject(
52 new Error(
53 `The EPSG code ${epsgCode} needs to include mapbox-gl-enhance.js. Refer to the example: https://iclient.supermap.io/examples/mapboxgl/editor.html#mvtVectorTile_2362`
54 )
55 );
56 return;
57 }
58 const mapOptions = await createMapOptions(url, res.result, { ...options, initMapService });
59 const map = new mapboxgl.Map(mapOptions);
60 if (!map.loaded()) {
61 map.on('load', () => {
62 resolve({ map });
63 });
64 } else {
65 resolve({ map });
66 }
67 return;
68 }
69 reject(new Error('Fetch mapService is failed.'));
70 } catch (error) {
71 reject(error);
72 }
73 });
74}
75
76/**
77 * @private

Callers 3

InitMapSpec.jsFile · 0.90
InitMapSpec.jsFile · 0.90
InitMapSpec.jsFile · 0.90

Calls 4

getMapInfoMethod · 0.95
isPlaneProjectionFunction · 0.90
createMapOptionsFunction · 0.70
onMethod · 0.45

Tested by

no test coverage detected