@@ -7,11 +7,50 @@ import { Util as CommonUtil } from '@supermapgis/iclient-common/commontypes/Util
77import { ServerGeometry } from '@supermapgis/iclient-common/iServer/ServerGeometry' ;
88import { Util } from '../core/Util' ;
99import TileImage from 'ol/source/TileImage' ;
10+ import TileRange from 'ol/TileRange' ;
1011import Geometry from 'ol/geom/Geometry' ;
1112import * as olSize from 'ol/size' ;
1213import * as olTilegrid from 'ol/tilegrid' ;
1314import TileGrid from 'ol/tilegrid/TileGrid' ;
1415
16+ function getOverflowTileCount ( overflowTiles ) {
17+ return Math . max ( 0 , Math . floor ( Number ( overflowTiles ) || 0 ) ) ;
18+ }
19+
20+ function wrapTileGridWithOverflow ( tileGrid , overflowTiles ) {
21+ const overflowTileCount = getOverflowTileCount ( overflowTiles ) ;
22+ if ( ! tileGrid || ! overflowTileCount ) {
23+ return tileGrid ;
24+ }
25+
26+ const wrappedTileGrid = Object . create ( tileGrid ) ;
27+ wrappedTileGrid . overflowTiles = overflowTileCount ;
28+ wrappedTileGrid . getTileRangeForExtentAndZ = function ( extent , z , tempTileRange ) {
29+ const tileRange = tileGrid . getTileRangeForExtentAndZ ( extent , z , tempTileRange ) ;
30+ if ( ! tileRange ) {
31+ return tileRange ;
32+ }
33+ tileRange . minX -= overflowTileCount ;
34+ tileRange . maxX += overflowTileCount ;
35+ tileRange . minY -= overflowTileCount ;
36+ tileRange . maxY += overflowTileCount ;
37+ return tileRange ;
38+ } ;
39+ wrappedTileGrid . getFullTileRange = function ( z ) {
40+ const tileRange = tileGrid . getFullTileRange ? tileGrid . getFullTileRange ( z ) : null ;
41+ if ( ! tileRange ) {
42+ return tileRange ;
43+ }
44+ return new TileRange (
45+ tileRange . minX - overflowTileCount ,
46+ tileRange . maxX + overflowTileCount ,
47+ tileRange . minY - overflowTileCount ,
48+ tileRange . maxY + overflowTileCount
49+ ) ;
50+ } ;
51+ return wrappedTileGrid ;
52+ }
53+
1554/**
1655 * @class TileSuperMapRest
1756 * @browsernamespace ol.source
@@ -36,6 +75,7 @@ import TileGrid from 'ol/tilegrid/TileGrid';
3675 * @param {string } [options.format = 'png'] - 瓦片表述类型,支持 "png" 、"webp"、"bmp" 、"jpg"、"gif" 等图片类型。
3776 * @param {(NDVIParameter|HillshadeParameter) } [options.rasterfunction] - 栅格分析参数。
3877 * @param {ChartSettingS57|ChartSettingS100 } [options.chartSetting] - 海图显示参数设置类,用于管理海图显示环境,包括海图的显示模式、显示类型名称、颜色模式、安全水深线等各种显示风格。
78+ * @param {number } [options.overflowTiles = 0] - 在当前视口范围外额外渲染的瓦片圈数。为 1 时上下左右各多请求一圈瓦片,可用于缓解符号在图层范围边缘被裁切的问题。
3979 * @extends {ol.source.TileImage }
4080 * @usage
4181 */
@@ -46,6 +86,7 @@ export class TileSuperMapRest extends TileImage {
4686 options . attributions || 'Map Data <span>© SuperMap iServer</span> with <span>© SuperMap iClient</span>' ;
4787
4888 options . format = options . format ? options . format : 'png' ;
89+ const tileGrid = wrapTileGridWithOverflow ( options . tileGrid , options . overflowTiles ) ;
4990
5091 super ( {
5192 attributions : options . attributions ,
@@ -57,7 +98,7 @@ export class TileSuperMapRest extends TileImage {
5798 reprojectionErrorThreshold : options . reprojectionErrorThreshold ,
5899 state : options . state ,
59100 tileClass : options . tileClass ,
60- tileGrid : options . tileGrid ,
101+ tileGrid : tileGrid ,
61102 tileLoadFunction : options . tileLoadFunction ,
62103 tilePixelRatio : options . tilePixelRatio ,
63104 tileUrlFunction : options . tileUrlFunction || tileUrlFunction ,
@@ -68,6 +109,7 @@ export class TileSuperMapRest extends TileImage {
68109 if ( options . tileProxy ) {
69110 this . tileProxy = options . tileProxy ;
70111 }
112+ options . tileGrid = tileGrid ;
71113 this . options = options ;
72114 //当前切片在切片集中的index
73115 this . tileSetsIndex = - 1 ;
@@ -218,19 +260,25 @@ export class TileSuperMapRest extends TileImage {
218260 function tileUrlFunction ( tileCoord , pixelRatio , projection ) {
219261 if ( ! me . tileGrid ) {
220262 if ( options . extent ) {
221- me . tileGrid = TileSuperMapRest . createTileGrid ( options . extent ) ;
263+ me . tileGrid = wrapTileGridWithOverflow ( TileSuperMapRest . createTileGrid ( options . extent ) , options . overflowTiles ) ;
222264 if ( me . resolutions ) {
223265 me . tileGrid . resolutions = me . resolutions ;
224266 }
225267 } else {
226268 if ( projection . getCode ( ) === 'EPSG:3857' ) {
227- me . tileGrid = TileSuperMapRest . createTileGrid ( [
228- - 20037508.3427892 , - 20037508.3427892 , 20037508.3427892 , 20037508.3427892
229- ] ) ;
269+ me . tileGrid = wrapTileGridWithOverflow (
270+ TileSuperMapRest . createTileGrid ( [
271+ - 20037508.3427892 , - 20037508.3427892 , 20037508.3427892 , 20037508.3427892
272+ ] ) ,
273+ options . overflowTiles
274+ ) ;
230275 me . extent = [ - 20037508.3427892 , - 20037508.3427892 , 20037508.3427892 , 20037508.3427892 ] ;
231276 }
232277 if ( projection . getCode ( ) === 'EPSG:4326' ) {
233- me . tileGrid = TileSuperMapRest . createTileGrid ( [ - 180 , - 90 , 180 , 90 ] ) ;
278+ me . tileGrid = wrapTileGridWithOverflow (
279+ TileSuperMapRest . createTileGrid ( [ - 180 , - 90 , 180 , 90 ] ) ,
280+ options . overflowTiles
281+ ) ;
234282 me . extent = [ - 180 , - 90 , 180 , 90 ] ;
235283 }
236284 }
0 commit comments