Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 55eb979

Browse files
【feature】创建地图时优化zoomBase计算方法; mapboxstyle 底图显隐优化;review by songym
1 parent 00f722f commit 55eb979

File tree

4 files changed

+454
-15
lines changed

4 files changed

+454
-15
lines changed

‎src/common/mapping/WebMapService.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ export class WebMapService {
225225
let bounds;
226226
let restResourceURL = '';
227227
let kvpResourceUrl = '';
228+
const scales = [];
228229
const proxy = this.handleProxy();
229230
let serviceUrl = Util.urlAppend(layerInfo.url, 'REQUEST=GetCapabilities&SERVICE=WMTS&VERSION=1.0.0');
230231
serviceUrl = this.handleParentRes(serviceUrl);
@@ -297,6 +298,7 @@ export class WebMapService {
297298
const tileMatrix = tileMatrixSet[i].TileMatrix[j];
298299
const identifier = tileMatrix['ows:Identifier'];
299300
const topLeftCorner = [...tileMatrix['TopLeftCorner'].split(' ')];
301+
scales.push(tileMatrix['ScaleDenominator']);
300302
if (
301303
(!this.numberEqual(topLeftCorner[0], defaultCRSTopLeftCorner[0]) ||
302304
!this.numberEqual(topLeftCorner[1], defaultCRSTopLeftCorner[1])) &&
@@ -365,7 +367,7 @@ export class WebMapService {
365367
restResourceURL = resourceUrl['@_template'];
366368
}
367369
}
368-
resolve({ isMatched, matchMaxZoom, matchMinZoom, style, bounds, restResourceURL, kvpResourceUrl });
370+
resolve({ isMatched, matchMaxZoom, matchMinZoom, style, bounds, restResourceURL, kvpResourceUrl, scales });
369371
})
370372
.catch(error => {
371373
reject(error);

‎src/common/mapping/WebMapV2.js

Lines changed: 79 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
114114
this._handleLayerInfo(mapInfo, _taskID);
115115
} else {
116116
setTimeout(() => {
117-
this._createMap(mapInfo);
118-
this.map.on('load', () => {
119-
this._handleLayerInfo(mapInfo, _taskID);
117+
this._createMap(mapInfo).then(() => {
118+
this.map.on('load', () => {
119+
this._handleLayerInfo(mapInfo, _taskID);
120+
});
120121
});
121122
}, 0);
122123
}
@@ -236,7 +237,78 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
236237
return true;
237238
}
238239

239-
_createMap(mapInfo) {
240+
async _getScales(mapInfo) {
241+
const baseLayerInfo = mapInfo.baseLayer;
242+
const scales = [];
243+
let coordUnit = baseLayerInfo.coordUnit || baseLayerInfo.units || mapRepo.CRS.get(this.baseProjection).unit;
244+
if (!coordUnit) {
245+
coordUnit = this.baseProjection == 'EPSG:3857' ? 'm' : 'degree';
246+
}
247+
let visibleScales = null;
248+
if (baseLayerInfo.layerType === 'TILE') {
249+
try {
250+
const reqOptions = {
251+
withoutFormatSuffix: true,
252+
withCredentials: this.webMapService.handleWithCredentials('', baseLayerInfo.url, false)
253+
};
254+
const res = await this.getBounds(`${baseLayerInfo.url}.json`, reqOptions)
255+
if (res && res.visibleScales) {
256+
visibleScales = res.visibleScales;
257+
}
258+
} catch (error) {
259+
console.error(error);
260+
}
261+
}
262+
if (visibleScales && visibleScales.length > 0) {
263+
//底部设置过固定比例尺,则使用设置的
264+
visibleScales.forEach((scale) => {
265+
const value = 1 / scale;
266+
scales.push(`1:${value}`);
267+
});
268+
} else if (baseLayerInfo.layerType === 'WMTS') {
269+
try {
270+
const result = await this.webMapService.getWmtsInfo(baseLayerInfo, this.baseProjection);
271+
result.scales.forEach((scale) => {
272+
scales.push(`1:${scale}`);
273+
});
274+
} catch (error) {
275+
console.error(error);
276+
}
277+
} else if (baseLayerInfo.layerType === 'ZXY_TILE') {
278+
const { resolutions: visibleResolution } = baseLayerInfo;
279+
visibleResolution.forEach((result) => {
280+
const currentScale = '1:' + Util.getScaleFromResolution(result, coordUnit);
281+
scales.push(currentScale);
282+
});
283+
} else {
284+
const extent = baseLayerInfo.layerType === 'MAPBOXSTYLE' ? mapRepo.CRS.get(this.baseProjection).extent : mapInfo.extent;
285+
const resolutions = this._getResolutionsByExtent({
286+
extent: this._transExtentToBounds(extent),
287+
tileSize: 512
288+
});
289+
for (const res of resolutions) {
290+
const scale = '1:' + Util.getScaleFromResolution(res, coordUnit);
291+
if (scales.indexOf(scale) === -1) {
292+
scales.push(scale);
293+
}
294+
}
295+
}
296+
return scales;
297+
}
298+
299+
_transExtentToBounds(extent) {
300+
if (extent instanceof Array) {
301+
return extent;
302+
}
303+
return [
304+
extent.leftBottom.x,
305+
extent.leftBottom.y,
306+
extent.rightTop.x,
307+
extent.rightTop.y
308+
];
309+
}
310+
311+
async _createMap(mapInfo) {
240312
// 获取字体样式
241313
const fontFamilys = this._getLabelFontFamily(mapInfo);
242314
const center = this._getMapCenter(mapInfo);
@@ -247,10 +319,6 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
247319
const interactive = this.mapOptions.interactive;
248320
const tileSize = mapInfo.baseLayer.tileSize;
249321

250-
if (mapInfo.baseLayer.layerType === 'ZXY_TILE') {
251-
const {leftBottom, rightTop} = mapInfo.extent;
252-
mapInfo.visibleExtent = [leftBottom.x, leftBottom.y, rightTop.x, rightTop.y];
253-
}
254322
if (isNaN(minZoom)) {
255323
minZoom = mapInfo.minScale
256324
? this._transformScaleToZoom(mapInfo.minScale, mapRepo.CRS.get(this.baseProjection), tileSize)
@@ -272,8 +340,9 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
272340
}
273341
if (!bounds) {
274342
if (mapInfo.minScale && mapInfo.maxScale) {
343+
const scales = await this._getScales(mapInfo);
275344
zoomBase = Math.min(
276-
this._transformScaleToZoom(mapInfo.minScale, mapRepo.CRS.get(this.baseProjection), tileSize),
345+
this._transformScaleToZoom(scales[0]||mapInfo.minScale, mapRepo.CRS.get(this.baseProjection), tileSize),
277346
this._transformScaleToZoom(mapInfo.maxScale, mapRepo.CRS.get(this.baseProjection), tileSize)
278347
);
279348
} else {
@@ -294,7 +363,6 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
294363
maxZoom,
295364
bearing: this.bearing || 0,
296365
pitch: this.pitch || 0,
297-
bounds,
298366
interactive: interactive === void 0 ? true : interactive,
299367
style: {
300368
version: 8,
@@ -3127,7 +3195,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
31273195
}
31283196

31293197
_getVisibility(visible) {
3130-
const visibility = visible === true || visible === 'visible' ? 'visible' : 'none';
3198+
const visibility = visible === false || visible === 'none' ? 'none' : 'visible';
31313199
return visibility;
31323200
}
31333201

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /