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

Method getMapLayerExtent

src/openlayers/mapping/WebMap.js:4957–5014  ·  view source on GitHub ↗

* @private * @function WebMap.prototype.getMapLayerExtent * @description 获取mapboxstyle图层信息 * @param {Object} layerInfo 图层信息 * @returns {Object} 图层信息

(layerInfo)

Source from the content-addressed store, hash-verified

4955 * @returns {Object} 图层信息
4956 */
4957 getMapLayerExtent(layerInfo) {
4958 const restMapMVTStr = '/tileFeature/vectorstyles.json?type=MapBox_GL&styleonly=true&tileURLTemplate=ZXY';
4959 let dataSource = layerInfo.dataSource;
4960 let url = dataSource.url;
4961 if (this.isRestMapMapboxStyle(layerInfo)) {
4962 url = url.replace(restMapMVTStr, '');
4963 url = this.getRequestUrl(url + '.json');
4964 }
4965 if (url.indexOf('/restjsr/') > -1 && !/\.json$/.test(url)) {
4966 url = this.getRequestUrl(url + '.json');
4967 } else {
4968 url = this.getRequestUrl(url);
4969 }
4970
4971 let credential = layerInfo.credential;
4972 let credentialValue, keyfix;
4973 //携带令牌(restmap用的首字母大写,但是这里要用小写)
4974 if (credential) {
4975 keyfix = Object.keys(credential)[0];
4976 credentialValue = credential[keyfix];
4977 url = `${url}?${keyfix}=${credentialValue}`;
4978 }
4979
4980 return FetchRequest.get(url, null, {
4981 withCredentials: this.isCredentail(url),
4982 withoutFormatSuffix: true,
4983 headers: {
4984 'Content-Type': 'application/json;chartset=uft-8'
4985 }
4986 })
4987 .then(function (response) {
4988 return response.json();
4989 })
4990 .then((result) => {
4991 layerInfo.visibleScales = result.visibleScales;
4992 layerInfo.coordUnit = result.coordUnit || 'METER';
4993 layerInfo.scale = result.scale;
4994 layerInfo.epsgCode = (result.prjCoordSys && result.prjCoordSys.epsgCode) || '3857';
4995 layerInfo.bounds = result.bounds || {
4996 top: 20037508.342789244,
4997 left: -20037508.342789244,
4998 bottom: -20037508.342789244,
4999 leftBottom: {
5000 x: -20037508.342789244,
5001 y: -20037508.342789244
5002 },
5003 right: 20037508.342789244,
5004 rightTop: {
5005 x: 20037508.342789244,
5006 y: 20037508.342789244
5007 }
5008 };
5009 return layerInfo;
5010 })
5011 .catch((error) => {
5012 throw error;
5013 });
5014 }

Callers 1

Calls 5

isRestMapMapboxStyleMethod · 0.95
getRequestUrlMethod · 0.95
isCredentailMethod · 0.95
indexOfMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected