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

Function createMapOptions

src/maplibregl/mapping/InitMap.js:155–265  ·  view source on GitHub ↗

* @private * @function createMapOptions * @description 获取地图参数。 * @param {string} url - rest 地图服务地址。 * @param {Object} resetServiceInfo - rest 地图服务信息。 * @param {Object} [options] - 参数。 * @param {string} [options.type] - 服务代理地址。 * @param {Object} [options.mapOptions] - 地图配置。 * @param {Object}

(url, resetServiceInfo, options)

Source from the content-addressed store, hash-verified

153 * @returns {Object} mapParams。
154 */
155async function createMapOptions(url, resetServiceInfo, options) {
156 if (options.type && !['raster', 'vector-tile'].includes(options.type)) {
157 return Promise.reject(new Error('type must be "raster" or "vector-tile".'));
158 }
159 const sourceType = options.type || 'raster';
160 const mapOptions = options.mapOptions || {};
161 const {
162 prjCoordSys: { epsgCode },
163 bounds,
164 center,
165 dpi,
166 coordUnit,
167 scale
168 } = resetServiceInfo;
169 let mapCenter = center ? [center.x, center.y] : [0, 0];
170 let crs = `EPSG:${epsgCode}`;
171 let extent = bounds;
172 let tileUrl =
173 sourceType === 'vector-tile'
174 ? Util.urlAppend(Util.urlPathAppend(url, 'tileFeature/vectorstyles.json'), 'type=MapBox_GL&styleonly=true&tileURLTemplate=ZXY')
175 : url;
176 tileUrl = SecurityManager.appendCredential(tileUrl);
177 let nonEnhanceExtraInfo = {};
178 let enhanceExtraInfo = {};
179 let zoom;
180 let tileSize = 512;
181 let tileFormat = 'png';
182 if (maplibregl.CRS) {
183 const baseProjection = crs;
184 const wkt = await options.initMapService.getWKT();
185 let vectorTileInfo;
186 if (sourceType === 'vector-tile') {
187 vectorTileInfo = await getVectorTileCRSExtent(tileUrl, url);
188 extent = vectorTileInfo.extent;
189 }
190 crs = defineCRSByWKT(baseProjection, wkt, extent);
191 if (sourceType === 'raster') {
192 enhanceExtraInfo.rasterSource = 'iserver';
193 }
194 if (vectorTileInfo && vectorTileInfo.center) {
195 mapCenter = vectorTileInfo.center;
196 } else {
197 mapCenter = transformMapCenter(mapCenter, baseProjection);
198 }
199
200 const tilesets = await options.initMapService.getTilesets();
201 const tileset = getTileset(tilesets.result, { prjCoordSys: resetServiceInfo.prjCoordSys, tileType: 'Image' });
202
203 if (tileset) {
204 tileFormat = getTileFormat(tileset);
205 const maxWidth = Math.max(tileset.bounds.right - tileset.originalPoint.x, tileset.originalPoint.y - tileset.bounds.bottom);
206 const tileCount = maxWidth / (tileset.resolutions[0] * 256);
207 zoom = Math.ceil(Math.log2(tileCount));
208 const closestTileCount = Math.pow(2, zoom);
209 const width = closestTileCount * 256 * tileset.resolutions[0];
210 const crsBounds = [
211 tileset.originalPoint.x,
212 tileset.originalPoint.y - width,

Callers 1

initMapFunction · 0.70

Calls 10

getTilesetFunction · 0.90
getTileFormatFunction · 0.90
getZoomFunction · 0.90
appendCredentialMethod · 0.80
maxMethod · 0.80
getVectorTileCRSExtentFunction · 0.70
defineCRSByWKTFunction · 0.70
transformMapCenterFunction · 0.70
getWKTMethod · 0.45
getTilesetsMethod · 0.45

Tested by

no test coverage detected