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