Skip to content

Commit

Permalink
Merge pull request openlayers#3073 from ahocevar/load-tile-options
Browse files Browse the repository at this point in the history
Make map's deviceOptions map options
  • Loading branch information
ahocevar committed Dec 23, 2014
2 parents 78ac65e + 38b12d3 commit 97afb31
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 51 deletions.
3 changes: 3 additions & 0 deletions examples/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ var map = new ol.Map({
})
],
renderer: exampleNS.getRendererFromQueryString(),
// Improve user experience by loading tiles while animating. Will make
// animations stutter on mobile or slow devices.
loadTilesWhileAnimating: true,
target: 'map',
controls: ol.control.defaults({
attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
Expand Down
3 changes: 3 additions & 0 deletions examples/bing-maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ for (i = 0, ii = styles.length; i < ii; ++i) {
var map = new ol.Map({
layers: layers,
renderer: exampleNS.getRendererFromQueryString(),
// Improve user experience by loading tiles while dragging/zooming. Will make
// zooming choppy on mobile or slow devices.
loadTilesWhileInteracting: true,
target: 'map',
view: new ol.View({
center: [-6655.5402445057125, 6709968.258934638],
Expand Down
57 changes: 22 additions & 35 deletions externs/olx.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,6 @@ olx.AttributionOptions;
olx.AttributionOptions.prototype.html;


/**
* @typedef {{loadTilesWhileAnimating: (boolean|undefined),
* loadTilesWhileInteracting: (boolean|undefined)}}
* @api
*/
olx.DeviceOptions;


/**
* When set to false, no tiles will be loaded while animating, which improves
* responsiveness on devices with slow memory. Default is `true`.
* @type {boolean|undefined}
* @api
*/
olx.DeviceOptions.prototype.loadTilesWhileAnimating;


/**
* When set to false, no tiles will be loaded while interacting, which improves
* responsiveness on devices with slow memory. Default is `true`.
* @type {boolean|undefined}
* @api
*/
olx.DeviceOptions.prototype.loadTilesWhileInteracting;


/**
* @typedef {{tracking: (boolean|undefined)}}
* @api
Expand Down Expand Up @@ -194,11 +168,12 @@ olx.interaction.InteractionOptions.prototype.handleEvent;
/**
* Object literal with config options for the map.
* @typedef {{controls: (ol.Collection.<ol.control.Control>|Array.<ol.control.Control>|undefined),
* deviceOptions: (olx.DeviceOptions|undefined),
* pixelRatio: (number|undefined),
* interactions: (ol.Collection.<ol.interaction.Interaction>|Array.<ol.interaction.Interaction>|undefined),
* keyboardEventTarget: (Element|Document|string|undefined),
* layers: (Array.<ol.layer.Base>|ol.Collection.<ol.layer.Base>|undefined),
* loadTilesWhileAnimating: (boolean|undefined),
* loadTilesWhileInteracting: (boolean|undefined),
* logo: (boolean|string|olx.LogoOptions|undefined),
* overlays: (ol.Collection.<ol.Overlay>|Array.<ol.Overlay>|undefined),
* renderer: (ol.RendererType|Array.<ol.RendererType|string>|string|undefined),
Expand All @@ -218,14 +193,6 @@ olx.MapOptions;
olx.MapOptions.prototype.controls;


/**
* Device options for the map.
* @type {olx.DeviceOptions|undefined}
* @api
*/
olx.MapOptions.prototype.deviceOptions;


/**
* The ratio between physical pixels and device-independent pixels (dips) on the
* device. If `undefined` then it gets set by using `window.devicePixelRatio`.
Expand Down Expand Up @@ -266,6 +233,26 @@ olx.MapOptions.prototype.keyboardEventTarget;
olx.MapOptions.prototype.layers;


/**
* When set to true, tiles will be loaded during animations. This may improve
* the user experience, but can also make animations stutter on devices with
* slow memory. Default is `false`.
* @type {boolean|undefined}
* @api
*/
olx.MapOptions.prototype.loadTilesWhileAnimating;


/**
* When set to true, tiles will be loaded while interacting with the map. This
* may improve the user experience, but can also make map panning and zooming
* choppy on devices with slow memory. Default is `false`.
* @type {boolean|undefined}
* @api
*/
olx.MapOptions.prototype.loadTilesWhileInteracting;


/**
* The map logo. A logo to be displayed on the map at all times. If a string is
* provided, it will be set as the image source of the logo. If an object is
Expand Down
35 changes: 19 additions & 16 deletions src/ol/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,21 @@ ol.Map = function(options) {

var optionsInternal = ol.Map.createOptionsInternal(options);

/**
* @type {boolean}
* @private
*/
this.loadTilesWhileAnimating_ = goog.isDef(options.loadTilesWhileAnimating) ?
options.loadTilesWhileAnimating : false;

/**
* @type {boolean}
* @private
*/
this.loadTilesWhileInteracting_ =
goog.isDef(options.loadTilesWhileInteracting) ?
options.loadTilesWhileInteracting : false;

/**
* @private
* @type {number}
Expand Down Expand Up @@ -302,12 +317,6 @@ ol.Map = function(options) {
*/
this.controls_ = optionsInternal.controls;

/**
* @type {olx.DeviceOptions}
* @private
*/
this.deviceOptions_ = optionsInternal.deviceOptions;

/**
* @type {ol.Collection.<ol.interaction.Interaction>}
* @private
Expand Down Expand Up @@ -915,15 +924,14 @@ ol.Map.prototype.handlePostRender = function() {
var tileSourceCount = 0;
if (!goog.isNull(frameState)) {
var hints = frameState.viewHints;
var deviceOptions = this.deviceOptions_;
if (hints[ol.ViewHint.ANIMATING]) {
maxTotalLoading = deviceOptions.loadTilesWhileAnimating === false ?
0 : 8;
maxTotalLoading = this.loadTilesWhileAnimating_ === true ?
8 : 0;
maxNewLoads = 2;
}
if (hints[ol.ViewHint.INTERACTING]) {
maxTotalLoading = deviceOptions.loadTilesWhileInteracting === false ?
0 : 8;
maxTotalLoading = this.loadTilesWhileInteracting_ === true ?
8 : 0;
maxNewLoads = 2;
}
tileSourceCount = goog.object.getCount(frameState.wantedTiles);
Expand Down Expand Up @@ -1397,7 +1405,6 @@ ol.Map.prototype.unskipFeature = function(feature) {

/**
* @typedef {{controls: ol.Collection.<ol.control.Control>,
* deviceOptions: olx.DeviceOptions,
* interactions: ol.Collection.<ol.interaction.Interaction>,
* keyboardEventTarget: (Element|Document),
* logos: Object,
Expand Down Expand Up @@ -1511,9 +1518,6 @@ ol.Map.createOptionsInternal = function(options) {
controls = ol.control.defaults();
}

var deviceOptions = goog.isDef(options.deviceOptions) ?
options.deviceOptions : /** @type {olx.DeviceOptions} */ ({});

var interactions;
if (goog.isDef(options.interactions)) {
if (goog.isArray(options.interactions)) {
Expand All @@ -1540,7 +1544,6 @@ ol.Map.createOptionsInternal = function(options) {

return {
controls: controls,
deviceOptions: deviceOptions,
interactions: interactions,
keyboardEventTarget: keyboardEventTarget,
logos: logos,
Expand Down

0 comments on commit 97afb31

Please sign in to comment.