Merge pull request #3073 from ahocevar/load-tile-options
Make map's deviceOptions map options
This commit is contained in:
@@ -55,6 +55,9 @@ var map = new ol.Map({
|
|||||||
})
|
})
|
||||||
],
|
],
|
||||||
renderer: exampleNS.getRendererFromQueryString(),
|
renderer: exampleNS.getRendererFromQueryString(),
|
||||||
|
// Improve user experience by loading tiles while animating. Will make
|
||||||
|
// animations stutter on mobile or slow devices.
|
||||||
|
loadTilesWhileAnimating: true,
|
||||||
target: 'map',
|
target: 'map',
|
||||||
controls: ol.control.defaults({
|
controls: ol.control.defaults({
|
||||||
attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
|
attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ for (i = 0, ii = styles.length; i < ii; ++i) {
|
|||||||
var map = new ol.Map({
|
var map = new ol.Map({
|
||||||
layers: layers,
|
layers: layers,
|
||||||
renderer: exampleNS.getRendererFromQueryString(),
|
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',
|
target: 'map',
|
||||||
view: new ol.View({
|
view: new ol.View({
|
||||||
center: [-6655.5402445057125, 6709968.258934638],
|
center: [-6655.5402445057125, 6709968.258934638],
|
||||||
|
|||||||
+22
-35
@@ -23,32 +23,6 @@ olx.AttributionOptions;
|
|||||||
olx.AttributionOptions.prototype.html;
|
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)}}
|
* @typedef {{tracking: (boolean|undefined)}}
|
||||||
* @api
|
* @api
|
||||||
@@ -194,11 +168,12 @@ olx.interaction.InteractionOptions.prototype.handleEvent;
|
|||||||
/**
|
/**
|
||||||
* Object literal with config options for the map.
|
* Object literal with config options for the map.
|
||||||
* @typedef {{controls: (ol.Collection.<ol.control.Control>|Array.<ol.control.Control>|undefined),
|
* @typedef {{controls: (ol.Collection.<ol.control.Control>|Array.<ol.control.Control>|undefined),
|
||||||
* deviceOptions: (olx.DeviceOptions|undefined),
|
|
||||||
* pixelRatio: (number|undefined),
|
* pixelRatio: (number|undefined),
|
||||||
* interactions: (ol.Collection.<ol.interaction.Interaction>|Array.<ol.interaction.Interaction>|undefined),
|
* interactions: (ol.Collection.<ol.interaction.Interaction>|Array.<ol.interaction.Interaction>|undefined),
|
||||||
* keyboardEventTarget: (Element|Document|string|undefined),
|
* keyboardEventTarget: (Element|Document|string|undefined),
|
||||||
* layers: (Array.<ol.layer.Base>|ol.Collection.<ol.layer.Base>|undefined),
|
* layers: (Array.<ol.layer.Base>|ol.Collection.<ol.layer.Base>|undefined),
|
||||||
|
* loadTilesWhileAnimating: (boolean|undefined),
|
||||||
|
* loadTilesWhileInteracting: (boolean|undefined),
|
||||||
* logo: (boolean|string|olx.LogoOptions|undefined),
|
* logo: (boolean|string|olx.LogoOptions|undefined),
|
||||||
* overlays: (ol.Collection.<ol.Overlay>|Array.<ol.Overlay>|undefined),
|
* overlays: (ol.Collection.<ol.Overlay>|Array.<ol.Overlay>|undefined),
|
||||||
* renderer: (ol.RendererType|Array.<ol.RendererType|string>|string|undefined),
|
* renderer: (ol.RendererType|Array.<ol.RendererType|string>|string|undefined),
|
||||||
@@ -218,14 +193,6 @@ olx.MapOptions;
|
|||||||
olx.MapOptions.prototype.controls;
|
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
|
* The ratio between physical pixels and device-independent pixels (dips) on the
|
||||||
* device. If `undefined` then it gets set by using `window.devicePixelRatio`.
|
* device. If `undefined` then it gets set by using `window.devicePixelRatio`.
|
||||||
@@ -266,6 +233,26 @@ olx.MapOptions.prototype.keyboardEventTarget;
|
|||||||
olx.MapOptions.prototype.layers;
|
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
|
* 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
|
* provided, it will be set as the image source of the logo. If an object is
|
||||||
|
|||||||
+19
-16
@@ -165,6 +165,21 @@ ol.Map = function(options) {
|
|||||||
|
|
||||||
var optionsInternal = ol.Map.createOptionsInternal(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
|
* @private
|
||||||
* @type {number}
|
* @type {number}
|
||||||
@@ -302,12 +317,6 @@ ol.Map = function(options) {
|
|||||||
*/
|
*/
|
||||||
this.controls_ = optionsInternal.controls;
|
this.controls_ = optionsInternal.controls;
|
||||||
|
|
||||||
/**
|
|
||||||
* @type {olx.DeviceOptions}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
this.deviceOptions_ = optionsInternal.deviceOptions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {ol.Collection.<ol.interaction.Interaction>}
|
* @type {ol.Collection.<ol.interaction.Interaction>}
|
||||||
* @private
|
* @private
|
||||||
@@ -915,15 +924,14 @@ ol.Map.prototype.handlePostRender = function() {
|
|||||||
var tileSourceCount = 0;
|
var tileSourceCount = 0;
|
||||||
if (!goog.isNull(frameState)) {
|
if (!goog.isNull(frameState)) {
|
||||||
var hints = frameState.viewHints;
|
var hints = frameState.viewHints;
|
||||||
var deviceOptions = this.deviceOptions_;
|
|
||||||
if (hints[ol.ViewHint.ANIMATING]) {
|
if (hints[ol.ViewHint.ANIMATING]) {
|
||||||
maxTotalLoading = deviceOptions.loadTilesWhileAnimating === false ?
|
maxTotalLoading = this.loadTilesWhileAnimating_ === true ?
|
||||||
0 : 8;
|
8 : 0;
|
||||||
maxNewLoads = 2;
|
maxNewLoads = 2;
|
||||||
}
|
}
|
||||||
if (hints[ol.ViewHint.INTERACTING]) {
|
if (hints[ol.ViewHint.INTERACTING]) {
|
||||||
maxTotalLoading = deviceOptions.loadTilesWhileInteracting === false ?
|
maxTotalLoading = this.loadTilesWhileInteracting_ === true ?
|
||||||
0 : 8;
|
8 : 0;
|
||||||
maxNewLoads = 2;
|
maxNewLoads = 2;
|
||||||
}
|
}
|
||||||
tileSourceCount = goog.object.getCount(frameState.wantedTiles);
|
tileSourceCount = goog.object.getCount(frameState.wantedTiles);
|
||||||
@@ -1397,7 +1405,6 @@ ol.Map.prototype.unskipFeature = function(feature) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{controls: ol.Collection.<ol.control.Control>,
|
* @typedef {{controls: ol.Collection.<ol.control.Control>,
|
||||||
* deviceOptions: olx.DeviceOptions,
|
|
||||||
* interactions: ol.Collection.<ol.interaction.Interaction>,
|
* interactions: ol.Collection.<ol.interaction.Interaction>,
|
||||||
* keyboardEventTarget: (Element|Document),
|
* keyboardEventTarget: (Element|Document),
|
||||||
* logos: Object,
|
* logos: Object,
|
||||||
@@ -1511,9 +1518,6 @@ ol.Map.createOptionsInternal = function(options) {
|
|||||||
controls = ol.control.defaults();
|
controls = ol.control.defaults();
|
||||||
}
|
}
|
||||||
|
|
||||||
var deviceOptions = goog.isDef(options.deviceOptions) ?
|
|
||||||
options.deviceOptions : /** @type {olx.DeviceOptions} */ ({});
|
|
||||||
|
|
||||||
var interactions;
|
var interactions;
|
||||||
if (goog.isDef(options.interactions)) {
|
if (goog.isDef(options.interactions)) {
|
||||||
if (goog.isArray(options.interactions)) {
|
if (goog.isArray(options.interactions)) {
|
||||||
@@ -1540,7 +1544,6 @@ ol.Map.createOptionsInternal = function(options) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
controls: controls,
|
controls: controls,
|
||||||
deviceOptions: deviceOptions,
|
|
||||||
interactions: interactions,
|
interactions: interactions,
|
||||||
keyboardEventTarget: keyboardEventTarget,
|
keyboardEventTarget: keyboardEventTarget,
|
||||||
logos: logos,
|
logos: logos,
|
||||||
|
|||||||
Reference in New Issue
Block a user