(url, options = {})
| 35 | * ``` |
| 36 | * */ |
| 37 | export 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 |
no test coverage detected