Skip to content

Commit ff4b5a5

Browse files
committed
【feature】1) webmap,对接geoserver的wmts服务
2)修复缺陷小范围+其他范围的地图。在dv中分享不可拖动地图
1 parent 2850833 commit ff4b5a5

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

src/openlayers/mapping/WebMap.js

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,7 @@ export class WebMap extends Observable {
489489
this.map.addLayer(layer);
490490

491491
if(this.mapParams) {
492-
let extent = [mapInfo.extent.leftBottom.x, mapInfo.extent.leftBottom.y, mapInfo.extent.rightTop.x, mapInfo.extent.rightTop.y];
493-
this.mapParams.extent = extent;
492+
this.mapParams.extent = baseLayer.extent;
494493
this.mapParams.projection = mapInfo.projection;
495494
}
496495
if (mapInfo.baseLayer && mapInfo.baseLayer.labelLayerVisible) {
@@ -592,15 +591,17 @@ export class WebMap extends Observable {
592591
}
593592
}else {
594593
if(this.resolutionArray && this.resolutionArray.length > 0) {
595-
viewOptions = { zoom, center, projection, extent, resolutions: this.resolutionArray, maxZoom};
594+
viewOptions = { zoom, center, projection, resolutions: this.resolutionArray, maxZoom};
596595
} else {
597-
viewOptions = {zoom, center, projection, extent, maxResolution, minResolution, maxZoom};
596+
viewOptions = {zoom, center, projection, maxResolution, minResolution, maxZoom};
598597
this.getScales(baseLayer);
599598
}
600599
}
601600
if(!['4', '5'].includes(Util.getOlVersion())){ // 兼容 ol 4,5,6
602601
viewOptions.multiWorld = true;
603602
viewOptions.showFullExtent = true;
603+
viewOptions.enableRotation = false;
604+
viewOptions.constrainResolution = true; //设置此参数,是因为需要显示整数级别。为了可视比例尺中包含当前比例尺
604605
}
605606
this.map.setView(new View(viewOptions));
606607
if (options.visibleExtent) {
@@ -884,12 +885,16 @@ export class WebMap extends Observable {
884885
prjCoordSys:{ epsgCode: isBaseLayer ? layerInfo.projection.split(':')[1] : this.baseProjection.split(':')[1] }
885886
};
886887
if(layerInfo.visibleScales && layerInfo.visibleScales.length >0){
887-
let result = this.getReslutionsFromScales(layerInfo.visibleScales, 96, layerInfo.coordUnit);
888+
let visibleResolutions = [];
889+
for(let i in layerInfo.visibleScales){
890+
let resolution = Util.scaleToResolution(layerInfo.visibleScales[i], dpiConfig.default, layerInfo.coordUnit);
891+
visibleResolutions.push(resolution);
892+
}
893+
layerInfo.visibleResolutions = visibleResolutions;
888894
let tileGrid = new TileGrid({
889895
extent: layerInfo.extent,
890-
resolutions: result.res
896+
resolutions: visibleResolutions
891897
});
892-
layerInfo.visibleResolutions = result.res;
893898
options.tileGrid = tileGrid;
894899
}else{
895900
options.extent = this.baseLayerExtent;
@@ -1118,7 +1123,7 @@ export class WebMap extends Observable {
11181123
getWmtsInfo(layerInfo, callback, mapInfo) {
11191124
let that = this;
11201125
let options = {
1121-
withCredentials: false,
1126+
withCredentials: true,
11221127
withoutFormatSuffix: true
11231128
};
11241129
return FetchRequest.get(that.getRequestUrl(layerInfo.url), null, options).then(function (response) {
@@ -1131,7 +1136,7 @@ export class WebMap extends Observable {
11311136
tileMatrixSet = content.TileMatrixSet,
11321137
layers = content.Layer,
11331138
layer, relSet = [],
1134-
idx, layerFormat;
1139+
idx, layerFormat, style = 'default';
11351140

11361141
for (let n = 0; n < layers.length; n++) {
11371142
if (layers[n].Title === layerInfo.name) {
@@ -1143,6 +1148,11 @@ export class WebMap extends Observable {
11431148
break;
11441149
}
11451150
}
1151+
layer && layer.Style && layer.Style.forEach(value => {
1152+
if(value.isDefault) {
1153+
style = value.Identifier;
1154+
}
1155+
});
11461156
let scales = [], matrixIds = [];
11471157
for (let i = 0; i < tileMatrixSet.length; i++) {
11481158
if (tileMatrixSet[i].Identifier === layerInfo.tileMatrixSet) {
@@ -1164,18 +1174,17 @@ export class WebMap extends Observable {
11641174
} else {
11651175
extent = olProj.get(that.baseProjection).getExtent()
11661176
}
1167-
const isKvp = layerInfo.requestEncoding === 'KVP';
1177+
const isKvp = !layerInfo.requestEncoding || layerInfo.requestEncoding === 'KVP';
11681178
layerInfo.tileUrl = that.getTileUrl(capabilities.OperationsMetadata.GetTile.DCP.HTTP.Get, isKvp, layerInfo.layer, layerInfo.tileMatrixSet);
11691179
//将需要的参数补上
11701180
layerInfo.dpi = 90.7;
11711181
layerInfo.extent = extent;
1172-
layerInfo.format = "image/png";
11731182
layerInfo.matrixSet = matrixSet;
11741183
layerInfo.name = name;
11751184
layerInfo.orginEpsgCode = layerInfo.projection;
11761185
layerInfo.overLayer = true;
11771186
layerInfo.scales = scales;
1178-
layerInfo.style = "default";
1187+
layerInfo.style = style;
11791188
layerInfo.title = name;
11801189
layerInfo.unit = "m";
11811190
layerInfo.layerFormat = layerFormat;
@@ -1231,6 +1240,7 @@ export class WebMap extends Observable {
12311240
url: layerInfo.tileUrl || layerInfo.url,
12321241
layer: layerInfo.layer,
12331242
format: layerInfo.layerFormat,
1243+
style: layerInfo.style,
12341244
matrixSet: layerInfo.tileMatrixSet,
12351245
requestEncoding: layerInfo.requestEncoding || 'KVP',
12361246
tileGrid: this.getWMTSTileGrid(extent, layerInfo.scales, unit, layerInfo.dpi, layerInfo.origin, layerInfo.matrixIds),
@@ -1280,8 +1290,10 @@ export class WebMap extends Observable {
12801290
//给个默认的
12811291
if (Util.isArray(scales)) {
12821292
scales && scales.forEach(function (scale, idx) {
1283-
matrixIds.push(idx);
1284-
res.push(this.getResolutionFromScale(scale, dpi, unit, datumAxis));
1293+
if(scale > 1.0) {
1294+
matrixIds.push(idx);
1295+
res.push(this.getResolutionFromScale(scale, dpi, unit, datumAxis));
1296+
}
12851297
}, this);
12861298
} else {
12871299
let tileMatrixSet = scales['TileMatrix'];
@@ -1306,7 +1318,7 @@ export class WebMap extends Observable {
13061318
* @param {number} datumAxis
13071319
* @returns {{res: Array, matrixIds: Array}}
13081320
*/
1309-
getResolutionFromScale(scale, dpi, unit, datumAxis) {
1321+
getResolutionFromScale(scale, dpi=dpiConfig.default, unit, datumAxis) {
13101322
//radio = 10000;
13111323
let res;
13121324
scale = +scale;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy