Skip to content

Commit e8376d1

Browse files
committed
fea: RestMap栅格图层支持设置overflowTiles参数,解决出图不完整的缺陷
(reviewed by sym)
1 parent 7c151da commit e8376d1

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

‎src/openlayers/mapping/WebMap.js‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ const WMTS_ARRAY_NODE_PATHS = [
111111
* @param {function} [options.mapSetting.controls] - 地图的控件。
112112
* @param {function} [options.mapSetting.interactions] - 地图控制的参数。
113113
* @param {number} [options.restDataSingleRequestCount=1000] - 自定义 restData 分批请求,单次请求数量。
114+
* @param {number} [options.overflowTiles=0] - RestMap 栅格图层瓦片范围向外扩大的圈数。
114115
* @extends {ol.Observable}
115116
* @usage
116117
*/
@@ -142,6 +143,7 @@ export class WebMap extends Observable {
142143
this.webMap = options.webMap;
143144
this.tileFormat = options.tileFormat && options.tileFormat.toLowerCase();
144145
this.restDataSingleRequestCount = options.restDataSingleRequestCount || 1000;
146+
this.overflowTiles = typeof options.overflowTiles === 'undefined' ? 1 : options.overflowTiles;
145147
this.tileRequestParameters = options.tileRequestParameters;
146148
this.createMap(options.mapSetting);
147149
if (this.webMap) {
@@ -1314,6 +1316,10 @@ export class WebMap extends Observable {
13141316
) {
13151317
options.tileProxy = this.server + 'apps/viewer/getUrlResource.png?url=';
13161318
}
1319+
if(this.overflowTiles) {
1320+
options.overflowTiles = this.overflowTiles;
1321+
layerInfo.restMapExtentExpanded = true;
1322+
}
13171323
let source = new TileSuperMapRest(options);
13181324
SecurityManager[`register${keyfix}`](layerInfo.url);
13191325
return source;
@@ -1401,7 +1407,11 @@ export class WebMap extends Observable {
14011407
getLayerOtherOptions(layerInfo) {
14021408
const { layerType, extent, minZoom, maxZoom } = layerInfo;
14031409
const extentVal = layerType === 'ZXY_TILE' ? this._getZXYTileMapBounds(layerInfo) : extent;
1404-
const options = { extent: extentVal };
1410+
const options = {};
1411+
if (!layerInfo.restMapExtentExpanded) {
1412+
// 扩大 RestMap 栅格图层的 tileGrid 后,不再向图层传递 extent
1413+
options.extent = extentVal;
1414+
}
14051415
if (typeof minZoom === 'number' && minZoom !== 0) {
14061416
options.minZoom = minZoom - 1;
14071417
}

‎test/openlayers/mapping/WebMapSpec.js‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2611,4 +2611,45 @@ describe('openlayers_WebMap', () => {
26112611
done();
26122612
}
26132613
});
2614+
it('overflowTiles_default_value', () => {
2615+
const webmap = new WebMap(id, { server: server });
2616+
expect(webmap.overflowTiles).toBe(1);
2617+
});
2618+
2619+
it('overflowTiles_custom_value', () => {
2620+
const webmap = new WebMap(id, { server: server, overflowTiles: 0 });
2621+
expect(webmap.overflowTiles).toBe(0);
2622+
2623+
const webmap2 = new WebMap(id, { server: server, overflowTiles: 2 });
2624+
expect(webmap2.overflowTiles).toBe(2);
2625+
});
2626+
2627+
it('createDynamicTiledSource_sets_overflowTiles_option_when_overflowTiles_has_value', () => {
2628+
const webmap = new WebMap(id, { server: server, overflowTiles: 2 });
2629+
// Need to set baseProjection before calling createDynamicTiledSource
2630+
webmap.baseProjection = 'EPSG:4326';
2631+
const layerInfo = {
2632+
url: 'http://example.com/map',
2633+
extent: [0, 0, 100, 100]
2634+
};
2635+
// Since SecurityManager.register is called dynamically, we just need to ensure it doesn't throw
2636+
const source = webmap.createDynamicTiledSource(layerInfo, true);
2637+
// Check that the options includes overflowTiles
2638+
expect(source.options.overflowTiles).toBe(2);
2639+
expect(layerInfo.restMapExtentExpanded).toBe(true);
2640+
});
2641+
2642+
it('createDynamicTiledSource_does_not_set_overflowTiles_option_when_overflowTiles_is_zero', () => {
2643+
const webmap = new WebMap(id, { server: server, overflowTiles: 0 });
2644+
// Need to set baseProjection before calling createDynamicTiledSource
2645+
webmap.baseProjection = 'EPSG:4326';
2646+
const layerInfo = {
2647+
url: 'http://example.com/map',
2648+
extent: [0, 0, 100, 100]
2649+
};
2650+
const source = webmap.createDynamicTiledSource(layerInfo, true);
2651+
// Check that overflowTiles is not set in the options when it's 0
2652+
expect(source.options.overflowTiles).toBeUndefined();
2653+
expect(layerInfo.restMapExtentExpanded).toBeUndefined();
2654+
});
26142655
});

0 commit comments

Comments
 (0)