@@ -18,6 +18,7 @@ define([
18
18
'../ThirdParty/when' ,
19
19
'./BingMapsStyle' ,
20
20
'./DiscardMissingTileImagePolicy' ,
21
+ './DiscardEmptyTileImagePolicy' ,
21
22
'./ImageryProvider'
22
23
] , function (
23
24
BingMapsApi ,
@@ -39,6 +40,7 @@ define([
39
40
when ,
40
41
BingMapsStyle ,
41
42
DiscardMissingTileImagePolicy ,
43
+ DiscardEmptyTilePolicy ,
42
44
ImageryProvider ) {
43
45
'use strict' ;
44
46
@@ -61,15 +63,16 @@ define([
61
63
* for information on the supported cultures.
62
64
* @param {Ellipsoid } [options.ellipsoid] The ellipsoid. If not specified, the WGS84 ellipsoid is used.
63
65
* @param {TileDiscardPolicy } [options.tileDiscardPolicy] The policy that determines if a tile
64
- * is invalid and should be discarded. If this value is not specified, a default
65
- * {@link DiscardMissingTileImagePolicy} is used which requests
66
- * tile 0,0 at the maximum tile level and checks pixels (0,0), (120,140), (130,160),
67
- * (200,50), and (200,200). If all of these pixels are transparent, the discard check is
68
- * disabled and no tiles are discarded. If any of them have a non-transparent color, any
69
- * tile that has the same values in these pixel locations is discarded. The end result of
70
- * these defaults should be correct tile discarding for a standard Bing Maps server. To ensure
71
- * that no tiles are discarded, construct and pass a {@link NeverTileDiscardPolicy} for this
72
- * parameter.
66
+ * is invalid and should be discarded. The default value will depend on the map style. If
67
+ * `BingMapsStyle.AERIAL_WITH_LABELS_ON_DEMAND` or `BingMapsStyle.ROADS_ON_DEMAND` is used, then a
68
+ * {@link DiscardEmptyTileImagePolicy} will be used to handle the Bing Maps API sending no content instead of
69
+ * a missing tile image, a behaviour specific to that imagery set. In all other cases, a default
70
+ * {@link DiscardMissingTileImagePolicy} is used which requests tile 0,0 at the maximum tile level and checks
71
+ * pixels (0,0), (120,140), (130,160), (200,50), and (200,200). If all of these pixels are transparent, the
72
+ * discard check is disabled and no tiles are discarded. If any of them have a non-transparent color, any
73
+ * tile that has the same values in these pixel locations is discarded. The end result of these defaults
74
+ * should be correct tile discarding for a standard Bing Maps server. To ensure that no tiles are discarded,
75
+ * construct and pass a {@link NeverTileDiscardPolicy} for this parameter.
73
76
*
74
77
* @see ArcGisMapServerImageryProvider
75
78
* @see GoogleEarthEnterpriseMapsProvider
@@ -171,11 +174,18 @@ define([
171
174
172
175
// Install the default tile discard policy if none has been supplied.
173
176
if ( ! defined ( that . _tileDiscardPolicy ) ) {
174
- that . _tileDiscardPolicy = new DiscardMissingTileImagePolicy ( {
175
- missingImageUrl : buildImageResource ( that , 0 , 0 , that . _maximumLevel ) . url ,
176
- pixelsToCheck : [ new Cartesian2 ( 0 , 0 ) , new Cartesian2 ( 120 , 140 ) , new Cartesian2 ( 130 , 160 ) , new Cartesian2 ( 200 , 50 ) , new Cartesian2 ( 200 , 200 ) ] ,
177
- disableCheckIfAllPixelsAreTransparent : true
178
- } ) ;
177
+ // Our default depends on which map style we're using.
178
+ if ( that . _mapStyle === BingMapsStyle . AERIAL_WITH_LABELS_ON_DEMAND
179
+ || that . _mapStyle === BingMapsStyle . ROAD_ON_DEMAND ) {
180
+ // this map style uses a different API, which returns a tile with no data instead of a placeholder image
181
+ that . _tileDiscardPolicy = new DiscardEmptyTilePolicy ( ) ;
182
+ } else {
183
+ that . _tileDiscardPolicy = new DiscardMissingTileImagePolicy ( {
184
+ missingImageUrl : buildImageResource ( that , 0 , 0 , that . _maximumLevel ) . url ,
185
+ pixelsToCheck : [ new Cartesian2 ( 0 , 0 ) , new Cartesian2 ( 120 , 140 ) , new Cartesian2 ( 130 , 160 ) , new Cartesian2 ( 200 , 50 ) , new Cartesian2 ( 200 , 200 ) ] ,
186
+ disableCheckIfAllPixelsAreTransparent : true
187
+ } ) ;
188
+ }
179
189
}
180
190
181
191
var attributionList = that . _attributionList = resource . imageryProviders ;
@@ -533,7 +543,23 @@ define([
533
543
}
534
544
//>>includeEnd('debug');
535
545
536
- return ImageryProvider . loadImage ( this , buildImageResource ( this , x , y , level , request ) ) ;
546
+ var promise = ImageryProvider . loadImage ( this , buildImageResource ( this , x , y , level , request ) ) ;
547
+
548
+ if ( defined ( promise ) ) {
549
+ return promise . otherwise ( function ( error ) {
550
+
551
+ // One possible cause of an error here is that the image we tried to load was empty. This isn't actually
552
+ // a problem. In some imagery sets (eg. `BingMapsStyle.AERIAL_WITH_LABELS_ON_DEMAND`), an empty image is
553
+ // returned rather than a blank "This Image is Missing" placeholder image. In this case, we supress the
554
+ // error.
555
+ if ( defined ( error . blob ) && error . blob . size === 0 ) {
556
+ return DiscardEmptyTilePolicy . EMPTY_IMAGE ;
557
+ }
558
+ return when . reject ( error ) ;
559
+ } ) ;
560
+ }
561
+
562
+ return undefined ;
537
563
} ;
538
564
539
565
/**
0 commit comments