Merge branch 'master' of github.com:openlayers/ol3 into vector

This commit is contained in:
Bart van den Eijnden
2013-03-05 14:20:32 +01:00
29 changed files with 539 additions and 258 deletions
+32 -30
View File
@@ -243,24 +243,24 @@ def build_lint_src_timestamp(t):
def _strip_comments(lines): def _strip_comments(lines):
# FIXME this is a horribe hack, we should use a proper JavaScript parser here # FIXME this is a horribe hack, we should use a proper JavaScript parser here
in_comment = False in_multiline_comment = False
lineno = 0
for line in lines: for line in lines:
if in_comment: lineno += 1
if in_multiline_comment:
index = line.find('*/') index = line.find('*/')
if index != -1: if index != -1:
in_comment = False in_multiline_comment = False
yield line[index + 2:] line = line[index + 2:]
else: if not in_multiline_comment:
line = re.sub(r'//[^\n]*', '', line)
line = re.sub(r'/\*.*?\*/', '', line)
index = line.find('/*') index = line.find('/*')
if index != -1: if index != -1:
yield line[:index] yield lineno, line[:index]
in_comment = True in_multiline_comment = True
else: else:
index = line.find('//') yield lineno, line
if index != -1:
yield line[:index]
else:
yield line
@target('build/check-requires-timestamp', SRC, INTERNAL_SRC, EXTERNAL_SRC, EXAMPLES_SRC, SPEC) @target('build/check-requires-timestamp', SRC, INTERNAL_SRC, EXTERNAL_SRC, EXAMPLES_SRC, SPEC)
@@ -272,10 +272,8 @@ def build_check_requires_timestamp(t):
continue continue
require_linenos = {} require_linenos = {}
uses = set() uses = set()
lineno = 0
lines = open(filename).readlines() lines = open(filename).readlines()
for line in lines: for lineno, line in _strip_comments(lines):
lineno += 1
m = re.match(r'goog.provide\(\'(.*)\'\);', line) m = re.match(r'goog.provide\(\'(.*)\'\);', line)
if m: if m:
all_provides.add(m.group(1)) all_provides.add(m.group(1))
@@ -284,7 +282,7 @@ def build_check_requires_timestamp(t):
if m: if m:
require_linenos[m.group(1)] = lineno require_linenos[m.group(1)] = lineno
continue continue
for line in lines: for lineno, line in _strip_comments(lines):
for require in require_linenos.iterkeys(): for require in require_linenos.iterkeys():
if require in line: if require in line:
uses.add(require) uses.add(require)
@@ -302,9 +300,7 @@ def build_check_requires_timestamp(t):
provides = set() provides = set()
requires = set() requires = set()
uses = set() uses = set()
lineno = 0 for lineno, line in _strip_comments(open(filename)):
for line in _strip_comments(open(filename)):
lineno += 1
m = re.match(r'goog.provide\(\'(.*)\'\);', line) m = re.match(r'goog.provide\(\'(.*)\'\);', line)
if m: if m:
provides.add(m.group(1)) provides.add(m.group(1))
@@ -363,24 +359,30 @@ def jsdoc_BRANCH_timestamp(t):
@target('hostexamples', 'build', 'examples', phony=True) @target('hostexamples', 'build', 'examples', phony=True)
def hostexamples(t): def hostexamples(t):
t.makedirs('build/gh-pages/%(BRANCH)s/examples') examples_dir = 'build/gh-pages/%(BRANCH)s/examples'
t.makedirs('build/gh-pages/%(BRANCH)s/build') build_dir = 'build/gh-pages/%(BRANCH)s/build'
t.cp(EXAMPLES, (path.replace('.html', '.js') for path in EXAMPLES), 'examples/style.css', 'build/gh-pages/%(BRANCH)s/examples/') t.rm_rf(examples_dir)
t.rm_rf('build/gh-pages/%(BRANCH)s/examples/data') t.makedirs(examples_dir)
t.cp_r('examples/data', 'build/gh-pages/%(BRANCH)s/examples/data') t.rm_rf(build_dir)
t.cp('build/loader_hosted_examples.js', 'build/gh-pages/%(BRANCH)s/examples/loader.js') t.makedirs(build_dir)
t.cp('build/ol.js', 'build/ol-simple.js', 'build/ol-whitespace.js', 'build/ol.css', 'build/gh-pages/%(BRANCH)s/build/') t.cp(EXAMPLES, (path.replace('.html', '.js') for path in EXAMPLES),
t.cp('examples/example-list.html', 'build/gh-pages/%(BRANCH)s/examples/index.html') 'examples/style.css', examples_dir)
t.cp('examples/example-list.js', 'examples/example-list.xml', 'examples/Jugl.js', 'build/gh-pages/%(BRANCH)s/examples/') t.cp_r('examples/data', examples_dir + '/data')
t.cp('build/loader_hosted_examples.js', examples_dir + '/loader.js')
t.cp('build/ol.js', 'build/ol-simple.js', 'build/ol-whitespace.js',
'build/ol.css', build_dir)
t.cp('examples/example-list.html', examples_dir + '/index.html')
t.cp('examples/example-list.js', 'examples/example-list.xml',
'examples/Jugl.js', examples_dir)
@target('check-examples', 'hostexamples', phony=True) @target('check-examples', 'hostexamples', phony=True)
def check_examples(t): def check_examples(t):
directory = 'build/gh-pages/%(BRANCH)s/' directory = 'build/gh-pages/%(BRANCH)s/'
examples = ['build/gh-pages/%(BRANCH)s/' + e for e in EXAMPLES] examples = ['build/gh-pages/%(BRANCH)s/' + e for e in EXAMPLES]
all_examples = examples + \ all_examples = [e + '?mode=whitespace' for e in examples] + \
[e + '?mode=simple' for e in examples] + \ [e + '?mode=simple' for e in examples] + \
[e + '?mode=whitespace' for e in examples] examples
for example in all_examples: for example in all_examples:
t.run('%(PHANTOMJS)s', 'bin/check-example.js', example) t.run('%(PHANTOMJS)s', 'bin/check-example.js', example)
+1 -1
View File
@@ -16,8 +16,8 @@ var layers = new ol.Collection([
source: new ol.source.TiledWMS({ source: new ol.source.TiledWMS({
url: 'http://vmap0.tiles.osgeo.org/wms/vmap0', url: 'http://vmap0.tiles.osgeo.org/wms/vmap0',
crossOrigin: null, crossOrigin: null,
version: '1.1.1',
params: { params: {
'VERSION': '1.1.1',
'LAYERS': 'basic', 'LAYERS': 'basic',
'FORMAT': 'image/jpeg' 'FORMAT': 'image/jpeg'
}, },
+42
View File
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<link rel="stylesheet" href="style.css" type="text/css">
<style type="text/css">
html, body, #map {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
#text {
position: absolute;
top: 8px;
right: 8px;
z-index: 20000;
background-color: white;
padding: 0 0.5em 0.5em 0.5em;
border-radius: 4px;
}
</style>
<title>Stamen example</title>
</head>
<body>
<div id="map">
<div id="text">
<h1 id="title">Stamen example</h1>
<div id="shortdesc">Example of a Stamen tile source.</div>
<div id="docs">
<p>See the
<a href="stamen.js" target="_blank">stamen.js source</a>
to see how this is done.</p>
</div>
</div>
</div>
<div id="tags">fullscreen, stamen, tilelayer</div>
<script src="loader.js?id=stamen" type="text/javascript"></script>
</body>
</html>
+31
View File
@@ -0,0 +1,31 @@
goog.require('ol.Collection');
goog.require('ol.Coordinate');
goog.require('ol.Map');
goog.require('ol.RendererHints');
goog.require('ol.View2D');
goog.require('ol.layer.TileLayer');
goog.require('ol.source.Stamen');
var layers = new ol.Collection([
new ol.layer.TileLayer({
source: new ol.source.Stamen({
layer: 'watercolor'
})
}),
new ol.layer.TileLayer({
source: new ol.source.Stamen({
layer: 'terrain-labels'
})
})
]);
var map = new ol.Map({
layers: layers,
renderers: ol.RendererHints.createFromQueryData(),
scaleLineControl: true,
target: 'map',
view: new ol.View2D({
center: new ol.Coordinate(0, 0),
zoom: 3
})
});
-14
View File
@@ -19,19 +19,6 @@ var epsg21781 = new ol.Projection('EPSG:21781', ol.ProjectionUnits.METERS,
new ol.Extent(485869.5728, 76443.1884, 837076.5648, 299941.7864)); new ol.Extent(485869.5728, 76443.1884, 837076.5648, 299941.7864));
ol.projection.addProjection(epsg21781); ol.projection.addProjection(epsg21781);
// We could give the single image source a set of resolutions. This prevents the
// source from requesting images of arbitrary resolutions. To try it, uncomment
// the block below and the resolutions option in the SingleImageWMS config.
/*
var projectionExtent = epsg21781.getExtent();
var maxResolution = Math.max(projectionExtent.getWidth(),
projectionExtent.getHeight()) / 256;
var resolutions = new Array(10);
for (var i = 0; i < 10; ++i) {
resolutions[i] = maxResolution / Math.pow(2.0, i);
}
*/
var extent = new ol.Extent(420000, 30000, 900000, 350000); var extent = new ol.Extent(420000, 30000, 900000, 350000);
var layers = new ol.Collection([ var layers = new ol.Collection([
new ol.layer.TileLayer({ new ol.layer.TileLayer({
@@ -50,7 +37,6 @@ var layers = new ol.Collection([
}), }),
new ol.layer.ImageLayer({ new ol.layer.ImageLayer({
source: new ol.source.SingleImageWMS({ source: new ol.source.SingleImageWMS({
//resolutions: resolutions,
url: 'http://wms.geo.admin.ch/', url: 'http://wms.geo.admin.ch/',
attributions: [new ol.Attribution( attributions: [new ol.Attribution(
'&copy; ' + '&copy; ' +
+5 -6
View File
@@ -7,7 +7,6 @@
@exportObjectLiteralProperty ol.MapOptions.keyboardPanOffset number|undefined @exportObjectLiteralProperty ol.MapOptions.keyboardPanOffset number|undefined
@exportObjectLiteralProperty ol.MapOptions.layers ol.Collection|undefined @exportObjectLiteralProperty ol.MapOptions.layers ol.Collection|undefined
@exportObjectLiteralProperty ol.MapOptions.mouseWheelZoom boolean|undefined @exportObjectLiteralProperty ol.MapOptions.mouseWheelZoom boolean|undefined
@exportObjectLiteralProperty ol.MapOptions.mouseWheelZoomDelta number|undefined
@exportObjectLiteralProperty ol.MapOptions.renderer ol.RendererHint|undefined @exportObjectLiteralProperty ol.MapOptions.renderer ol.RendererHint|undefined
@exportObjectLiteralProperty ol.MapOptions.renderers Array.<ol.RendererHint>|undefined @exportObjectLiteralProperty ol.MapOptions.renderers Array.<ol.RendererHint>|undefined
@exportObjectLiteralProperty ol.MapOptions.scaleLineControl boolean|undefined @exportObjectLiteralProperty ol.MapOptions.scaleLineControl boolean|undefined
@@ -111,11 +110,13 @@
@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.projection ol.Projection|undefined @exportObjectLiteralProperty ol.source.SingleImageWMSOptions.projection ol.Projection|undefined
@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.resolutions Array.<number>|undefined @exportObjectLiteralProperty ol.source.SingleImageWMSOptions.resolutions Array.<number>|undefined
@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.url string|undefined @exportObjectLiteralProperty ol.source.SingleImageWMSOptions.url string|undefined
@exportObjectLiteralProperty ol.source.SingleImageWMSOptions.version string|undefined
@exportObjectLiteral ol.source.StamenOptions @exportObjectLiteral ol.source.StamenOptions
@exportObjectLiteralProperty ol.source.StamenOptions.flavor string|undefined @exportObjectLiteralProperty ol.source.StamenOptions.layer string
@exportObjectLiteralProperty ol.source.StamenOptions.provider string @exportObjectLiteralProperty ol.source.StamenOptions.minZoom number|undefined
@exportObjectLiteralProperty ol.source.StamenOptions.maxZoom number|undefined
@exportObjectLiteralProperty ol.source.StamenOptions.opaque boolean|undefined
@exportObjectLiteralProperty ol.source.StamenOptions.url string|undefined
@exportObjectLiteral ol.source.StaticImageOptions @exportObjectLiteral ol.source.StaticImageOptions
@exportObjectLiteralProperty ol.source.StaticImageOptions.attributions Array.<ol.Attribution>|undefined @exportObjectLiteralProperty ol.source.StaticImageOptions.attributions Array.<ol.Attribution>|undefined
@@ -129,11 +130,9 @@
@exportObjectLiteral ol.source.TiledWMSOptions @exportObjectLiteral ol.source.TiledWMSOptions
@exportObjectLiteralProperty ol.source.TiledWMSOptions.attributions Array.<ol.Attribution>|undefined @exportObjectLiteralProperty ol.source.TiledWMSOptions.attributions Array.<ol.Attribution>|undefined
@exportObjectLiteralProperty ol.source.TiledWMSOptions.params Object @exportObjectLiteralProperty ol.source.TiledWMSOptions.params Object
@exportObjectLiteralProperty ol.source.TiledWMSOptions.version string|undefined
@exportObjectLiteralProperty ol.source.TiledWMSOptions.crossOrigin null|string|undefined @exportObjectLiteralProperty ol.source.TiledWMSOptions.crossOrigin null|string|undefined
@exportObjectLiteralProperty ol.source.TiledWMSOptions.extent ol.Extent|undefined @exportObjectLiteralProperty ol.source.TiledWMSOptions.extent ol.Extent|undefined
@exportObjectLiteralProperty ol.source.TiledWMSOptions.tileGrid ol.tilegrid.TileGrid|undefined @exportObjectLiteralProperty ol.source.TiledWMSOptions.tileGrid ol.tilegrid.TileGrid|undefined
@exportObjectLiteralProperty ol.source.TiledWMSOptions.transparent boolean|undefined
@exportObjectLiteralProperty ol.source.TiledWMSOptions.maxZoom number|undefined @exportObjectLiteralProperty ol.source.TiledWMSOptions.maxZoom number|undefined
@exportObjectLiteralProperty ol.source.TiledWMSOptions.projection ol.Projection|undefined @exportObjectLiteralProperty ol.source.TiledWMSOptions.projection ol.Projection|undefined
@exportObjectLiteralProperty ol.source.TiledWMSOptions.url string|undefined @exportObjectLiteralProperty ol.source.TiledWMSOptions.url string|undefined
+4 -2
View File
@@ -70,7 +70,8 @@ ol.control.Zoom.prototype.handleIn_ = function(browserEvent) {
var map = this.getMap(); var map = this.getMap();
map.requestRenderFrame(); map.requestRenderFrame();
// FIXME works for View2D only // FIXME works for View2D only
map.getView().zoom(map, this.delta_, undefined, ol.control.ZOOM_DURATION); map.getView().zoomByDelta(map, this.delta_, undefined,
ol.control.ZOOM_DURATION);
}; };
@@ -84,5 +85,6 @@ ol.control.Zoom.prototype.handleOut_ = function(browserEvent) {
var map = this.getMap(); var map = this.getMap();
map.requestRenderFrame(); map.requestRenderFrame();
// FIXME works for View2D only // FIXME works for View2D only
map.getView().zoom(map, -this.delta_, undefined, ol.control.ZOOM_DURATION); map.getView().zoomByDelta(map, -this.delta_, undefined,
ol.control.ZOOM_DURATION);
}; };
+2 -3
View File
@@ -15,14 +15,13 @@ ol.ImageUrlFunctionType;
/** /**
* @param {string} baseUrl Base URL (may have query data). * @param {string} baseUrl Base URL (may have query data).
* @param {Object.<string, string|number>} params WMS parameters. * @param {Object.<string, string|number>} params WMS parameters.
* @param {string=} opt_version WMS version.
* @return {ol.ImageUrlFunctionType} Image URL function. * @return {ol.ImageUrlFunctionType} Image URL function.
*/ */
ol.ImageUrlFunction.createWMSParams = ol.ImageUrlFunction.createWMSParams =
function(baseUrl, params, opt_version) { function(baseUrl, params) {
return function(extent, size, projection) { return function(extent, size, projection) {
return ol.source.wms.getUrl( return ol.source.wms.getUrl(
baseUrl, params, extent, size, projection, opt_version); baseUrl, params, extent, size, projection);
}; };
}; };
@@ -8,6 +8,12 @@ goog.require('ol.View2D');
goog.require('ol.interaction.Interaction'); goog.require('ol.interaction.Interaction');
/**
* @define {number} Animation duration.
*/
ol.interaction.DBLCLICKZOOM_ANIMATION_DURATION = 250;
/** /**
* @constructor * @constructor
@@ -41,7 +47,8 @@ ol.interaction.DblClickZoom.prototype.handleMapBrowserEvent =
// FIXME works for View2D only // FIXME works for View2D only
var view = map.getView(); var view = map.getView();
goog.asserts.assert(view instanceof ol.View2D); goog.asserts.assert(view instanceof ol.View2D);
view.zoom(map, delta, anchor); view.zoomByDelta(map, delta, anchor,
ol.interaction.DBLCLICKZOOM_ANIMATION_DURATION);
mapBrowserEvent.preventDefault(); mapBrowserEvent.preventDefault();
browserEvent.preventDefault(); browserEvent.preventDefault();
} }
@@ -66,7 +66,7 @@ ol.interaction.DragRotateAndZoom.prototype.handleDrag =
this.lastAngle_ = theta; this.lastAngle_ = theta;
if (goog.isDef(this.lastMagnitude_)) { if (goog.isDef(this.lastMagnitude_)) {
var resolution = this.lastMagnitude_ * (view.getResolution() / magnitude); var resolution = this.lastMagnitude_ * (view.getResolution() / magnitude);
view.zoomToResolution(map, resolution); view.zoom(map, resolution);
} }
this.lastMagnitude_ = magnitude; this.lastMagnitude_ = magnitude;
}; };
+24 -1
View File
@@ -1,10 +1,17 @@
goog.provide('ol.interaction.DragRotate'); goog.provide('ol.interaction.DragRotate');
goog.require('ol.View2D'); goog.require('ol.View2D');
goog.require('ol.ViewHint');
goog.require('ol.interaction.ConditionType'); goog.require('ol.interaction.ConditionType');
goog.require('ol.interaction.Drag'); goog.require('ol.interaction.Drag');
/**
* @define {number} Animation duration.
*/
ol.interaction.DRAGROTATE_ANIMATION_DURATION = 250;
/** /**
* @constructor * @constructor
@@ -46,12 +53,27 @@ ol.interaction.DragRotate.prototype.handleDrag = function(mapBrowserEvent) {
// FIXME supports View2D only // FIXME supports View2D only
goog.asserts.assert(view instanceof ol.View2D); goog.asserts.assert(view instanceof ol.View2D);
map.requestRenderFrame(); map.requestRenderFrame();
view.rotate(map, view.getRotation() - delta); view.rotateWithoutConstraints(map, view.getRotation() - delta);
} }
this.lastAngle_ = theta; this.lastAngle_ = theta;
}; };
/**
* @inheritDoc
*/
ol.interaction.DragRotate.prototype.handleDragEnd = function(mapBrowserEvent) {
var browserEvent = mapBrowserEvent.browserEvent;
var map = mapBrowserEvent.map;
// FIXME supports View2D only
var view = map.getView();
goog.asserts.assert(view instanceof ol.View2D);
view.rotate(map, view.getRotation(), undefined,
ol.interaction.DRAGROTATE_ANIMATION_DURATION);
view.setHint(ol.ViewHint.INTERACTING, -1);
};
/** /**
* @inheritDoc * @inheritDoc
*/ */
@@ -65,6 +87,7 @@ ol.interaction.DragRotate.prototype.handleDragStart =
goog.asserts.assert(view instanceof ol.View2D); goog.asserts.assert(view instanceof ol.View2D);
map.requestRenderFrame(); map.requestRenderFrame();
this.lastAngle_ = undefined; this.lastAngle_ = undefined;
view.setHint(ol.ViewHint.INTERACTING, 1);
return true; return true;
} else { } else {
return false; return false;
@@ -40,7 +40,8 @@ ol.interaction.KeyboardZoom.prototype.handleMapBrowserEvent =
// FIXME works for View2D only // FIXME works for View2D only
var view = map.getView(); var view = map.getView();
goog.asserts.assert(view instanceof ol.View2D); goog.asserts.assert(view instanceof ol.View2D);
view.zoom(map, delta, undefined, ol.interaction.KEYBOARD_ZOOM_DURATION); view.zoomByDelta(map, delta, undefined,
ol.interaction.KEYBOARD_ZOOM_DURATION);
keyEvent.preventDefault(); keyEvent.preventDefault();
mapBrowserEvent.preventDefault(); mapBrowserEvent.preventDefault();
} }
+82 -11
View File
@@ -4,24 +4,63 @@ goog.provide('ol.interaction.MouseWheelZoom');
goog.require('goog.events.MouseWheelEvent'); goog.require('goog.events.MouseWheelEvent');
goog.require('goog.events.MouseWheelHandler.EventType'); goog.require('goog.events.MouseWheelHandler.EventType');
goog.require('goog.math');
goog.require('ol.Coordinate');
goog.require('ol.View2D'); goog.require('ol.View2D');
goog.require('ol.interaction.Interaction'); goog.require('ol.interaction.Interaction');
/**
* @define {number} Animation duration.
*/
ol.interaction.MOUSEWHEELZOOM_ANIMATION_DURATION = 250;
/**
* @define {number} Maximum delta.
*/
ol.interaction.MOUSEWHEELZOOM_MAXDELTA = 1;
/**
* @define {number} Timeout duration.
*/
ol.interaction.MOUSEWHEELZOOM_TIMEOUT_DURATION = 80;
/** /**
* @constructor * @constructor
* @extends {ol.interaction.Interaction} * @extends {ol.interaction.Interaction}
* @param {number} delta The zoom delta applied on each mousewheel.
*/ */
ol.interaction.MouseWheelZoom = function(delta) { ol.interaction.MouseWheelZoom = function() {
goog.base(this);
/** /**
* @private * @private
* @type {number} * @type {number}
*/ */
this.delta_ = delta; this.delta_ = 0;
/**
* @private
* @type {?ol.Coordinate}
*/
this.lastAnchor_ = null;
/**
* @private
* @type {number|undefined}
*/
this.startTime_ = undefined;
/**
* @private
* @type {number|undefined}
*/
this.timeoutId_ = undefined;
goog.base(this);
}; };
goog.inherits(ol.interaction.MouseWheelZoom, ol.interaction.Interaction); goog.inherits(ol.interaction.MouseWheelZoom, ol.interaction.Interaction);
@@ -31,20 +70,52 @@ goog.inherits(ol.interaction.MouseWheelZoom, ol.interaction.Interaction);
*/ */
ol.interaction.MouseWheelZoom.prototype.handleMapBrowserEvent = ol.interaction.MouseWheelZoom.prototype.handleMapBrowserEvent =
function(mapBrowserEvent) { function(mapBrowserEvent) {
if (mapBrowserEvent.type == if (mapBrowserEvent.type ==
goog.events.MouseWheelHandler.EventType.MOUSEWHEEL) { goog.events.MouseWheelHandler.EventType.MOUSEWHEEL) {
var map = mapBrowserEvent.map; var map = mapBrowserEvent.map;
var mouseWheelEvent = /** @type {goog.events.MouseWheelEvent} */ var mouseWheelEvent = /** @type {goog.events.MouseWheelEvent} */
(mapBrowserEvent.browserEvent); (mapBrowserEvent.browserEvent);
goog.asserts.assert(mouseWheelEvent instanceof goog.events.MouseWheelEvent); goog.asserts.assert(mouseWheelEvent instanceof goog.events.MouseWheelEvent);
var anchor = mapBrowserEvent.getCoordinate();
var delta = mouseWheelEvent.deltaY < 0 ? this.delta_ : -this.delta_; this.lastAnchor_ = mapBrowserEvent.getCoordinate();
// FIXME works for View2D only this.delta_ += mouseWheelEvent.deltaY / 3;
var view = map.getView();
goog.asserts.assert(view instanceof ol.View2D); if (!goog.isDef(this.startTime_)) {
map.requestRenderFrame(); this.startTime_ = goog.now();
view.zoom(map, delta, anchor); }
var duration = ol.interaction.MOUSEWHEELZOOM_TIMEOUT_DURATION;
var timeLeft = Math.max(duration - (goog.now() - this.startTime_), 0);
goog.global.clearTimeout(this.timeoutId_);
this.timeoutId_ = goog.global.setTimeout(
goog.bind(this.doZoom_, this, map), timeLeft);
mapBrowserEvent.preventDefault(); mapBrowserEvent.preventDefault();
mouseWheelEvent.preventDefault(); mouseWheelEvent.preventDefault();
} }
}; };
/**
* @private
* @param {ol.Map} map Map.
*/
ol.interaction.MouseWheelZoom.prototype.doZoom_ = function(map) {
var maxDelta = ol.interaction.MOUSEWHEELZOOM_MAXDELTA;
var delta = goog.math.clamp(this.delta_, -maxDelta, maxDelta);
// FIXME works for View2D only
var view = map.getView();
goog.asserts.assert(view instanceof ol.View2D);
map.requestRenderFrame();
view.zoomByDelta(map, -delta, this.lastAnchor_,
ol.interaction.MOUSEWHEELZOOM_ANIMATION_DURATION);
this.delta_ = 0;
this.lastAnchor_ = null;
this.startTime_ = undefined;
this.timeoutId_ = undefined;
};
+14 -1
View File
@@ -8,6 +8,14 @@ goog.require('ol.ViewHint');
goog.require('ol.interaction.Touch'); goog.require('ol.interaction.Touch');
/**
* @define {number} Animation duration.
*/
ol.interaction.TOUCHROTATE_ANIMATION_DURATION = 250;
/**
/** /**
* @constructor * @constructor
@@ -90,7 +98,8 @@ ol.interaction.TouchRotate.prototype.handleTouchMove =
// rotate // rotate
if (this.rotating_) { if (this.rotating_) {
view.rotate(map, view.getRotation() + rotationDelta, anchor); view.rotateWithoutConstraints(map, view.getRotation() + rotationDelta,
anchor);
} }
}; };
@@ -103,6 +112,10 @@ ol.interaction.TouchRotate.prototype.handleTouchEnd =
if (this.targetTouches.length < 2) { if (this.targetTouches.length < 2) {
var map = mapBrowserEvent.map; var map = mapBrowserEvent.map;
var view = map.getView(); var view = map.getView();
if (this.rotating_) {
view.rotate(map, view.getRotation(), undefined,
ol.interaction.TOUCHROTATE_ANIMATION_DURATION);
}
view.setHint(ol.ViewHint.INTERACTING, -1); view.setHint(ol.ViewHint.INTERACTING, -1);
return false; return false;
} else { } else {
+9 -2
View File
@@ -8,6 +8,12 @@ goog.require('ol.ViewHint');
goog.require('ol.interaction.Touch'); goog.require('ol.interaction.Touch');
/**
* @define {number} Animation duration.
*/
ol.interaction.TOUCHZOOM_ANIMATION_DURATION = 250;
/** /**
* @constructor * @constructor
@@ -59,7 +65,7 @@ ol.interaction.TouchZoom.prototype.handleTouchMove =
var anchor = map.getCoordinateFromPixel(centroid); var anchor = map.getCoordinateFromPixel(centroid);
// scale, bypass the resolution constraint // scale, bypass the resolution constraint
view.zoom_(map, view.getResolution() * scaleDelta, anchor); view.zoomWithoutConstraints(map, view.getResolution() * scaleDelta, anchor);
}; };
@@ -73,7 +79,8 @@ ol.interaction.TouchZoom.prototype.handleTouchEnd =
var map = mapBrowserEvent.map; var map = mapBrowserEvent.map;
var view = map.getView(); var view = map.getView();
// take the resolution constraint into account // take the resolution constraint into account
view.zoomToResolution(map, view.getResolution()); view.zoom(map, view.getResolution(), undefined,
ol.interaction.TOUCHZOOM_ANIMATION_DURATION);
view.setHint(ol.ViewHint.INTERACTING, -1); view.setHint(ol.ViewHint.INTERACTING, -1);
return false; return false;
} else { } else {
+3 -6
View File
@@ -941,7 +941,7 @@ ol.Map.createControls_ = function(mapOptions) {
mapOptions.zoomControl : true; mapOptions.zoomControl : true;
if (zoomControl) { if (zoomControl) {
var zoomDelta = goog.isDef(mapOptions.zoomDelta) ? var zoomDelta = goog.isDef(mapOptions.zoomDelta) ?
mapOptions.zoomDelta : 4; mapOptions.zoomDelta : 1;
controls.push(new ol.control.Zoom({ controls.push(new ol.control.Zoom({
delta: zoomDelta delta: zoomDelta
})); }));
@@ -971,7 +971,7 @@ ol.Map.createInteractions_ = function(mapOptions) {
mapOptions.doubleClickZoom : true; mapOptions.doubleClickZoom : true;
if (doubleClickZoom) { if (doubleClickZoom) {
var zoomDelta = goog.isDef(mapOptions.zoomDelta) ? var zoomDelta = goog.isDef(mapOptions.zoomDelta) ?
mapOptions.zoomDelta : 4; mapOptions.zoomDelta : 1;
interactions.push(new ol.interaction.DblClickZoom(zoomDelta)); interactions.push(new ol.interaction.DblClickZoom(zoomDelta));
} }
@@ -1014,10 +1014,7 @@ ol.Map.createInteractions_ = function(mapOptions) {
var mouseWheelZoom = goog.isDef(mapOptions.mouseWheelZoom) ? var mouseWheelZoom = goog.isDef(mapOptions.mouseWheelZoom) ?
mapOptions.mouseWheelZoom : true; mapOptions.mouseWheelZoom : true;
if (mouseWheelZoom) { if (mouseWheelZoom) {
var mouseWheelZoomDelta = interactions.push(new ol.interaction.MouseWheelZoom());
goog.isDef(mapOptions.mouseWheelZoomDelta) ?
mapOptions.mouseWheelZoomDelta : 1;
interactions.push(new ol.interaction.MouseWheelZoom(mouseWheelZoomDelta));
} }
var shiftDragZoom = goog.isDef(mapOptions.shiftDragZoom) ? var shiftDragZoom = goog.isDef(mapOptions.shiftDragZoom) ?
@@ -12,6 +12,8 @@ goog.require('ol.projection');
* @extends {ol.parser.XML} * @extends {ol.parser.XML}
*/ */
ol.parser.ogc.WMTSCapabilities_v1_0_0 = function() { ol.parser.ogc.WMTSCapabilities_v1_0_0 = function() {
this.defaultNamespaceURI = 'http://www.opengis.net/wtms/1.0';
this.errorProperty = 'serviceIdentification';
this.readers = { this.readers = {
'http://www.opengis.net/wmts/1.0': { 'http://www.opengis.net/wmts/1.0': {
'Capabilities': function(node, obj) { 'Capabilities': function(node, obj) {
+20
View File
@@ -37,3 +37,23 @@ ol.RotationConstraint.createSnapToN = function(n) {
} }
}; };
}; };
/**
* @param {number=} opt_tolerance Tolerance.
* @return {ol.RotationConstraintType} Rotation constraint.
*/
ol.RotationConstraint.createSnapToZero = function(opt_tolerance) {
var tolerance = opt_tolerance || 0.1;
return function(rotation, delta) {
if (goog.isDef(rotation)) {
if (Math.abs(rotation + delta) <= tolerance) {
return 0;
} else {
return rotation + delta;
}
} else {
return undefined;
}
};
};
+1 -2
View File
@@ -15,8 +15,7 @@ goog.require('ol.source.ImageSource');
*/ */
ol.source.SingleImageWMS = function(options) { ol.source.SingleImageWMS = function(options) {
var imageUrlFunction = goog.isDef(options.url) ? var imageUrlFunction = goog.isDef(options.url) ?
ol.ImageUrlFunction.createWMSParams( ol.ImageUrlFunction.createWMSParams(options.url, options.params) :
options.url, options.params, options.version) :
ol.ImageUrlFunction.nullImageUrlFunction; ol.ImageUrlFunction.nullImageUrlFunction;
goog.base(this, { goog.base(this, {
-20
View File
@@ -1,21 +1 @@
@exportSymbol ol.source.Stamen @exportSymbol ol.source.Stamen
@exportSymbol ol.source.StamenFlavor
@exportProperty ol.source.StamenFlavor.TERRAIN_BACKGROUND
@exportProperty ol.source.StamenFlavor.TERRAIN_LABELS
@exportProperty ol.source.StamenFlavor.TERRAIN_LINES
@exportProperty ol.source.StamenFlavor.TONER_2010
@exportProperty ol.source.StamenFlavor.TONER_2011
@exportProperty ol.source.StamenFlavor.TONER_2011_LABELS
@exportProperty ol.source.StamenFlavor.TONER_2011_LINES
@exportProperty ol.source.StamenFlavor.TONER_2011_LITE
@exportProperty ol.source.StamenFlavor.TONER_BACKGROUND
@exportProperty ol.source.StamenFlavor.TONER_HYBRID
@exportProperty ol.source.StamenFlavor.TONER_LABELS
@exportProperty ol.source.StamenFlavor.TONER_LINES
@exportProperty ol.source.StamenFlavor.TONER_LITE
@exportSymbol ol.source.StamenProvider
@exportProperty ol.source.StamenProvider.TERRAIN
@exportProperty ol.source.StamenProvider.TONER
@exportProperty ol.source.StamenProvider.WATERCOLOR
+77 -55
View File
@@ -1,61 +1,76 @@
// FIXME Configure minZoom when supported by TileGrid
goog.provide('ol.source.Stamen'); goog.provide('ol.source.Stamen');
goog.provide('ol.source.StamenFlavor');
goog.provide('ol.source.StamenProvider');
goog.require('ol.Attribution'); goog.require('ol.Attribution');
goog.require('ol.source.XYZ'); goog.require('ol.source.XYZ');
/** /**
* @enum {string} * @type {Object.<string, {extension: string, opaque: boolean}>}
*/ */
ol.source.StamenFlavor = { ol.source.StamenLayerConfig = {
TERRAIN_BACKGROUND: 'background', 'terrain': {
TERRAIN_LABELS: 'labels', extension: 'jpg',
TERRAIN_LINES: 'lines', opaque: true
TONER_2010: '2010', },
TONER_2011: '2011', 'terrain-background': {
TONER_2011_LABELS: '2011-labels', extension: 'jpg',
TONER_2011_LINES: '2011-lines', opaque: true
TONER_2011_LITE: '2011-lite', },
TONER_BACKGROUND: 'background', 'terrain-labels': {
TONER_HYBRID: 'hybrid', extension: 'png',
TONER_LABELS: 'labels', opaque: false
TONER_LINES: 'lines', },
TONER_LITE: 'lite' 'terrain-lines': {
extension: 'png',
opaque: false
},
'toner-background': {
extension: 'png',
opaque: true
},
'toner': {
extension: 'png',
opaque: true
},
'toner-hybrid': {
extension: 'png',
opaque: false
},
'toner-labels': {
extension: 'png',
opaque: false
},
'toner-lines': {
extension: 'png',
opaque: false
},
'toner-lite': {
extension: 'png',
opaque: true
},
'watercolor': {
extension: 'jpg',
opaque: true
}
}; };
/** /**
* @enum {string} * @type {Object.<string, {minZoom: number, maxZoom: number}>}
*/ */
ol.source.StamenProvider = { ol.source.StamenProviderConfig = {
TERRAIN: 'terrain', 'terrain': {
TONER: 'toner', minZoom: 4,
WATERCOLOR: 'watercolor' maxZoom: 18
}; },
'toner': {
minZoom: 0,
/** maxZoom: 20
* @type {Object.<string, {type: string, minZoom: number, maxZoom: number}>} },
*/ 'watercolor': {
ol.source.StamenProviderConfig = {}; minZoom: 3,
ol.source.StamenProviderConfig[ol.source.StamenProvider.TERRAIN] = { maxZoom: 16
type: 'jpg', }
minZoom: 4,
maxZoom: 18
};
ol.source.StamenProviderConfig[ol.source.StamenProvider.TONER] = {
type: 'png',
minZoom: 0,
maxZoom: 20
};
ol.source.StamenProviderConfig[ol.source.StamenProvider.WATERCOLOR] = {
type: 'jpg',
minZoom: 3,
maxZoom: 16
}; };
@@ -63,9 +78,9 @@ ol.source.StamenProviderConfig[ol.source.StamenProvider.WATERCOLOR] = {
/** /**
* @constructor * @constructor
* @extends {ol.source.XYZ} * @extends {ol.source.XYZ}
* @param {ol.source.StamenOptions} stamenOptions Stamen options. * @param {ol.source.StamenOptions} options Options.
*/ */
ol.source.Stamen = function(stamenOptions) { ol.source.Stamen = function(options) {
var attribution = new ol.Attribution( var attribution = new ol.Attribution(
'Map tiles by <a href="http://stamen.com">Stamen Design</a>, ' + 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, ' +
@@ -75,18 +90,25 @@ ol.source.Stamen = function(stamenOptions) {
'under ' + 'under ' +
'<a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>.'); '<a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>.');
var layer = stamenOptions.provider; var i = options.layer.indexOf('-');
if (goog.isDef(stamenOptions.flavor)) { var provider = i == -1 ? options.layer : options.layer.slice(0, i);
layer += '-' + stamenOptions.flavor; goog.asserts.assert(provider in ol.source.StamenProviderConfig);
} var providerConfig = ol.source.StamenProviderConfig[provider];
var config = ol.source.StamenProviderConfig[stamenOptions.provider]; goog.asserts.assert(options.layer in ol.source.StamenLayerConfig);
var layerConfig = ol.source.StamenLayerConfig[options.layer];
var url = goog.isDef(options.url) ? options.url :
'http://{a-d}.tile.stamen.com/' + options.layer + '/{z}/{x}/{y}.' +
layerConfig.extension;
goog.base(this, { goog.base(this, {
attributions: [attribution], attributions: [attribution],
maxZoom: config.maxZoom, maxZoom: providerConfig.maxZoom,
opaque: false, // FIXME uncomment the following when tilegrid supports minZoom
url: 'http://{a-d}.tile.stamen.com/' + layer + '/{z}/{x}/{y}.' + config.type //minZoom: providerConfig.minZoom,
opaque: layerConfig.opaque,
url: url
}); });
}; };
+5 -7
View File
@@ -21,25 +21,24 @@ ol.source.TiledWMS = function(tiledWMSOptions) {
if (goog.isDef(tiledWMSOptions.tileGrid)) { if (goog.isDef(tiledWMSOptions.tileGrid)) {
tileGrid = tiledWMSOptions.tileGrid; tileGrid = tiledWMSOptions.tileGrid;
} }
var version = tiledWMSOptions.version;
var tileUrlFunction; var tileUrlFunction;
if (tiledWMSOptions.urls) { if (tiledWMSOptions.urls) {
var tileUrlFunctions = goog.array.map( var tileUrlFunctions = goog.array.map(
tiledWMSOptions.urls, function(url) { tiledWMSOptions.urls, function(url) {
return ol.TileUrlFunction.createWMSParams( return ol.TileUrlFunction.createWMSParams(
url, tiledWMSOptions.params, version); url, tiledWMSOptions.params);
}); });
tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions( tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(
tileUrlFunctions); tileUrlFunctions);
} else if (tiledWMSOptions.url) { } else if (tiledWMSOptions.url) {
tileUrlFunction = ol.TileUrlFunction.createWMSParams( tileUrlFunction = ol.TileUrlFunction.createWMSParams(
tiledWMSOptions.url, tiledWMSOptions.params, version); tiledWMSOptions.url, tiledWMSOptions.params);
} else { } else {
tileUrlFunction = ol.TileUrlFunction.nullTileUrlFunction; tileUrlFunction = ol.TileUrlFunction.nullTileUrlFunction;
} }
var transparent = goog.isDef(tiledWMSOptions.transparent) ? var transparent = goog.isDef(tiledWMSOptions.params['TRANSPARENT']) ?
tiledWMSOptions.transparent : true; tiledWMSOptions.params['TRANSPARENT'] : true;
var extent = tiledWMSOptions.extent; var extent = tiledWMSOptions.extent;
var tileCoordTransform = function(tileCoord, tileGrid, projection) { var tileCoordTransform = function(tileCoord, tileGrid, projection) {
@@ -49,8 +48,7 @@ ol.source.TiledWMS = function(tiledWMSOptions) {
var x = tileCoord.x; var x = tileCoord.x;
var tileExtent = tileGrid.getTileCoordExtent(tileCoord); var tileExtent = tileGrid.getTileCoordExtent(tileCoord);
var projectionExtent = projection.getExtent(); var projectionExtent = projection.getExtent();
var extent = goog.isDef(tiledWMSOptions.extent) ? extent = goog.isDef(extent) ? extent : projectionExtent;
tiledWMSOptions.extent : projectionExtent;
// FIXME do we want a wrapDateLine param? The code below will break maps // FIXME do we want a wrapDateLine param? The code below will break maps
// with projections that do not span the whole world width. // with projections that do not span the whole world width.
if (extent.minX === projectionExtent.minX && if (extent.minX === projectionExtent.minX &&
+14 -12
View File
@@ -7,31 +7,33 @@ goog.provide('ol.source.wms');
* @param {ol.Extent} extent Extent. * @param {ol.Extent} extent Extent.
* @param {ol.Size} size Size. * @param {ol.Size} size Size.
* @param {ol.Projection} projection Projection. * @param {ol.Projection} projection Projection.
* @param {string=} opt_version WMS version. Default is '1.3.0'.
* @return {string} WMS GetMap request URL. * @return {string} WMS GetMap request URL.
*/ */
ol.source.wms.getUrl = ol.source.wms.getUrl =
function(baseUrl, params, extent, size, projection, opt_version) { function(baseUrl, params, extent, size, projection) {
var version = goog.isDef(opt_version) ? opt_version : '1.3.0';
var wms13 = version >= '1.3';
var axisOrientation = projection.getAxisOrientation();
var bboxValues = (wms13 && axisOrientation.substr(0, 2) == 'ne') ?
[extent.minY, extent.minX, extent.maxY, extent.maxX] :
[extent.minX, extent.minY, extent.maxX, extent.maxY];
var baseParams = { var baseParams = {
'SERVICE': 'WMS', 'SERVICE': 'WMS',
'VERSION': version, 'VERSION': '1.3.0',
'REQUEST': 'GetMap', 'REQUEST': 'GetMap',
'FORMAT': 'image/png', 'FORMAT': 'image/png',
'TRANSPARENT': true, 'TRANSPARENT': true,
'WIDTH': size.width, 'WIDTH': size.width,
'HEIGHT': size.height, 'HEIGHT': size.height
'BBOX': bboxValues.join(',')
}; };
goog.object.extend(baseParams, params); goog.object.extend(baseParams, params);
baseParams[wms13 ? 'CRS' : 'SRS'] = projection.getCode();
//TODO: Provide our own appendParams function to avoid this empty string hack //TODO: Provide our own appendParams function to avoid this empty string hack
var stylesParam = 'STYLES'; var stylesParam = 'STYLES';
baseParams[stylesParam] = params[stylesParam] || new String(''); baseParams[stylesParam] = params[stylesParam] || new String('');
var wms13 = baseParams['VERSION'] > '1.3';
baseParams[wms13 ? 'CRS' : 'SRS'] = projection.getCode();
var axisOrientation = projection.getAxisOrientation();
var bboxValues = (wms13 && axisOrientation.substr(0, 2) == 'ne') ?
[extent.minY, extent.minX, extent.maxY, extent.maxX] :
[extent.minX, extent.minY, extent.maxX, extent.maxY];
baseParams['BBOX'] = bboxValues.join(',');
return goog.uri.utils.appendParamsFromMap(baseUrl, baseParams); return goog.uri.utils.appendParamsFromMap(baseUrl, baseParams);
}; };
+2 -3
View File
@@ -74,11 +74,10 @@ ol.TileUrlFunction.createFromTileUrlFunctions = function(tileUrlFunctions) {
/** /**
* @param {string} baseUrl Base URL (may have query data). * @param {string} baseUrl Base URL (may have query data).
* @param {Object.<string, string|number>} params WMS parameters. * @param {Object.<string, string|number>} params WMS parameters.
* @param {string=} opt_version WMS version.
* @return {ol.TileUrlFunctionType} Tile URL function. * @return {ol.TileUrlFunctionType} Tile URL function.
*/ */
ol.TileUrlFunction.createWMSParams = ol.TileUrlFunction.createWMSParams =
function(baseUrl, params, opt_version) { function(baseUrl, params) {
return function(tileCoord, tileGrid, projection) { return function(tileCoord, tileGrid, projection) {
if (goog.isNull(tileCoord)) { if (goog.isNull(tileCoord)) {
return undefined; return undefined;
@@ -86,7 +85,7 @@ ol.TileUrlFunction.createWMSParams =
var size = tileGrid.getTileSize(tileCoord.z); var size = tileGrid.getTileSize(tileCoord.z);
var extent = tileGrid.getTileCoordExtent(tileCoord); var extent = tileGrid.getTileCoordExtent(tileCoord);
return ol.source.wms.getUrl( return ol.source.wms.getUrl(
baseUrl, params, extent, size, projection, opt_version); baseUrl, params, extent, size, projection);
} }
}; };
}; };
+98 -48
View File
@@ -4,6 +4,7 @@
goog.provide('ol.View2D'); goog.provide('ol.View2D');
goog.provide('ol.View2DProperty'); goog.provide('ol.View2DProperty');
goog.require('goog.fx.easing');
goog.require('ol.Constraints'); goog.require('ol.Constraints');
goog.require('ol.Coordinate'); goog.require('ol.Coordinate');
goog.require('ol.Extent'); goog.require('ol.Extent');
@@ -258,49 +259,72 @@ goog.exportProperty(
* @param {ol.Map} map Map. * @param {ol.Map} map Map.
* @param {number|undefined} rotation Rotation. * @param {number|undefined} rotation Rotation.
* @param {ol.Coordinate=} opt_anchor Anchor coordinate. * @param {ol.Coordinate=} opt_anchor Anchor coordinate.
* @param {number=} opt_duration Duration.
*/ */
ol.View2D.prototype.rotate = function(map, rotation, opt_anchor) { ol.View2D.prototype.rotate =
function(map, rotation, opt_anchor, opt_duration) {
rotation = this.constraints_.rotation(rotation, 0); rotation = this.constraints_.rotation(rotation, 0);
if (goog.isDefAndNotNull(opt_anchor)) { this.rotateWithoutConstraints(map, rotation, opt_anchor, opt_duration);
var anchor = opt_anchor; };
var oldCenter = /** @type {!ol.Coordinate} */ (this.getCenter());
var center = new ol.Coordinate(
oldCenter.x - anchor.x, /**
oldCenter.y - anchor.y); * @param {ol.Map} map Map.
center.rotate(rotation - this.getRotation()); * @param {number|undefined} rotation Rotation.
center.x += anchor.x; * @param {ol.Coordinate=} opt_anchor Anchor coordinate.
center.y += anchor.y; * @param {number=} opt_duration Duration.
map.withFrozenRendering(function() { */
this.setCenter(center); ol.View2D.prototype.rotateWithoutConstraints =
function(map, rotation, opt_anchor, opt_duration) {
if (goog.isDefAndNotNull(rotation)) {
var currentRotation = this.getRotation();
var currentCenter = this.getCenter();
if (goog.isDef(currentRotation) && goog.isDef(currentCenter) &&
goog.isDef(opt_duration)) {
map.requestRenderFrame();
map.addPreRenderFunction(ol.animation.rotate({
rotation: currentRotation,
duration: opt_duration,
easing: goog.fx.easing.easeOut
}));
if (goog.isDef(opt_anchor)) {
map.addPreRenderFunction(ol.animation.pan({
source: currentCenter,
duration: opt_duration,
easing: goog.fx.easing.easeOut
}));
}
}
if (goog.isDefAndNotNull(opt_anchor)) {
var anchor = opt_anchor;
var oldCenter = /** @type {!ol.Coordinate} */ (this.getCenter());
var center = new ol.Coordinate(
oldCenter.x - anchor.x,
oldCenter.y - anchor.y);
center.rotate(rotation - this.getRotation());
center.x += anchor.x;
center.y += anchor.y;
map.withFrozenRendering(function() {
this.setCenter(center);
this.setRotation(rotation);
}, this);
} else {
this.setRotation(rotation); this.setRotation(rotation);
}, this); }
} else {
this.setRotation(rotation);
} }
}; };
/** /**
* @private
* @param {ol.Map} map Map. * @param {ol.Map} map Map.
* @param {number|undefined} resolution Resolution to go to. * @param {number|undefined} resolution Resolution to go to.
* @param {ol.Coordinate=} opt_anchor Anchor coordinate. * @param {ol.Coordinate=} opt_anchor Anchor coordinate.
* @param {number=} opt_duration Duration.
*/ */
ol.View2D.prototype.zoom_ = function(map, resolution, opt_anchor) { ol.View2D.prototype.zoom =
if (goog.isDefAndNotNull(resolution) && goog.isDefAndNotNull(opt_anchor)) { function(map, resolution, opt_anchor, opt_duration) {
var anchor = opt_anchor; resolution = this.constraints_.resolution(resolution, 0);
var oldCenter = /** @type {!ol.Coordinate} */ (this.getCenter()); this.zoomWithoutConstraints(map, resolution, opt_anchor, opt_duration);
var oldResolution = this.getResolution();
var x = anchor.x - resolution * (anchor.x - oldCenter.x) / oldResolution;
var y = anchor.y - resolution * (anchor.y - oldCenter.y) / oldResolution;
var center = new ol.Coordinate(x, y);
map.withFrozenRendering(function() {
this.setCenter(center);
this.setResolution(resolution);
}, this);
} else {
this.setResolution(resolution);
}
}; };
@@ -310,17 +334,11 @@ ol.View2D.prototype.zoom_ = function(map, resolution, opt_anchor) {
* @param {ol.Coordinate=} opt_anchor Anchor coordinate. * @param {ol.Coordinate=} opt_anchor Anchor coordinate.
* @param {number=} opt_duration Duration. * @param {number=} opt_duration Duration.
*/ */
ol.View2D.prototype.zoom = function(map, delta, opt_anchor, opt_duration) { ol.View2D.prototype.zoomByDelta =
function(map, delta, opt_anchor, opt_duration) {
var currentResolution = this.getResolution(); var currentResolution = this.getResolution();
if (goog.isDef(currentResolution) && goog.isDef(opt_duration)) {
map.requestRenderFrame();
map.addPreRenderFunction(ol.animation.zoom({
resolution: currentResolution,
duration: opt_duration
}));
}
var resolution = this.constraints_.resolution(currentResolution, delta); var resolution = this.constraints_.resolution(currentResolution, delta);
this.zoom_(map, resolution, opt_anchor); this.zoomWithoutConstraints(map, resolution, opt_anchor, opt_duration);
}; };
@@ -328,10 +346,44 @@ ol.View2D.prototype.zoom = function(map, delta, opt_anchor, opt_duration) {
* @param {ol.Map} map Map. * @param {ol.Map} map Map.
* @param {number|undefined} resolution Resolution to go to. * @param {number|undefined} resolution Resolution to go to.
* @param {ol.Coordinate=} opt_anchor Anchor coordinate. * @param {ol.Coordinate=} opt_anchor Anchor coordinate.
* @param {number=} opt_duration Duration.
*/ */
ol.View2D.prototype.zoomToResolution = function(map, resolution, opt_anchor) { ol.View2D.prototype.zoomWithoutConstraints =
resolution = this.constraints_.resolution(resolution, 0); function(map, resolution, opt_anchor, opt_duration) {
this.zoom_(map, resolution, opt_anchor); if (goog.isDefAndNotNull(resolution)) {
var currentResolution = this.getResolution();
var currentCenter = this.getCenter();
if (goog.isDef(currentResolution) && goog.isDef(currentCenter) &&
goog.isDef(opt_duration)) {
map.requestRenderFrame();
map.addPreRenderFunction(ol.animation.zoom({
resolution: currentResolution,
duration: opt_duration,
easing: goog.fx.easing.easeOut
}));
if (goog.isDef(opt_anchor)) {
map.addPreRenderFunction(ol.animation.pan({
source: currentCenter,
duration: opt_duration,
easing: goog.fx.easing.easeOut
}));
}
}
if (goog.isDefAndNotNull(opt_anchor)) {
var anchor = opt_anchor;
var oldCenter = /** @type {!ol.Coordinate} */ (this.getCenter());
var oldResolution = this.getResolution();
var x = anchor.x - resolution * (anchor.x - oldCenter.x) / oldResolution;
var y = anchor.y - resolution * (anchor.y - oldCenter.y) / oldResolution;
var center = new ol.Coordinate(x, y);
map.withFrozenRendering(function() {
this.setCenter(center);
this.setResolution(resolution);
}, this);
} else {
this.setResolution(resolution);
}
}
}; };
@@ -359,15 +411,13 @@ ol.View2D.createConstraints_ = function(view2DOptions) {
maxResolution = Math.max( maxResolution = Math.max(
projectionExtent.maxX - projectionExtent.minX, projectionExtent.maxX - projectionExtent.minX,
projectionExtent.maxY - projectionExtent.minY) / ol.DEFAULT_TILE_SIZE; projectionExtent.maxY - projectionExtent.minY) / ol.DEFAULT_TILE_SIZE;
// number of steps we want between two data resolutions numZoomLevels = 29;
var numSteps = 4; zoomFactor = 2;
numZoomLevels = 29 * numSteps;
zoomFactor = Math.exp(Math.log(2) / numSteps);
} }
resolutionConstraint = ol.ResolutionConstraint.createSnapToPower( resolutionConstraint = ol.ResolutionConstraint.createSnapToPower(
zoomFactor, maxResolution, numZoomLevels - 1); zoomFactor, maxResolution, numZoomLevels - 1);
} }
// FIXME rotation constraint is not configurable at the moment // FIXME rotation constraint is not configurable at the moment
var rotationConstraint = ol.RotationConstraint.none; var rotationConstraint = ol.RotationConstraint.createSnapToZero();
return new ol.Constraints(resolutionConstraint, rotationConstraint); return new ol.Constraints(resolutionConstraint, rotationConstraint);
}; };
+6 -23
View File
@@ -85,28 +85,11 @@ describe('ol.Map', function() {
}); });
describe('create mousewheel interaction', function() { describe('create mousewheel interaction', function() {
it('creates mousewheel interaction', function() {
beforeEach(function() {
options.mouseWheelZoom = true; options.mouseWheelZoom = true;
}); var interactions = ol.Map.createInteractions_(options);
expect(interactions.getLength()).toEqual(1);
describe('default mouseWheelZoomDelta', function() { expect(interactions.getAt(0)).toBeA(ol.interaction.MouseWheelZoom);
it('create mousewheel interaction with default delta', function() {
var interactions = ol.Map.createInteractions_(options);
expect(interactions.getLength()).toEqual(1);
expect(interactions.getAt(0)).toBeA(ol.interaction.MouseWheelZoom);
expect(interactions.getAt(0).delta_).toEqual(1);
});
});
describe('set mouseWheelZoomDelta', function() {
it('create mousewheel interaction with set delta', function() {
options.mouseWheelZoomDelta = 7;
var interactions = ol.Map.createInteractions_(options);
expect(interactions.getLength()).toEqual(1);
expect(interactions.getAt(0)).toBeA(ol.interaction.MouseWheelZoom);
expect(interactions.getAt(0).delta_).toEqual(7);
});
}); });
}); });
@@ -121,11 +104,11 @@ describe('ol.Map', function() {
var interactions = ol.Map.createInteractions_(options); var interactions = ol.Map.createInteractions_(options);
expect(interactions.getLength()).toEqual(1); expect(interactions.getLength()).toEqual(1);
expect(interactions.getAt(0)).toBeA(ol.interaction.DblClickZoom); expect(interactions.getAt(0)).toBeA(ol.interaction.DblClickZoom);
expect(interactions.getAt(0).delta_).toEqual(4); expect(interactions.getAt(0).delta_).toEqual(1);
}); });
}); });
describe('set mouseWheelZoomDelta', function() { describe('set zoomDelta', function() {
it('create double click interaction with set delta', function() { it('create double click interaction with set delta', function() {
options.zoomDelta = 7; options.zoomDelta = 7;
var interactions = ol.Map.createInteractions_(options); var interactions = ol.Map.createInteractions_(options);
+36
View File
@@ -0,0 +1,36 @@
goog.provide('ol.test.RotationConstraint');
describe('ol.RotationConstraint', function() {
describe('SnapToZero', function() {
it('returns expected rotation value', function() {
var rotationConstraint = ol.RotationConstraint.createSnapToZero(0.3);
expect(rotationConstraint(0.1, 0)).toEqual(0);
expect(rotationConstraint(0.2, 0)).toEqual(0);
expect(rotationConstraint(0.3, 0)).toEqual(0);
expect(rotationConstraint(0.4, 0)).toEqual(0.4);
expect(rotationConstraint(-0.1, 0)).toEqual(0);
expect(rotationConstraint(-0.2, 0)).toEqual(0);
expect(rotationConstraint(-0.3, 0)).toEqual(0);
expect(rotationConstraint(-0.4, 0)).toEqual(-0.4);
expect(rotationConstraint(1, -0.9)).toEqual(0);
expect(rotationConstraint(1, -0.8)).toEqual(0);
// floating-point arithmetic
expect(rotationConstraint(1, -0.7)).not.toEqual(0);
expect(rotationConstraint(1, -0.6)).toEqual(0.4);
expect(rotationConstraint(-1, 0.9)).toEqual(0);
expect(rotationConstraint(-1, 0.8)).toEqual(0);
// floating-point arithmetic
expect(rotationConstraint(-1, 0.7)).not.toEqual(0);
expect(rotationConstraint(-1, 0.6)).toEqual(-0.4);
});
});
});
goog.require('ol.RotationConstraint');
+8 -8
View File
@@ -74,10 +74,10 @@ describe('ol.TileUrlFunction', function() {
'http://wms?foo=bar', {}); 'http://wms?foo=bar', {});
var tileCoord = new ol.TileCoord(1, 0, 0); var tileCoord = new ol.TileCoord(1, 0, 0);
var tileUrl = tileUrlFunction(tileCoord, tileGrid, epsg3857); var tileUrl = tileUrlFunction(tileCoord, tileGrid, epsg3857);
var expected = 'http://wms?foo=bar&SERVICE=WMS&VERSION=1.3.0&' + var expected = 'http://wms?foo=bar&SERVICE=WMS&VERSION=1.3.0&REQUEST=' +
'REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&WIDTH=256&' + 'GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&WIDTH=256&HEIGHT=256&' +
'HEIGHT=256&BBOX=-20037508.342789244%2C20037508.342789244%2C0%2C' + 'STYLES=&CRS=EPSG%3A3857&BBOX=-20037508.342789244%2C2' +
'40075016.68557849&CRS=EPSG%3A3857&STYLES='; '0037508.342789244%2C0%2C40075016.68557849';
expect(tileUrl).toEqual(expected); expect(tileUrl).toEqual(expected);
}); });
it('creates expected URL respecting axis orientation', function() { it('creates expected URL respecting axis orientation', function() {
@@ -86,10 +86,10 @@ describe('ol.TileUrlFunction', function() {
'http://wms?foo=bar', {}); 'http://wms?foo=bar', {});
var tileCoord = new ol.TileCoord(1, 0, 0); var tileCoord = new ol.TileCoord(1, 0, 0);
var tileUrl = tileUrlFunction(tileCoord, tileGrid, epsg4326); var tileUrl = tileUrlFunction(tileCoord, tileGrid, epsg4326);
var expected = 'http://wms?foo=bar&SERVICE=WMS&VERSION=1.3.0&' + var expected = 'http://wms?foo=bar&SERVICE=WMS&VERSION=1.3.0&REQUEST=' +
'REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&WIDTH=256&' + 'GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&WIDTH=256&HEIGHT=256&' +
'HEIGHT=256&BBOX=20037508.342789244%2C-20037508.342789244%2C' + 'STYLES=&CRS=EPSG%3A4326&BBOX=20037508.342789244%2C' +
'40075016.68557849%2C0&CRS=EPSG%3A4326&STYLES='; '-20037508.342789244%2C40075016.68557849%2C0';
expect(tileUrl).toEqual(expected); expect(tileUrl).toEqual(expected);
}); });
}); });
+10
View File
@@ -49,6 +49,16 @@ describe('ol.View2D', function() {
}); });
}); });
describe('create rotation constraint', function() {
it('gives a correct rotation constraint function', function() {
var options = {};
var fn = ol.View2D.createConstraints_(options).rotation;
expect(fn(0.01, 0)).toEqual(0);
expect(fn(0.15, 0)).toEqual(0.15);
});
});
}); });
}); });