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

Function createMapOptions

src/mapboxgl/mapping/InitMap.js:162–273  ·  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

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

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