Skip to content

Commit b28c4f1

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

2 files changed

Lines changed: 53 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: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,4 +2232,46 @@ describe('openlayers_WebMap', () => {
22322232
done();
22332233
}
22342234
});
2235+
2236+
it('overflowTiles_default_value', () => {
2237+
const webmap = new WebMap(id, { server: server });
2238+
expect(webmap.overflowTiles).toBe(1);
2239+
});
2240+
2241+
it('overflowTiles_custom_value', () => {
2242+
const webmap = new WebMap(id, { server: server, overflowTiles: 0 });
2243+
expect(webmap.overflowTiles).toBe(0);
2244+
2245+
const webmap2 = new WebMap(id, { server: server, overflowTiles: 2 });
2246+
expect(webmap2.overflowTiles).toBe(2);
2247+
});
2248+
2249+
it('createDynamicTiledSource_sets_overflowTiles_option_when_overflowTiles_has_value', () => {
2250+
const webmap = new WebMap(id, { server: server, overflowTiles: 2 });
2251+
// Need to set baseProjection before calling createDynamicTiledSource
2252+
webmap.baseProjection = 'EPSG:4326';
2253+
const layerInfo = {
2254+
url: 'http://example.com/map',
2255+
extent: [0, 0, 100, 100]
2256+
};
2257+
// Since SecurityManager.register is called dynamically, we just need to ensure it doesn't throw
2258+
const source = webmap.createDynamicTiledSource(layerInfo, true);
2259+
// Check that the options includes overflowTiles
2260+
expect(source.options.overflowTiles).toBe(2);
2261+
expect(layerInfo.restMapExtentExpanded).toBe(true);
2262+
});
2263+
2264+
it('createDynamicTiledSource_does_not_set_overflowTiles_option_when_overflowTiles_is_zero', () => {
2265+
const webmap = new WebMap(id, { server: server, overflowTiles: 0 });
2266+
// Need to set baseProjection before calling createDynamicTiledSource
2267+
webmap.baseProjection = 'EPSG:4326';
2268+
const layerInfo = {
2269+
url: 'http://example.com/map',
2270+
extent: [0, 0, 100, 100]
2271+
};
2272+
const source = webmap.createDynamicTiledSource(layerInfo, true);
2273+
// Check that overflowTiles is not set in the options when it's 0
2274+
expect(source.options.overflowTiles).toBeUndefined();
2275+
expect(layerInfo.restMapExtentExpanded).toBeUndefined();
2276+
});
22352277
});

0 commit comments

Comments
 (0)