@@ -6,8 +6,8 @@ import { Unit } from '@supermapgis/iclient-common/REST';
66import { Util as CommonUtil } from '@supermapgis/iclient-common/commontypes/Util' ;
77import { ServerGeometry } from '@supermapgis/iclient-common/iServer/ServerGeometry' ;
88import { Util } from '../core/Util' ;
9- import ImageSource , { defaultImageLoadFunction } from 'ol/source/Image' ;
10- import ImageWrapper from 'ol/Image' ;
9+ import ImageSource from 'ol/source/Image' ;
10+ import ImageWrapper , { decode } from 'ol/Image' ;
1111import Geometry from 'ol/geom/Geometry' ;
1212import GeoJSON from 'ol/format/GeoJSON' ;
1313import { containsExtent , getCenter , getHeight , getWidth , getForViewAndSize } from 'ol/extent' ;
@@ -42,12 +42,23 @@ import { containsExtent, getCenter, getHeight, getWidth, getForViewAndSize } fro
4242 * @param {string } [options.tileProxy] - 代理地址。
4343 * @param {NDVIParameter|HillshadeParameter } [options.rasterfunction] - 栅格分析参数。
4444 * @param {string } [options.format = 'png'] - 瓦片表述类型,支持 "png" 、"webp"、"bmp" 、"jpg"、"gif" 等图片类型。
45- * @param {Function } [options.imageLoadFunction] - 加载图片的方法。默认为function(imageTile, src) {imageTile.getImage().src = src;};
45+ * @deprecated {Function} [options.imageLoadFunction] - 加载图片的方法。默认为function(imageTile, src) {imageTile.getImage().src = src;};
4646 * @param {string } [options.ratio=1.5] - 请求图片大小比例。 1 表示请求图片大小和地图视窗范围一致,2 表示请求图片大小是地图视窗范围的2倍,以此类推。
4747 * @extends {ol.source.Image }
4848 * @usage
4949 */
50- export class ImageSuperMapRest extends ImageSource {
50+
51+ function defaultImageLoadFunction ( image , src ) {
52+ image . getImage ( ) . src = src ;
53+ }
54+
55+ function fromResolutionLike ( resolution ) {
56+ if ( Array . isArray ( resolution ) ) {
57+ return Math . min ( ...resolution ) ;
58+ }
59+ return resolution ;
60+ }
61+ export class ImageSuperMapRest extends ImageSource {
5162 constructor ( options ) {
5263 super ( {
5364 attributions : options . attributions ,
@@ -150,7 +161,8 @@ import { containsExtent, getCenter, getHeight, getWidth, getForViewAndSize } fro
150161 this . tileProxy = options . tileProxy ;
151162 }
152163 }
153- getImageInternal ( extent , resolution , pixelRatio ) {
164+
165+ _getImageInternalParams ( extent , resolution , pixelRatio ) {
154166 resolution = this . findNearestResolution ( resolution ) ;
155167 const imageResolution = resolution / pixelRatio ;
156168 const center = getCenter ( extent ) ;
@@ -160,6 +172,19 @@ import { containsExtent, getCenter, getHeight, getWidth, getForViewAndSize } fro
160172 const requestWidth = Math . ceil ( ( this . ratio_ * getWidth ( extent ) ) / imageResolution ) ;
161173 const requestHeight = Math . ceil ( ( this . ratio_ * getHeight ( extent ) ) / imageResolution ) ;
162174 const requestExtent = getForViewAndSize ( center , imageResolution , 0 , [ requestWidth , requestHeight ] ) ;
175+ const imageSize = [
176+ Math . round ( getWidth ( requestExtent ) / imageResolution ) ,
177+ Math . round ( getHeight ( requestExtent ) / imageResolution )
178+ ] ;
179+ const src = this . _getRequestUrl ( requestExtent , imageSize ) ;
180+ return { imageSize, src, requestExtent, resolution, viewExtent } ;
181+ }
182+ _getImageInternalBy8 ( extent , resolutionVal , pixelRatio ) {
183+ const { src, resolution, requestExtent, viewExtent } = this . _getImageInternalParams (
184+ extent ,
185+ resolutionVal ,
186+ pixelRatio
187+ ) ;
163188 const image = this . _image ;
164189 if (
165190 image &&
@@ -170,23 +195,54 @@ import { containsExtent, getCenter, getHeight, getWidth, getForViewAndSize } fro
170195 ) {
171196 return image ;
172197 }
173- const imageSize = [
174- Math . round ( getWidth ( requestExtent ) / imageResolution ) ,
175- Math . round ( getHeight ( requestExtent ) / imageResolution )
176- ] ;
177- const imageUrl = this . _getRequestUrl ( requestExtent , imageSize ) ;
178198 this . _image = new ImageWrapper (
179199 requestExtent ,
180200 resolution ,
181201 pixelRatio ,
182- imageUrl ,
202+ src ,
183203 this . _crossOrigin ,
184204 this . imageLoadFunction_
185205 ) ;
186206 this . renderedRevision_ = this . getRevision ( ) ;
187207 this . _image . addEventListener ( 'change' , this . handleImageChange . bind ( this ) ) ;
188208 return this . _image ;
189209 }
210+
211+ _getImageInternal ( extent , resolutionVal , pixelRatio ) {
212+ const { src, resolution, requestExtent } = this . _getImageInternalParams ( extent , resolutionVal , pixelRatio ) ;
213+ if ( this . image ) {
214+ if (
215+ ( ( this . wantedExtent_ && containsExtent ( this . wantedExtent_ , requestExtent ) ) ||
216+ containsExtent ( this . image . getExtent ( ) , requestExtent ) ) &&
217+ ( ( this . wantedResolution_ && fromResolutionLike ( this . wantedResolution_ ) === resolution ) ||
218+ fromResolutionLike ( this . image . getResolution ( ) ) === resolution )
219+ ) {
220+ return this . image ;
221+ }
222+ }
223+ this . wantedExtent_ = requestExtent ;
224+ this . wantedResolution_ = resolution ;
225+ this . loader = this . createLoader ( { src, crossOrigin : this . _crossOrigin } ) ;
226+ this . image = new ImageWrapper ( requestExtent , resolution , pixelRatio , this . loader ) ;
227+ this . image . addEventListener ( 'change' , this . handleImageChange . bind ( this ) ) ;
228+ return this . image ;
229+ }
230+
231+ createLoader ( { src, crossOrigin } ) {
232+ const loadCallback = decode ;
233+ return ( extent , resolution , pixelRatio ) => {
234+ const image = new Image ( ) ;
235+ image . crossOrigin = crossOrigin ?? null ;
236+ return loadCallback ( image , src ) . then ( ( image ) => ( { image, extent, pixelRatio } ) ) ;
237+ } ;
238+ }
239+
240+ getImageInternal ( extent , resolutionVal , pixelRatio ) {
241+ if ( Number ( Util . getOlVersion ( ) ) < 8 ) {
242+ return this . _getImageInternalBy8 ( extent , resolutionVal , pixelRatio ) ;
243+ }
244+ return this . _getImageInternal ( extent , resolutionVal , pixelRatio ) ;
245+ }
190246 _getRequestUrl ( extent , imageSize ) {
191247 const params = {
192248 width : imageSize [ 0 ] ,
0 commit comments