@@ -7,12 +7,51 @@ 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 GeoJSON from 'ol/format/GeoJSON' ;
1213import * as olSize from 'ol/size' ;
1314import * as olTilegrid from 'ol/tilegrid' ;
1415import TileGrid from 'ol/tilegrid/TileGrid' ;
1516
17+ function getOverflowTileCount ( overflowTiles ) {
18+ return Math . max ( 0 , Math . floor ( Number ( overflowTiles ) || 0 ) ) ;
19+ }
20+
21+ function wrapTileGridWithOverflow ( tileGrid , overflowTiles ) {
22+ const overflowTileCount = getOverflowTileCount ( overflowTiles ) ;
23+ if ( ! tileGrid || ! overflowTileCount ) {
24+ return tileGrid ;
25+ }
26+
27+ const wrappedTileGrid = Object . create ( tileGrid ) ;
28+ wrappedTileGrid . overflowTiles = overflowTileCount ;
29+ wrappedTileGrid . getTileRangeForExtentAndZ = function ( extent , z , tempTileRange ) {
30+ const tileRange = tileGrid . getTileRangeForExtentAndZ ( extent , z , tempTileRange ) ;
31+ if ( ! tileRange ) {
32+ return tileRange ;
33+ }
34+ tileRange . minX -= overflowTileCount ;
35+ tileRange . maxX += overflowTileCount ;
36+ tileRange . minY -= overflowTileCount ;
37+ tileRange . maxY += overflowTileCount ;
38+ return tileRange ;
39+ } ;
40+ wrappedTileGrid . getFullTileRange = function ( z ) {
41+ const tileRange = tileGrid . getFullTileRange ? tileGrid . getFullTileRange ( z ) : null ;
42+ if ( ! tileRange ) {
43+ return tileRange ;
44+ }
45+ return new TileRange (
46+ tileRange . minX - overflowTileCount ,
47+ tileRange . maxX + overflowTileCount ,
48+ tileRange . minY - overflowTileCount ,
49+ tileRange . maxY + overflowTileCount
50+ ) ;
51+ } ;
52+ return wrappedTileGrid ;
53+ }
54+
1655/**
1756 * @class TileSuperMapRest
1857 * @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 {ChartSetting } [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,14 +98,15 @@ 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 : tileUrlFunction ,
64105 wrapX : options . wrapX !== undefined ? options . wrapX : false ,
65106 cacheEnabled : options . cacheEnabled ,
66107 layersID : options . layersID
67108 } ) ;
109+ options . tileGrid = tileGrid ;
68110 if ( options . tileProxy ) {
69111 this . tileProxy = options . tileProxy ;
70112 }
@@ -166,22 +208,28 @@ export class TileSuperMapRest extends TileImage {
166208 function tileUrlFunction ( tileCoord , pixelRatio , projection ) {
167209 if ( ! me . tileGrid ) {
168210 if ( options . extent ) {
169- me . tileGrid = TileSuperMapRest . createTileGrid ( options . extent ) ;
211+ me . tileGrid = wrapTileGridWithOverflow ( TileSuperMapRest . createTileGrid ( options . extent ) , options . overflowTiles ) ;
170212 if ( me . resolutions ) {
171213 me . tileGrid . resolutions = me . resolutions ;
172214 }
173215 } else {
174216 if ( projection . getCode ( ) === 'EPSG:3857' ) {
175- me . tileGrid = TileSuperMapRest . createTileGrid ( [
176- - 20037508.3427892 ,
177- - 20037508.3427892 ,
178- 20037508.3427892 ,
179- 20037508.3427892
180- ] ) ;
217+ me . tileGrid = wrapTileGridWithOverflow (
218+ TileSuperMapRest . createTileGrid ( [
219+ - 20037508.3427892 ,
220+ - 20037508.3427892 ,
221+ 20037508.3427892 ,
222+ 20037508.3427892
223+ ] ) ,
224+ options . overflowTiles
225+ ) ;
181226 me . extent = [ - 20037508.3427892 , - 20037508.3427892 , 20037508.3427892 , 20037508.3427892 ] ;
182227 }
183228 if ( projection . getCode ( ) === 'EPSG:4326' ) {
184- me . tileGrid = TileSuperMapRest . createTileGrid ( [ - 180 , - 90 , 180 , 90 ] ) ;
229+ me . tileGrid = wrapTileGridWithOverflow (
230+ TileSuperMapRest . createTileGrid ( [ - 180 , - 90 , 180 , 90 ] ) ,
231+ options . overflowTiles
232+ ) ;
185233 me . extent = [ - 180 , - 90 , 180 , 90 ] ;
186234 }
187235 }
0 commit comments