Merge pull request #677 from twpayne/improve-type-checking
Improve type checking
This commit is contained in:
+88
-68
@@ -17,22 +17,27 @@ ol.animation.bounce = function(options) {
|
|||||||
var duration = goog.isDef(options.duration) ? options.duration : 1000;
|
var duration = goog.isDef(options.duration) ? options.duration : 1000;
|
||||||
var easing = goog.isDef(options.easing) ?
|
var easing = goog.isDef(options.easing) ?
|
||||||
options.easing : ol.easing.upAndDown;
|
options.easing : ol.easing.upAndDown;
|
||||||
return function(map, frameState) {
|
return (
|
||||||
if (frameState.time < start) {
|
/**
|
||||||
frameState.animate = true;
|
* @param {ol.Map} map Map.
|
||||||
frameState.viewHints[ol.ViewHint.ANIMATING] += 1;
|
* @param {?ol.FrameState} frameState Frame state.
|
||||||
return true;
|
*/
|
||||||
} else if (frameState.time < start + duration) {
|
function(map, frameState) {
|
||||||
var delta = easing((frameState.time - start) / duration);
|
if (frameState.time < start) {
|
||||||
var deltaResolution = resolution - frameState.view2DState.resolution;
|
frameState.animate = true;
|
||||||
frameState.animate = true;
|
frameState.viewHints[ol.ViewHint.ANIMATING] += 1;
|
||||||
frameState.view2DState.resolution += delta * deltaResolution;
|
return true;
|
||||||
frameState.viewHints[ol.ViewHint.ANIMATING] += 1;
|
} else if (frameState.time < start + duration) {
|
||||||
return true;
|
var delta = easing((frameState.time - start) / duration);
|
||||||
} else {
|
var deltaResolution = resolution - frameState.view2DState.resolution;
|
||||||
return false;
|
frameState.animate = true;
|
||||||
}
|
frameState.view2DState.resolution += delta * deltaResolution;
|
||||||
};
|
frameState.viewHints[ol.ViewHint.ANIMATING] += 1;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -48,24 +53,29 @@ ol.animation.pan = function(options) {
|
|||||||
var duration = goog.isDef(options.duration) ? options.duration : 1000;
|
var duration = goog.isDef(options.duration) ? options.duration : 1000;
|
||||||
var easing = goog.isDef(options.easing) ?
|
var easing = goog.isDef(options.easing) ?
|
||||||
options.easing : ol.easing.inAndOut;
|
options.easing : ol.easing.inAndOut;
|
||||||
return function(map, frameState) {
|
return (
|
||||||
if (frameState.time < start) {
|
/**
|
||||||
frameState.animate = true;
|
* @param {ol.Map} map Map.
|
||||||
frameState.viewHints[ol.ViewHint.ANIMATING] += 1;
|
* @param {?ol.FrameState} frameState Frame state.
|
||||||
return true;
|
*/
|
||||||
} else if (frameState.time < start + duration) {
|
function(map, frameState) {
|
||||||
var delta = 1 - easing((frameState.time - start) / duration);
|
if (frameState.time < start) {
|
||||||
var deltaX = sourceX - frameState.view2DState.center[0];
|
frameState.animate = true;
|
||||||
var deltaY = sourceY - frameState.view2DState.center[1];
|
frameState.viewHints[ol.ViewHint.ANIMATING] += 1;
|
||||||
frameState.animate = true;
|
return true;
|
||||||
frameState.view2DState.center[0] += delta * deltaX;
|
} else if (frameState.time < start + duration) {
|
||||||
frameState.view2DState.center[1] += delta * deltaY;
|
var delta = 1 - easing((frameState.time - start) / duration);
|
||||||
frameState.viewHints[ol.ViewHint.ANIMATING] += 1;
|
var deltaX = sourceX - frameState.view2DState.center[0];
|
||||||
return true;
|
var deltaY = sourceY - frameState.view2DState.center[1];
|
||||||
} else {
|
frameState.animate = true;
|
||||||
return false;
|
frameState.view2DState.center[0] += delta * deltaX;
|
||||||
}
|
frameState.view2DState.center[1] += delta * deltaY;
|
||||||
};
|
frameState.viewHints[ol.ViewHint.ANIMATING] += 1;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -80,23 +90,28 @@ ol.animation.rotate = function(options) {
|
|||||||
var easing = goog.isDef(options.easing) ?
|
var easing = goog.isDef(options.easing) ?
|
||||||
options.easing : ol.easing.inAndOut;
|
options.easing : ol.easing.inAndOut;
|
||||||
|
|
||||||
return function(map, frameState) {
|
return (
|
||||||
if (frameState.time < start) {
|
/**
|
||||||
frameState.animate = true;
|
* @param {ol.Map} map Map.
|
||||||
frameState.viewHints[ol.ViewHint.ANIMATING] += 1;
|
* @param {?ol.FrameState} frameState Frame state.
|
||||||
return true;
|
*/
|
||||||
} else if (frameState.time < start + duration) {
|
function(map, frameState) {
|
||||||
var delta = 1 - easing((frameState.time - start) / duration);
|
if (frameState.time < start) {
|
||||||
var deltaRotation =
|
frameState.animate = true;
|
||||||
sourceRotation - frameState.view2DState.rotation;
|
frameState.viewHints[ol.ViewHint.ANIMATING] += 1;
|
||||||
frameState.animate = true;
|
return true;
|
||||||
frameState.view2DState.rotation += delta * deltaRotation;
|
} else if (frameState.time < start + duration) {
|
||||||
frameState.viewHints[ol.ViewHint.ANIMATING] += 1;
|
var delta = 1 - easing((frameState.time - start) / duration);
|
||||||
return true;
|
var deltaRotation =
|
||||||
} else {
|
sourceRotation - frameState.view2DState.rotation;
|
||||||
return false;
|
frameState.animate = true;
|
||||||
}
|
frameState.view2DState.rotation += delta * deltaRotation;
|
||||||
};
|
frameState.viewHints[ol.ViewHint.ANIMATING] += 1;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -110,21 +125,26 @@ ol.animation.zoom = function(options) {
|
|||||||
var duration = goog.isDef(options.duration) ? options.duration : 1000;
|
var duration = goog.isDef(options.duration) ? options.duration : 1000;
|
||||||
var easing = goog.isDef(options.easing) ?
|
var easing = goog.isDef(options.easing) ?
|
||||||
options.easing : ol.easing.inAndOut;
|
options.easing : ol.easing.inAndOut;
|
||||||
return function(map, frameState) {
|
return (
|
||||||
if (frameState.time < start) {
|
/**
|
||||||
frameState.animate = true;
|
* @param {ol.Map} map Map.
|
||||||
frameState.viewHints[ol.ViewHint.ANIMATING] += 1;
|
* @param {?ol.FrameState} frameState Frame state.
|
||||||
return true;
|
*/
|
||||||
} else if (frameState.time < start + duration) {
|
function(map, frameState) {
|
||||||
var delta = 1 - easing((frameState.time - start) / duration);
|
if (frameState.time < start) {
|
||||||
var deltaResolution =
|
frameState.animate = true;
|
||||||
sourceResolution - frameState.view2DState.resolution;
|
frameState.viewHints[ol.ViewHint.ANIMATING] += 1;
|
||||||
frameState.animate = true;
|
return true;
|
||||||
frameState.view2DState.resolution += delta * deltaResolution;
|
} else if (frameState.time < start + duration) {
|
||||||
frameState.viewHints[ol.ViewHint.ANIMATING] += 1;
|
var delta = 1 - easing((frameState.time - start) / duration);
|
||||||
return true;
|
var deltaResolution =
|
||||||
} else {
|
sourceResolution - frameState.view2DState.resolution;
|
||||||
return false;
|
frameState.animate = true;
|
||||||
}
|
frameState.view2DState.resolution += delta * deltaResolution;
|
||||||
};
|
frameState.viewHints[ol.ViewHint.ANIMATING] += 1;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -35,9 +35,14 @@ ol.coordinate.add = function(coordinate, delta) {
|
|||||||
* @return {ol.CoordinateFormatType} Coordinate format.
|
* @return {ol.CoordinateFormatType} Coordinate format.
|
||||||
*/
|
*/
|
||||||
ol.coordinate.createStringXY = function(opt_precision) {
|
ol.coordinate.createStringXY = function(opt_precision) {
|
||||||
return function(coordinate) {
|
return (
|
||||||
return ol.coordinate.toStringXY(coordinate, opt_precision);
|
/**
|
||||||
};
|
* @param {ol.Coordinate|undefined} coordinate Coordinate.
|
||||||
|
* @return {string} String XY.
|
||||||
|
*/
|
||||||
|
function(coordinate) {
|
||||||
|
return ol.coordinate.toStringXY(coordinate, opt_precision);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,15 +15,21 @@ ol.ImageUrlFunctionType;
|
|||||||
* @param {string} baseUrl Base URL (may have query data).
|
* @param {string} baseUrl Base URL (may have query data).
|
||||||
* @param {Object.<string,*>} params to encode in the url.
|
* @param {Object.<string,*>} params to encode in the url.
|
||||||
* @param {function(string, Object.<string,*>, ol.Extent, ol.Size,
|
* @param {function(string, Object.<string,*>, ol.Extent, ol.Size,
|
||||||
* ol.Projection)} paramsFunction params function.
|
* ol.Projection): (string|undefined)} paramsFunction params function.
|
||||||
* @return {ol.ImageUrlFunctionType} Image URL function.
|
* @return {ol.ImageUrlFunctionType} Image URL function.
|
||||||
*/
|
*/
|
||||||
ol.ImageUrlFunction.createFromParamsFunction =
|
ol.ImageUrlFunction.createFromParamsFunction =
|
||||||
function(baseUrl, params, paramsFunction) {
|
function(baseUrl, params, paramsFunction) {
|
||||||
return function(extent, size, projection) {
|
return (
|
||||||
return paramsFunction(
|
/**
|
||||||
baseUrl, params, extent, size, projection);
|
* @param {ol.Extent} extent Extent.
|
||||||
};
|
* @param {ol.Size} size Size.
|
||||||
|
* @param {ol.Projection} projection Projection.
|
||||||
|
* @return {string|undefined} URL.
|
||||||
|
*/
|
||||||
|
function(extent, size, projection) {
|
||||||
|
return paramsFunction(baseUrl, params, extent, size, projection);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -266,10 +266,17 @@ ol.renderer.Layer.prototype.updateUsedTiles =
|
|||||||
*/
|
*/
|
||||||
ol.renderer.Layer.prototype.createGetTileIfLoadedFunction =
|
ol.renderer.Layer.prototype.createGetTileIfLoadedFunction =
|
||||||
function(isLoadedFunction, tileSource, projection) {
|
function(isLoadedFunction, tileSource, projection) {
|
||||||
return function(z, x, y) {
|
return (
|
||||||
var tile = tileSource.getTile(z, x, y, projection);
|
/**
|
||||||
return isLoadedFunction(tile) ? tile : null;
|
* @param {number} z Z.
|
||||||
};
|
* @param {number} x X.
|
||||||
|
* @param {number} y Y.
|
||||||
|
* @return {ol.Tile} Tile.
|
||||||
|
*/
|
||||||
|
function(z, x, y) {
|
||||||
|
var tile = tileSource.getTile(z, x, y, projection);
|
||||||
|
return isLoadedFunction(tile) ? tile : null;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -20,14 +20,21 @@ ol.ResolutionConstraintType;
|
|||||||
ol.ResolutionConstraint.createContinuous =
|
ol.ResolutionConstraint.createContinuous =
|
||||||
function(power, maxResolution, opt_minResolution) {
|
function(power, maxResolution, opt_minResolution) {
|
||||||
var minResolution = opt_minResolution || 0;
|
var minResolution = opt_minResolution || 0;
|
||||||
return function(resolution, delta, direction) {
|
return (
|
||||||
if (goog.isDef(resolution)) {
|
/**
|
||||||
resolution /= Math.pow(power, delta);
|
* @param {number|undefined} resolution Resolution.
|
||||||
return goog.math.clamp(resolution, minResolution, maxResolution);
|
* @param {number} delta Delta.
|
||||||
} else {
|
* @param {number} direction Direction.
|
||||||
return undefined;
|
* @return {number|undefined} Resolution.
|
||||||
}
|
*/
|
||||||
};
|
function(resolution, delta, direction) {
|
||||||
|
if (goog.isDef(resolution)) {
|
||||||
|
resolution /= Math.pow(power, delta);
|
||||||
|
return goog.math.clamp(resolution, minResolution, maxResolution);
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -37,15 +44,23 @@ ol.ResolutionConstraint.createContinuous =
|
|||||||
*/
|
*/
|
||||||
ol.ResolutionConstraint.createSnapToResolutions =
|
ol.ResolutionConstraint.createSnapToResolutions =
|
||||||
function(resolutions) {
|
function(resolutions) {
|
||||||
return function(resolution, delta, direction) {
|
return (
|
||||||
if (goog.isDef(resolution)) {
|
/**
|
||||||
var z = ol.array.linearFindNearest(resolutions, resolution, direction);
|
* @param {number|undefined} resolution Resolution.
|
||||||
z = goog.math.clamp(z + delta, 0, resolutions.length - 1);
|
* @param {number} delta Delta.
|
||||||
return resolutions[z];
|
* @param {number} direction Direction.
|
||||||
} else {
|
* @return {number|undefined} Resolution.
|
||||||
return undefined;
|
*/
|
||||||
}
|
function(resolution, delta, direction) {
|
||||||
};
|
if (goog.isDef(resolution)) {
|
||||||
|
var z =
|
||||||
|
ol.array.linearFindNearest(resolutions, resolution, direction);
|
||||||
|
z = goog.math.clamp(z + delta, 0, resolutions.length - 1);
|
||||||
|
return resolutions[z];
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -57,25 +72,32 @@ ol.ResolutionConstraint.createSnapToResolutions =
|
|||||||
*/
|
*/
|
||||||
ol.ResolutionConstraint.createSnapToPower =
|
ol.ResolutionConstraint.createSnapToPower =
|
||||||
function(power, maxResolution, opt_maxLevel) {
|
function(power, maxResolution, opt_maxLevel) {
|
||||||
return function(resolution, delta, direction) {
|
return (
|
||||||
if (goog.isDef(resolution)) {
|
/**
|
||||||
var offset;
|
* @param {number|undefined} resolution Resolution.
|
||||||
if (direction > 0) {
|
* @param {number} delta Delta.
|
||||||
offset = 0;
|
* @param {number} direction Direction.
|
||||||
} else if (direction < 0) {
|
* @return {number|undefined} Resolution.
|
||||||
offset = 1;
|
*/
|
||||||
} else {
|
function(resolution, delta, direction) {
|
||||||
offset = 0.5;
|
if (goog.isDef(resolution)) {
|
||||||
}
|
var offset;
|
||||||
var oldLevel = Math.floor(
|
if (direction > 0) {
|
||||||
Math.log(maxResolution / resolution) / Math.log(power) + offset);
|
offset = 0;
|
||||||
var newLevel = Math.max(oldLevel + delta, 0);
|
} else if (direction < 0) {
|
||||||
if (goog.isDef(opt_maxLevel)) {
|
offset = 1;
|
||||||
newLevel = Math.min(newLevel, opt_maxLevel);
|
} else {
|
||||||
}
|
offset = 0.5;
|
||||||
return maxResolution / Math.pow(power, newLevel);
|
}
|
||||||
} else {
|
var oldLevel = Math.floor(
|
||||||
return undefined;
|
Math.log(maxResolution / resolution) / Math.log(power) + offset);
|
||||||
}
|
var newLevel = Math.max(oldLevel + delta, 0);
|
||||||
};
|
if (goog.isDef(opt_maxLevel)) {
|
||||||
|
newLevel = Math.min(newLevel, opt_maxLevel);
|
||||||
|
}
|
||||||
|
return maxResolution / Math.pow(power, newLevel);
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -28,14 +28,20 @@ ol.RotationConstraint.none = function(rotation, delta) {
|
|||||||
*/
|
*/
|
||||||
ol.RotationConstraint.createSnapToN = function(n) {
|
ol.RotationConstraint.createSnapToN = function(n) {
|
||||||
var theta = 2 * Math.PI / n;
|
var theta = 2 * Math.PI / n;
|
||||||
return function(rotation, delta) {
|
return (
|
||||||
if (goog.isDef(rotation)) {
|
/**
|
||||||
rotation = Math.floor((rotation + delta) / theta + 0.5) * theta;
|
* @param {number|undefined} rotation Rotation.
|
||||||
return rotation;
|
* @param {number} delta Delta.
|
||||||
} else {
|
* @return {number|undefined} Rotation.
|
||||||
return undefined;
|
*/
|
||||||
}
|
function(rotation, delta) {
|
||||||
};
|
if (goog.isDef(rotation)) {
|
||||||
|
rotation = Math.floor((rotation + delta) / theta + 0.5) * theta;
|
||||||
|
return rotation;
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -45,15 +51,21 @@ ol.RotationConstraint.createSnapToN = function(n) {
|
|||||||
*/
|
*/
|
||||||
ol.RotationConstraint.createSnapToZero = function(opt_tolerance) {
|
ol.RotationConstraint.createSnapToZero = function(opt_tolerance) {
|
||||||
var tolerance = opt_tolerance || 0.1;
|
var tolerance = opt_tolerance || 0.1;
|
||||||
return function(rotation, delta) {
|
return (
|
||||||
if (goog.isDef(rotation)) {
|
/**
|
||||||
if (Math.abs(rotation + delta) <= tolerance) {
|
* @param {number|undefined} rotation Rotation.
|
||||||
return 0;
|
* @param {number} delta Delta.
|
||||||
} else {
|
* @return {number|undefined} Rotation.
|
||||||
return rotation + delta;
|
*/
|
||||||
}
|
function(rotation, delta) {
|
||||||
} else {
|
if (goog.isDef(rotation)) {
|
||||||
return undefined;
|
if (Math.abs(rotation + delta) <= tolerance) {
|
||||||
}
|
return 0;
|
||||||
};
|
} else {
|
||||||
|
return rotation + delta;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -88,16 +88,22 @@ ol.source.BingMaps.prototype.handleImageryMetadataResponse =
|
|||||||
var imageUrl = resource.imageUrl
|
var imageUrl = resource.imageUrl
|
||||||
.replace('{subdomain}', subdomain)
|
.replace('{subdomain}', subdomain)
|
||||||
.replace('{culture}', culture);
|
.replace('{culture}', culture);
|
||||||
return function(tileCoord, projection) {
|
return (
|
||||||
goog.asserts.assert(ol.projection.equivalent(
|
/**
|
||||||
projection, this.getProjection()));
|
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
||||||
if (goog.isNull(tileCoord)) {
|
* @param {ol.Projection} projection Projection.
|
||||||
return undefined;
|
* @return {string|undefined} Tile URL.
|
||||||
} else {
|
*/
|
||||||
return imageUrl.replace(
|
function(tileCoord, projection) {
|
||||||
'{quadkey}', tileCoord.quadKey());
|
goog.asserts.assert(ol.projection.equivalent(
|
||||||
}
|
projection, this.getProjection()));
|
||||||
};
|
if (goog.isNull(tileCoord)) {
|
||||||
|
return undefined;
|
||||||
|
} else {
|
||||||
|
return imageUrl.replace(
|
||||||
|
'{quadkey}', tileCoord.quadKey());
|
||||||
|
}
|
||||||
|
});
|
||||||
})));
|
})));
|
||||||
|
|
||||||
var transform = ol.projection.getTransformFromProjections(
|
var transform = ol.projection.getTransformFromProjections(
|
||||||
|
|||||||
@@ -60,7 +60,14 @@ ol.source.StaticImage.prototype.getImage =
|
|||||||
* @return {ol.ImageUrlFunctionType} Function.
|
* @return {ol.ImageUrlFunctionType} Function.
|
||||||
*/
|
*/
|
||||||
ol.source.StaticImage.createImageFunction = function(url) {
|
ol.source.StaticImage.createImageFunction = function(url) {
|
||||||
return function(extent, size, projection) {
|
return (
|
||||||
return url;
|
/**
|
||||||
};
|
* @param {ol.Extent} extent Extent.
|
||||||
|
* @param {ol.Size} size Size.
|
||||||
|
* @param {ol.Projection} projection Projection.
|
||||||
|
* @return {string|undefined} URL.
|
||||||
|
*/
|
||||||
|
function(extent, size, projection) {
|
||||||
|
return url;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
+26
-21
@@ -73,27 +73,32 @@ ol.source.WMTS = function(options) {
|
|||||||
* @return {ol.TileUrlFunctionType} Tile URL function.
|
* @return {ol.TileUrlFunctionType} Tile URL function.
|
||||||
*/
|
*/
|
||||||
function createFromWMTSTemplate(template) {
|
function createFromWMTSTemplate(template) {
|
||||||
return function(tileCoord) {
|
return (
|
||||||
if (goog.isNull(tileCoord)) {
|
/**
|
||||||
return undefined;
|
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
||||||
} else {
|
* @return {string|undefined} Tile URL.
|
||||||
var localContext = {
|
*/
|
||||||
'TileMatrix': tileGrid.getMatrixId(tileCoord.z),
|
function(tileCoord) {
|
||||||
'TileCol': tileCoord.x,
|
if (goog.isNull(tileCoord)) {
|
||||||
'TileRow': tileCoord.y
|
return undefined;
|
||||||
};
|
} else {
|
||||||
if (requestEncoding != ol.source.WMTSRequestEncoding.KVP) {
|
var localContext = {
|
||||||
goog.object.extend(localContext, context);
|
'TileMatrix': tileGrid.getMatrixId(tileCoord.z),
|
||||||
}
|
'TileCol': tileCoord.x,
|
||||||
var url = template;
|
'TileRow': tileCoord.y
|
||||||
for (var key in localContext) {
|
};
|
||||||
// FIXME: should we filter properties with hasOwnProperty?
|
if (requestEncoding != ol.source.WMTSRequestEncoding.KVP) {
|
||||||
url = url.replace('{' + key + '}', localContext[key])
|
goog.object.extend(localContext, context);
|
||||||
.replace('%7B' + key + '%7D', localContext[key]);
|
}
|
||||||
}
|
var url = template;
|
||||||
return url;
|
for (var key in localContext) {
|
||||||
}
|
// FIXME: should we filter properties with hasOwnProperty?
|
||||||
};
|
url = url.replace('{' + key + '}', localContext[key])
|
||||||
|
.replace('%7B' + key + '%7D', localContext[key]);
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var tileUrlFunction = ol.TileUrlFunction.nullTileUrlFunction;
|
var tileUrlFunction = ol.TileUrlFunction.nullTileUrlFunction;
|
||||||
|
|||||||
+66
-41
@@ -18,15 +18,21 @@ ol.TileUrlFunctionType;
|
|||||||
* @return {ol.TileUrlFunctionType} Tile URL function.
|
* @return {ol.TileUrlFunctionType} Tile URL function.
|
||||||
*/
|
*/
|
||||||
ol.TileUrlFunction.createFromTemplate = function(template) {
|
ol.TileUrlFunction.createFromTemplate = function(template) {
|
||||||
return function(tileCoord) {
|
return (
|
||||||
if (goog.isNull(tileCoord)) {
|
/**
|
||||||
return undefined;
|
* @param {ol.TileCoord} tileCoord Tile Coordinate.
|
||||||
} else {
|
* @param {ol.Projection} projection Projection.
|
||||||
return template.replace('{z}', tileCoord.z)
|
* @return {string|undefined} Tile URL.
|
||||||
.replace('{x}', tileCoord.x)
|
*/
|
||||||
.replace('{y}', tileCoord.y);
|
function(tileCoord, projection) {
|
||||||
}
|
if (goog.isNull(tileCoord)) {
|
||||||
};
|
return undefined;
|
||||||
|
} else {
|
||||||
|
return template.replace('{z}', '' + tileCoord.z)
|
||||||
|
.replace('{x}', '' + tileCoord.x)
|
||||||
|
.replace('{y}', '' + tileCoord.y);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -48,14 +54,21 @@ ol.TileUrlFunction.createFromTileUrlFunctions = function(tileUrlFunctions) {
|
|||||||
if (tileUrlFunctions.length === 1) {
|
if (tileUrlFunctions.length === 1) {
|
||||||
return tileUrlFunctions[0];
|
return tileUrlFunctions[0];
|
||||||
}
|
}
|
||||||
return function(tileCoord, projection) {
|
return (
|
||||||
if (goog.isNull(tileCoord)) {
|
/**
|
||||||
return undefined;
|
* @param {ol.TileCoord} tileCoord Tile Coordinate.
|
||||||
} else {
|
* @param {ol.Projection} projection Projection.
|
||||||
var index = goog.math.modulo(tileCoord.hash(), tileUrlFunctions.length);
|
* @return {string|undefined} Tile URL.
|
||||||
return tileUrlFunctions[index].call(this, tileCoord, projection);
|
*/
|
||||||
}
|
function(tileCoord, projection) {
|
||||||
};
|
if (goog.isNull(tileCoord)) {
|
||||||
|
return undefined;
|
||||||
|
} else {
|
||||||
|
var index =
|
||||||
|
goog.math.modulo(tileCoord.hash(), tileUrlFunctions.length);
|
||||||
|
return tileUrlFunctions[index].call(this, tileCoord, projection);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -69,20 +82,26 @@ ol.TileUrlFunction.createFromTileUrlFunctions = function(tileUrlFunctions) {
|
|||||||
ol.TileUrlFunction.createFromParamsFunction =
|
ol.TileUrlFunction.createFromParamsFunction =
|
||||||
function(baseUrl, params, paramsFunction) {
|
function(baseUrl, params, paramsFunction) {
|
||||||
var tmpExtent = ol.extent.createEmptyExtent();
|
var tmpExtent = ol.extent.createEmptyExtent();
|
||||||
return function(tileCoord, projection) {
|
return (
|
||||||
if (goog.isNull(tileCoord)) {
|
/**
|
||||||
return undefined;
|
* @param {ol.TileCoord} tileCoord Tile Coordinate.
|
||||||
} else {
|
* @param {ol.Projection} projection Projection.
|
||||||
var tileGrid = this.getTileGrid();
|
* @return {string|undefined} Tile URL.
|
||||||
if (goog.isNull(tileGrid)) {
|
*/
|
||||||
tileGrid = ol.tilegrid.getForProjection(projection);
|
function(tileCoord, projection) {
|
||||||
}
|
if (goog.isNull(tileCoord)) {
|
||||||
var size = tileGrid.getTileSize(tileCoord.z);
|
return undefined;
|
||||||
var extent = tileGrid.getTileCoordExtent(tileCoord, tmpExtent);
|
} else {
|
||||||
return paramsFunction.call(this, baseUrl, params,
|
var tileGrid = this.getTileGrid();
|
||||||
extent, size, projection);
|
if (goog.isNull(tileGrid)) {
|
||||||
}
|
tileGrid = ol.tilegrid.getForProjection(projection);
|
||||||
};
|
}
|
||||||
|
var size = tileGrid.getTileSize(tileCoord.z);
|
||||||
|
var extent = tileGrid.getTileCoordExtent(tileCoord, tmpExtent);
|
||||||
|
return paramsFunction.call(this, baseUrl, params,
|
||||||
|
extent, size, projection);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -105,16 +124,22 @@ ol.TileUrlFunction.nullTileUrlFunction = function(tileCoord, projection) {
|
|||||||
ol.TileUrlFunction.withTileCoordTransform =
|
ol.TileUrlFunction.withTileCoordTransform =
|
||||||
function(transformFn, tileUrlFunction) {
|
function(transformFn, tileUrlFunction) {
|
||||||
var tmpTileCoord = new ol.TileCoord(0, 0, 0);
|
var tmpTileCoord = new ol.TileCoord(0, 0, 0);
|
||||||
return function(tileCoord, projection) {
|
return (
|
||||||
if (goog.isNull(tileCoord)) {
|
/**
|
||||||
return undefined;
|
* @param {ol.TileCoord} tileCoord Tile Coordinate.
|
||||||
} else {
|
* @param {ol.Projection} projection Projection.
|
||||||
return tileUrlFunction.call(
|
* @return {string|undefined} Tile URL.
|
||||||
this,
|
*/
|
||||||
transformFn.call(this, tileCoord, projection, tmpTileCoord),
|
function(tileCoord, projection) {
|
||||||
projection);
|
if (goog.isNull(tileCoord)) {
|
||||||
}
|
return undefined;
|
||||||
};
|
} else {
|
||||||
|
return tileUrlFunction.call(
|
||||||
|
this,
|
||||||
|
transformFn.call(this, tileCoord, projection, tmpTileCoord),
|
||||||
|
projection);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+22
-11
@@ -231,12 +231,17 @@ ol.View2D.prototype.getResolutionForValueFunction = function(opt_power) {
|
|||||||
var maxResolution = this.maxResolution_;
|
var maxResolution = this.maxResolution_;
|
||||||
var minResolution = this.minResolution_;
|
var minResolution = this.minResolution_;
|
||||||
var max = Math.log(maxResolution / minResolution) / Math.log(power);
|
var max = Math.log(maxResolution / minResolution) / Math.log(power);
|
||||||
return function(value) {
|
return (
|
||||||
var resolution = maxResolution / Math.pow(power, value * max);
|
/**
|
||||||
goog.asserts.assert(resolution >= minResolution &&
|
* @param {number} value Value.
|
||||||
resolution <= maxResolution);
|
* @return {number} Resolution.
|
||||||
return resolution;
|
*/
|
||||||
};
|
function(value) {
|
||||||
|
var resolution = maxResolution / Math.pow(power, value * max);
|
||||||
|
goog.asserts.assert(resolution >= minResolution &&
|
||||||
|
resolution <= maxResolution);
|
||||||
|
return resolution;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -264,11 +269,17 @@ ol.View2D.prototype.getValueForResolutionFunction = function(opt_power) {
|
|||||||
var maxResolution = this.maxResolution_;
|
var maxResolution = this.maxResolution_;
|
||||||
var minResolution = this.minResolution_;
|
var minResolution = this.minResolution_;
|
||||||
var max = Math.log(maxResolution / minResolution) / Math.log(power);
|
var max = Math.log(maxResolution / minResolution) / Math.log(power);
|
||||||
return function(resolution) {
|
return (
|
||||||
var value = (Math.log(maxResolution / resolution) / Math.log(power)) / max;
|
/**
|
||||||
goog.asserts.assert(value >= 0 && value <= 1);
|
* @param {number} resolution Resolution.
|
||||||
return value;
|
* @return {number} Value.
|
||||||
};
|
*/
|
||||||
|
function(resolution) {
|
||||||
|
var value =
|
||||||
|
(Math.log(maxResolution / resolution) / Math.log(power)) / max;
|
||||||
|
goog.asserts.assert(value >= 0 && value <= 1);
|
||||||
|
return value;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user