@@ -6,8 +6,8 @@ import { Unit } from '@supermapgis/iclient-common/REST';
6
6
import { Util as CommonUtil } from '@supermapgis/iclient-common/commontypes/Util' ;
7
7
import { ServerGeometry } from '@supermapgis/iclient-common/iServer/ServerGeometry' ;
8
8
import { 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' ;
11
11
import Geometry from 'ol/geom/Geometry' ;
12
12
import GeoJSON from 'ol/format/GeoJSON' ;
13
13
import { containsExtent , getCenter , getHeight , getWidth , getForViewAndSize } from 'ol/extent' ;
@@ -42,12 +42,23 @@ import { containsExtent, getCenter, getHeight, getWidth, getForViewAndSize } fro
42
42
* @param {string } [options.tileProxy] - 代理地址。
43
43
* @param {NDVIParameter|HillshadeParameter } [options.rasterfunction] - 栅格分析参数。
44
44
* @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;};
46
46
* @param {string } [options.ratio=1.5] - 请求图片大小比例。 1 表示请求图片大小和地图视窗范围一致,2 表示请求图片大小是地图视窗范围的2倍,以此类推。
47
47
* @extends {ol.source.Image }
48
48
* @usage
49
49
*/
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 {
51
62
constructor ( options ) {
52
63
super ( {
53
64
attributions : options . attributions ,
@@ -150,7 +161,8 @@ import { containsExtent, getCenter, getHeight, getWidth, getForViewAndSize } fro
150
161
this . tileProxy = options . tileProxy ;
151
162
}
152
163
}
153
- getImageInternal ( extent , resolution , pixelRatio ) {
164
+
165
+ _getImageInternalParams ( extent , resolution , pixelRatio ) {
154
166
resolution = this . findNearestResolution ( resolution ) ;
155
167
const imageResolution = resolution / pixelRatio ;
156
168
const center = getCenter ( extent ) ;
@@ -160,6 +172,19 @@ import { containsExtent, getCenter, getHeight, getWidth, getForViewAndSize } fro
160
172
const requestWidth = Math . ceil ( ( this . ratio_ * getWidth ( extent ) ) / imageResolution ) ;
161
173
const requestHeight = Math . ceil ( ( this . ratio_ * getHeight ( extent ) ) / imageResolution ) ;
162
174
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
+ ) ;
163
188
const image = this . _image ;
164
189
if (
165
190
image &&
@@ -170,23 +195,54 @@ import { containsExtent, getCenter, getHeight, getWidth, getForViewAndSize } fro
170
195
) {
171
196
return image ;
172
197
}
173
- const imageSize = [
174
- Math . round ( getWidth ( requestExtent ) / imageResolution ) ,
175
- Math . round ( getHeight ( requestExtent ) / imageResolution )
176
- ] ;
177
- const imageUrl = this . _getRequestUrl ( requestExtent , imageSize ) ;
178
198
this . _image = new ImageWrapper (
179
199
requestExtent ,
180
200
resolution ,
181
201
pixelRatio ,
182
- imageUrl ,
202
+ src ,
183
203
this . _crossOrigin ,
184
204
this . imageLoadFunction_
185
205
) ;
186
206
this . renderedRevision_ = this . getRevision ( ) ;
187
207
this . _image . addEventListener ( 'change' , this . handleImageChange . bind ( this ) ) ;
188
208
return this . _image ;
189
209
}
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
+ }
190
246
_getRequestUrl ( extent , imageSize ) {
191
247
const params = {
192
248
width : imageSize [ 0 ] ,
0 commit comments