(url, options = {})
| 42 | * ``` |
| 43 | * */ |
| 44 | export async function initMap(url, options = {}) { |
| 45 | const { mapOptions, viewOptions, layerOptions, sourceOptions } = options; |
| 46 | const initMapService = new InitMapServiceBase(MapService, url, options); |
| 47 | const tilesets = await initMapService.getTilesets(); |
| 48 | const result = await initMapService.getMapInfo(); |
| 49 | if (!result || !result.result) { |
| 50 | return 'service is not work!'; |
| 51 | } |
| 52 | const mapObject = result.result; |
| 53 | const { prjCoordSys, bounds, center, visibleScales, coordUnit, scale, dpi } = mapObject; |
| 54 | // tileset和地图不同投影,优先使用地图 |
| 55 | const tileset = getTileset(tilesets.result, { prjCoordSys, tileType: 'Image' }); |
| 56 | |
| 57 | const config = { |
| 58 | center, |
| 59 | bounds, |
| 60 | dpi, |
| 61 | visibleScales, |
| 62 | scale, |
| 63 | prjCoordSys, |
| 64 | coordUnit, |
| 65 | tileFormat: 'webp', |
| 66 | tileSize: 256 |
| 67 | }; |
| 68 | if (tileset) { |
| 69 | config.tileFormat = getTileFormat(tileset); |
| 70 | config.tileSize = tileset.tileWidth || 256; |
| 71 | config.transparent = tileset.transparent || true; |
| 72 | config.origin = [tileset.originalPoint.x, tileset.originalPoint.y]; |
| 73 | config.resolutions = tileset.resolutions; |
| 74 | config.scaleDenominators = tileset.scaleDenominators; |
| 75 | config.dpi = Util.getDpi(1.0 / tileset.scaleDenominators[0], tileset.resolutions[0], coordUnit); |
| 76 | } |
| 77 | |
| 78 | if (!get(`EPSG:${prjCoordSys.epsgCode}`) && !isPlaneProjection(prjCoordSys.type)) { |
| 79 | const wkt = await initMapService.getWKT(); |
| 80 | registerProj(prjCoordSys.epsgCode, wkt, bounds); |
| 81 | } |
| 82 | |
| 83 | let map = createMap(config, mapOptions, viewOptions); |
| 84 | let { layer, source } = createLayer(url, config, sourceOptions, layerOptions); |
| 85 | map.addLayer(layer); |
| 86 | return { |
| 87 | map, |
| 88 | source, |
| 89 | layer |
| 90 | }; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @function viewOptionsFromMapJSON |
nothing calls this directly
no test coverage detected