MCPcopy Create free account
hub / github.com/SuperMap/iClient-JavaScript / _registerMapCRS

Method _registerMapCRS

src/common/mapping/WebMapV2.js:126–184  ·  view source on GitHub ↗
(mapInfo)

Source from the content-addressed store, hash-verified

124 }
125
126 async _registerMapCRS(mapInfo) {
127 const { projection, extent = { leftBottom: {}, rightTop: {} }, baseLayer = {} } = mapInfo;
128 const epsgCode = toEpsgCode(projection);
129 let crs = {
130 name: epsgCode,
131 extent: [extent.leftBottom.x, extent.leftBottom.y, extent.rightTop.x, extent.rightTop.y],
132 wkt: this._getProjectionWKT(projection)
133 };
134 if (!crsManager.getCRS(epsgCode)) {
135 switch (baseLayer.layerType) {
136 case 'MAPBOXSTYLE': {
137 let url = baseLayer.dataSource.url;
138 if (url.indexOf('/restjsr/') > -1 && !/\/style\.json$/.test(url)) {
139 url = Util.urlPathAppend(url, '/style.json');
140 }
141 const res = await this.webMapService.getMapBoxStyle(url);
142 if (res && res.metadata && res.metadata.indexbounds) {
143 crs.extent = res.metadata.indexbounds;
144 }
145 break;
146 }
147 case 'TILE': {
148 // 获取地图的wkt
149 if (!crs.wkt) {
150 crs.wkt = await this.getEpsgCodeWKT(Util.urlPathAppend(baseLayer.url, '/prjCoordSys.wkt'), {
151 withoutFormatSuffix: true,
152 withCredentials: this.webMapService.handleWithCredentials('', baseLayer.url, false)
153 });
154 }
155 const boundsRes = await this.getBounds(`${baseLayer.url}.json`, {
156 withoutFormatSuffix: true,
157 withCredentials: this.webMapService.handleWithCredentials('', baseLayer.url, false)
158 });
159 if (boundsRes && boundsRes.bounds) {
160 crs.extent = [
161 boundsRes.bounds.leftBottom.x,
162 boundsRes.bounds.leftBottom.y,
163 boundsRes.bounds.rightTop.x,
164 boundsRes.bounds.rightTop.y
165 ];
166 }
167 break;
168 }
169 case 'ZXY_TILE': {
170 const extent = this._getZXYTileCrsExtent(baseLayer);
171 crs.extent = extent;
172 break;
173 }
174 default:
175 crs = null;
176 break;
177 }
178 }
179 if (!crs) {
180 throw new Error('Unsupported coordinate system!')
181 }
182 crsManager.registerCRS(crs);
183 return epsgCode;

Callers 1

initializeMapMethod · 0.95

Calls 10

_getProjectionWKTMethod · 0.95
getEpsgCodeWKTMethod · 0.95
getBoundsMethod · 0.95
_getZXYTileCrsExtentMethod · 0.95
toEpsgCodeFunction · 0.90
indexOfMethod · 0.80
getMapBoxStyleMethod · 0.80
handleWithCredentialsMethod · 0.80
getCRSMethod · 0.45
registerCRSMethod · 0.45

Tested by

no test coverage detected