diff --git a/bin/check-example.js b/bin/check-example.js
new file mode 100644
index 0000000000..7995118519
--- /dev/null
+++ b/bin/check-example.js
@@ -0,0 +1,30 @@
+//
+// A PhantomJS script used to check that the hosted examples load
+// without errors. This script is executed by the build tool's
+// check-examples target.
+//
+var args = require('system').args;
+if (args.length != 2) {
+ phantom.exit(2);
+}
+var examplePath = args[1];
+var page = require('webpage').create();
+page.onError = function(msg, trace) {
+ var msgStack = ['JavaScript ERROR: ' + msg];
+ if (trace) {
+ msgStack.push('TRACE:');
+ trace.forEach(function(t) {
+ msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function + '")' : ''));
+ });
+ }
+ console.error(msgStack.join('\n'));
+ phantom.exit(1);
+};
+page.open(examplePath, function(s) {
+ var exitCode = 0;
+ if (s != 'success') {
+ exitCode = 1;
+ console.error('PAGE LOAD ERROR');
+ }
+ phantom.exit(exitCode);
+});
diff --git a/build.py b/build.py
index 4fb0b399f5..9494b18f1b 100755
--- a/build.py
+++ b/build.py
@@ -95,7 +95,7 @@ def report_sizes(t):
virtual('all', 'build-all', 'build', 'examples', 'precommit')
-virtual('precommit', 'lint', 'build-all', 'test', 'build', 'build-examples', 'doc')
+virtual('precommit', 'lint', 'build-all', 'test', 'build', 'build-examples', 'check-examples', 'doc')
virtual('build', 'build/ol.css', 'build/ol.js', 'build/ol-simple.js', 'build/ol-whitespace.js')
@@ -263,7 +263,7 @@ def _strip_comments(lines):
yield line
-@target('build/check-requires-timestamp', SRC, INTERNAL_SRC, EXTERNAL_SRC, EXAMPLES_SRC)
+@target('build/check-requires-timestamp', SRC, INTERNAL_SRC, EXTERNAL_SRC, EXAMPLES_SRC, SPEC)
def build_check_requires_timestamp(t):
unused_count = 0
all_provides = set()
@@ -273,7 +273,8 @@ def build_check_requires_timestamp(t):
require_linenos = {}
uses = set()
lineno = 0
- for line in open(filename):
+ lines = open(filename).readlines()
+ for line in lines:
lineno += 1
m = re.match(r'goog.provide\(\'(.*)\'\);', line)
if m:
@@ -283,6 +284,7 @@ def build_check_requires_timestamp(t):
if m:
require_linenos[m.group(1)] = lineno
continue
+ for line in lines:
for require in require_linenos.iterkeys():
if require in line:
uses.add(require)
@@ -378,6 +380,17 @@ def hostexamples(t):
t.cp('examples/example-list.js', 'examples/example-list.xml', 'examples/Jugl.js', 'build/gh-pages/%(BRANCH)s/examples/')
+@target('check-examples', 'hostexamples', phony=True)
+def check_examples(t):
+ directory = 'build/gh-pages/%(BRANCH)s/'
+ examples = ['build/gh-pages/%(BRANCH)s/' + e for e in EXAMPLES]
+ all_examples = examples + \
+ [e + '?mode=simple' for e in examples] + \
+ [e + '?mode=whitespace' for e in examples]
+ for example in all_examples:
+ t.run('%(PHANTOMJS)s', 'bin/check-example.js', example)
+
+
@target(PROJ4JS, PROJ4JS_ZIP)
def proj4js(t):
from zipfile import ZipFile
diff --git a/build/ol-simple.json b/build/ol-simple.json
index ed07e263c8..f6163a713b 100644
--- a/build/ol-simple.json
+++ b/build/ol-simple.json
@@ -1,5 +1,15 @@
{
+ // If ambiguate-properties and disambiguate-properties are set to true
+ // we get function names like "ol_control_Control_prototype$setMap" in
+ // the compiled code when using the SIMPLE compilation. It looks like
+ // "ambiguate-properties" and "disambiguate-properties" are only
+ // appropriate for ADVANCED compilation.
+
+ "ambiguate-properties": false,
+
+ "disambiguate-properties": false,
+
"id": "ol-simple",
"externs": [
diff --git a/build/ol-whitespace.json b/build/ol-whitespace.json
index 5564f8a11e..aebd93fa65 100644
--- a/build/ol-whitespace.json
+++ b/build/ol-whitespace.json
@@ -2,6 +2,17 @@
"id": "ol-whitespace",
+ // If ambiguate-properties and disambiguate-properties are set to true
+ // we get function names like "ol_control_Control_prototype$setMap" in
+ // the compiled code when using the SIMPLE compilation. It looks like
+ // "ambiguate-properties" and "disambiguate-properties" are only
+ // appropriate for ADVANCED compilation. To be sure we also don't
+ // set them for WHITESPACE.
+
+ "ambiguate-properties": false,
+
+ "disambiguate-properties": false,
+
"externs": [
"//json.js",
"externs/bingmaps.js",
diff --git a/css/ol.css b/css/ol.css
index 197439505e..1a2ede8923 100644
--- a/css/ol.css
+++ b/css/ol.css
@@ -28,6 +28,24 @@
width: 100%;
height: 100%;
}
+.ol-scale-line {
+ background: rgba(0,60,136,0.3);
+ border-radius: 4px;
+ bottom: 8px;
+ left: 8px;
+ padding: 2px;
+ position: absolute;
+}
+.ol-scale-line-inner {
+ border: 1px solid #eeeeee;
+ border-top: none;
+ color: #eeeeee;
+ font-size: 10px;
+ font-family: 'Lucida Grande',Verdana,Geneva,Lucida,Arial,Helvetica,sans-serif;
+ text-align: center;
+ margin: 1px;
+ padding: 0px 2px;
+}
.ol-viewport .ol-unselectable {
-webkit-touch-callout: none;
-webkit-user-select: none;
diff --git a/examples/epsg-4326.js b/examples/epsg-4326.js
index 27fc69913b..ba95c06146 100644
--- a/examples/epsg-4326.js
+++ b/examples/epsg-4326.js
@@ -1,21 +1,14 @@
-goog.require('goog.debug.Console');
-goog.require('goog.debug.Logger');
-goog.require('goog.debug.Logger.Level');
goog.require('ol.Collection');
goog.require('ol.Coordinate');
goog.require('ol.Map');
goog.require('ol.RendererHint');
goog.require('ol.View2D');
+goog.require('ol.control.ScaleLineUnits');
goog.require('ol.layer.TileLayer');
goog.require('ol.projection');
goog.require('ol.source.TiledWMS');
-if (goog.DEBUG) {
- goog.debug.Console.autoInstall();
- goog.debug.Logger.getLogger('ol').setLevel(goog.debug.Logger.Level.INFO);
-}
-
var epsg4326 = ol.projection.getFromCode('EPSG:4326');
// We give the single image source a set of resolutions. This prevents the
@@ -47,6 +40,8 @@ var map = new ol.Map({
layers: layers,
// The OSgeo server does not set cross origin headers, so we cannot use WebGL
renderers: [ol.RendererHint.CANVAS, ol.RendererHint.DOM],
+ scaleLineControl: true,
+ scaleLineUnits: ol.control.ScaleLineUnits.DEGREES,
target: 'map',
view: new ol.View2D({
projection: epsg4326,
diff --git a/examples/full-screen.js b/examples/full-screen.js
index e696c2fea1..8ab4ca96ea 100644
--- a/examples/full-screen.js
+++ b/examples/full-screen.js
@@ -15,6 +15,7 @@ var layer = new ol.layer.TileLayer({
var map = new ol.Map({
layers: new ol.Collection([layer]),
renderers: ol.RendererHints.createFromQueryData(),
+ scaleLineControl: true,
target: 'map',
view: new ol.View2D({
center: new ol.Coordinate(0, 0),
diff --git a/examples/two-layers.js b/examples/two-layers.js
index 78451c0669..e325376b7f 100644
--- a/examples/two-layers.js
+++ b/examples/two-layers.js
@@ -1,4 +1,3 @@
-goog.require('ol.BingMapsStyle');
goog.require('ol.Collection');
goog.require('ol.Coordinate');
goog.require('ol.Map');
@@ -14,7 +13,7 @@ var layers = new ol.Collection([
new ol.layer.TileLayer({
source: new ol.source.BingMaps({
key: 'AgtFlPYDnymLEe9zJ5PCkghbNiFZE9aAtTy3mPaEnEBXqLHtFuTcKoZ-miMC3w7R',
- style: ol.BingMapsStyle.AERIAL
+ style: 'Aerial'
})
}),
new ol.layer.TileLayer({
diff --git a/examples/wms-capabilities.html b/examples/wms-capabilities.html
index c119fdc92e..3fde09bcf8 100644
--- a/examples/wms-capabilities.html
+++ b/examples/wms-capabilities.html
@@ -35,7 +35,7 @@
wms capabilities example
-
+
WMS GetCapabilities parsing example
diff --git a/examples/wms-capabilities.js b/examples/wms-capabilities.js
index 09d8ed7061..8566372599 100644
--- a/examples/wms-capabilities.js
+++ b/examples/wms-capabilities.js
@@ -13,7 +13,8 @@ xhr.open('GET', url, true);
xhr.onload = function() {
if (xhr.status == 200) {
result = parser.read(xhr.responseXML);
- document.getElementById('log').innerHTML = window.JSON.stringify(result);
+ document.getElementById('log').innerHTML =
+ window.JSON.stringify(result, undefined, 2);
}
};
xhr.send();
diff --git a/readme.md b/readme.md
index 85925eddb5..b94f437aa9 100644
--- a/readme.md
+++ b/readme.md
@@ -5,7 +5,13 @@
## Hosted Examples
-The examples are hosted on GitHub (as GitHub pages). See http://openlayers.github.com/ol3/master/examples/.
+The examples are hosted on GitHub (as GitHub pages): http://openlayers.github.com/ol3/master/examples/.
+
+By default the examples use the `ol.js` script, which is compiled using Closure Compiler's ADVANVCED mode.
+By appending `?mode=simple` or `?mode=whitespace` to the URL you can make the example page load `ol-simple.js`
+or `ol-whitespace.js` instead of `ol.js`. As their names suggest it, `ol-simple.js` and `ol-whitespace.js`
+are compiled using the SIMPLE and WHITESPACE modes, respectively. For example:
+http://openlayers.github.com/ol3/master/examples/full-screen.html?mode=simple.
## Build OpenLayers 3
@@ -15,7 +21,7 @@ Run build.py:
Windows users should run `build` instead.
-## Run examples locally
+## Run Examples locally
Run the [Plovr](http://plovr.com/) web server with:
@@ -33,18 +39,20 @@ and explore the `examples/` directory, for example by opening
You can turn off compilation by appending `?mode=RAW` to the URL, for example
. (By default mode is `ADVANCED`.)
+Run examples without Plovr:
+
The examples can also be run against the `ol.js` standalone lib, without Plovr,
just like the examples [hosted](http://openlayers.github.com/ol3/master/examples/)
-on GitHub. You will want to run the examples against the standalone lib to verify
-that will work correctly when copied on GitHub (as GitHub pages). Start by executing
-the `hostexamples` build target:
+on GitHub. Start by executing the `hostexamples` build target:
$ ./build.py hostexamples
-This will build `ol.js` and `ol.css`, creates the examples index page, and copy everything to
-`build/gh-pages//`, where `` is the name of the local checked
-out Git branch. You can now open the `build/gh-pages/examples` directory
-in the browser, for example: .
+This will build `ol.js`, `ol-simple.js`, `ol-whitespace.js`, and `ol.css`, create the examples index page,
+and copy everything to `build/gh-pages//`, where `` is the name of the local
+checked out Git branch. You can now open the examples index page in the browser, for example:
+. To make an example use `ol-simple.js` or
+`ol-whitespace.js` instead of `ol.js` append `?mode=simple` or `?mode=whitespace` to the example
+URL.
## Run tests
diff --git a/src/objectliterals.exports b/src/objectliterals.exports
index 3e0d0e4f1a..dd819ccd2d 100644
--- a/src/objectliterals.exports
+++ b/src/objectliterals.exports
@@ -10,10 +10,13 @@
@exportObjectLiteralProperty ol.MapOptions.mouseWheelZoomDelta number|undefined
@exportObjectLiteralProperty ol.MapOptions.renderer ol.RendererHint|undefined
@exportObjectLiteralProperty ol.MapOptions.renderers Array.|undefined
+@exportObjectLiteralProperty ol.MapOptions.scaleLineControl boolean|undefined
+@exportObjectLiteralProperty ol.MapOptions.scaleLineUnits ol.control.ScaleLineUnits|undefined
@exportObjectLiteralProperty ol.MapOptions.shiftDragZoom boolean|undefined
@exportObjectLiteralProperty ol.MapOptions.target Element|string
@exportObjectLiteralProperty ol.MapOptions.touchPan boolean|undefined
-@exportObjectLiteralProperty ol.MapOptions.touchRotateZoom boolean|undefined
+@exportObjectLiteralProperty ol.MapOptions.touchRotate boolean|undefined
+@exportObjectLiteralProperty ol.MapOptions.touchZoom boolean|undefined
@exportObjectLiteralProperty ol.MapOptions.view ol.IView|undefined
@exportObjectLiteralProperty ol.MapOptions.zoomControl boolean|undefined
@exportObjectLiteralProperty ol.MapOptions.zoomDelta number|undefined
@@ -57,6 +60,12 @@
@exportObjectLiteralProperty ol.control.AttributionOptions.map ol.Map|undefined
@exportObjectLiteralProperty ol.control.AttributionOptions.target Element|undefined
+@exportObjectLiteral ol.control.ScaleLineOptions
+@exportObjectLiteralProperty ol.control.ScaleLineOptions.map ol.Map|undefined
+@exportObjectLiteralProperty ol.control.ScaleLineOptions.minWidth number|undefined
+@exportObjectLiteralProperty ol.control.ScaleLineOptions.target Element|undefined
+@exportObjectLiteralProperty ol.control.ScaleLineOptions.units ol.control.ScaleLineUnits|undefined
+
@exportObjectLiteral ol.control.MousePositionOptions
@exportObjectLiteralProperty ol.control.MousePositionOptions.coordinateFormat ol.CoordinateFormatType|undefined
@exportObjectLiteralProperty ol.control.MousePositionOptions.map ol.Map|undefined
@@ -87,7 +96,7 @@
@exportObjectLiteral ol.source.BingMapsOptions
@exportObjectLiteralProperty ol.source.BingMapsOptions.culture string|undefined
@exportObjectLiteralProperty ol.source.BingMapsOptions.key string
-@exportObjectLiteralProperty ol.source.BingMapsOptions.style ol.BingMapsStyle
+@exportObjectLiteralProperty ol.source.BingMapsOptions.style string
@exportObjectLiteral ol.source.DebugTileSourceOptions
@exportObjectLiteralProperty ol.source.DebugTileSourceOptions.extent ol.Extent|undefined
@@ -134,6 +143,7 @@
@exportObjectLiteralProperty ol.tilegrid.TileGridOptions.origins Array.|undefined
@exportObjectLiteralProperty ol.tilegrid.TileGridOptions.resolutions !Array.
@exportObjectLiteralProperty ol.tilegrid.TileGridOptions.tileSize ol.Size|undefined
+@exportObjectLiteralProperty ol.tilegrid.TileGridOptions.tileSizes Array.|undefined
@exportObjectLiteral ol.tilegrid.XYZOptions
@exportObjectLiteralProperty ol.tilegrid.XYZOptions.maxZoom number
diff --git a/src/ol/control/mousepositioncontrol.js b/src/ol/control/mousepositioncontrol.js
index 09abf92d4b..60a667f4a0 100644
--- a/src/ol/control/mousepositioncontrol.js
+++ b/src/ol/control/mousepositioncontrol.js
@@ -8,6 +8,7 @@ goog.require('goog.dom');
goog.require('goog.events');
goog.require('goog.events.EventType');
goog.require('goog.style');
+goog.require('ol.Coordinate');
goog.require('ol.CoordinateFormatType');
goog.require('ol.MapEvent');
goog.require('ol.MapEventType');
@@ -177,7 +178,9 @@ ol.control.MousePosition.prototype.updateHTML_ = function(pixel) {
var map = this.getMap();
var coordinate = map.getCoordinateFromPixel(pixel);
if (!goog.isNull(coordinate)) {
- coordinate = this.transform_(coordinate);
+ var vertex = [coordinate.x, coordinate.y];
+ vertex = this.transform_(vertex, vertex);
+ coordinate = new ol.Coordinate(vertex[0], vertex[1]);
if (goog.isDef(this.coordinateFormat_)) {
html = this.coordinateFormat_(coordinate);
} else {
diff --git a/src/ol/control/scaleline.exports b/src/ol/control/scaleline.exports
new file mode 100644
index 0000000000..6d0cbe1cd1
--- /dev/null
+++ b/src/ol/control/scaleline.exports
@@ -0,0 +1,9 @@
+@exportClass ol.control.ScaleLine ol.control.ScaleLineOptions
+@exportProperty ol.control.ScaleLine.prototype.setMap
+
+@exportSymbol ol.control.ScaleLineUnits
+@exportProperty ol.control.ScaleLineUnits.DEGREES
+@exportProperty ol.control.ScaleLineUnits.IMPERIAL
+@exportProperty ol.control.ScaleLineUnits.NAUTICAL
+@exportProperty ol.control.ScaleLineUnits.METRIC
+@exportProperty ol.control.ScaleLineUnits.US
diff --git a/src/ol/control/scalelinecontrol.js b/src/ol/control/scalelinecontrol.js
new file mode 100644
index 0000000000..a2144e502c
--- /dev/null
+++ b/src/ol/control/scalelinecontrol.js
@@ -0,0 +1,277 @@
+goog.provide('ol.control.ScaleLine');
+goog.provide('ol.control.ScaleLineUnits');
+
+goog.require('goog.dom');
+goog.require('goog.style');
+goog.require('ol.FrameState');
+goog.require('ol.MapEvent');
+goog.require('ol.MapEventType');
+goog.require('ol.ProjectionUnits');
+goog.require('ol.TransformFunction');
+goog.require('ol.control.Control');
+goog.require('ol.projection');
+goog.require('ol.sphere.NORMAL');
+
+
+/**
+ * @enum {string}
+ */
+ol.control.ScaleLineUnits = {
+ DEGREES: 'degrees',
+ IMPERIAL: 'imperial',
+ NAUTICAL: 'nautical',
+ METRIC: 'metric',
+ US: 'us'
+};
+
+
+
+/**
+ * @constructor
+ * @extends {ol.control.Control}
+ * @param {ol.control.ScaleLineOptions=} opt_options Options.
+ */
+ol.control.ScaleLine = function(opt_options) {
+
+ var options = opt_options || {};
+
+ /**
+ * @private
+ * @type {Element}
+ */
+ this.innerElement_ = goog.dom.createDom(goog.dom.TagName.DIV, {
+ 'class': 'ol-scale-line-inner'
+ });
+
+ /**
+ * @private
+ * @type {Element}
+ */
+ this.element_ = goog.dom.createDom(goog.dom.TagName.DIV, {
+ 'class': 'ol-scale-line ol-unselectable'
+ }, this.innerElement_);
+
+ /**
+ * @private
+ * @type {number}
+ */
+ this.minWidth_ = goog.isDef(options.minWidth) ? options.minWidth : 64;
+
+ /**
+ * @private
+ * @type {ol.control.ScaleLineUnits}
+ */
+ this.units_ = goog.isDef(options.units) ?
+ options.units : ol.control.ScaleLineUnits.METRIC;
+
+ /**
+ * @private
+ * @type {Array.}
+ */
+ this.listenerKeys_ = null;
+
+ /**
+ * @private
+ * @type {boolean}
+ */
+ this.renderedVisible_ = false;
+
+ /**
+ * @private
+ * @type {number|undefined}
+ */
+ this.renderedWidth_;
+
+ /**
+ * @private
+ * @type {string}
+ */
+ this.renderedHTML_ = '';
+
+ /**
+ * @private
+ * @type {?ol.TransformFunction}
+ */
+ this.toEPSG4326_ = null;
+
+ goog.base(this, {
+ element: this.element_,
+ map: options.map,
+ target: options.target
+ });
+
+};
+goog.inherits(ol.control.ScaleLine, ol.control.Control);
+
+
+/**
+ * @const
+ * @type {Array.}
+ */
+ol.control.ScaleLine.LEADING_DIGITS = [1, 2, 5];
+
+
+/**
+ * @param {ol.MapEvent} mapEvent Map event.
+ */
+ol.control.ScaleLine.prototype.handleMapPostrender = function(mapEvent) {
+ var frameState = mapEvent.frameState;
+ this.updateElement_(mapEvent.frameState);
+};
+
+
+/**
+ * @inheritDoc
+ */
+ol.control.ScaleLine.prototype.setMap = function(map) {
+ if (!goog.isNull(this.listenerKeys_)) {
+ goog.array.forEach(this.listenerKeys_, goog.events.unlistenByKey);
+ this.listenerKeys_ = null;
+ }
+ goog.base(this, 'setMap', map);
+ if (!goog.isNull(map)) {
+ this.listenerKeys_ = [
+ goog.events.listen(map, ol.MapEventType.POSTRENDER,
+ this.handleMapPostrender, false, this)
+ ];
+ }
+};
+
+
+/**
+ * @param {?ol.FrameState} frameState Frame state.
+ * @private
+ */
+ol.control.ScaleLine.prototype.updateElement_ = function(frameState) {
+
+ if (goog.isNull(frameState)) {
+ if (this.renderedVisible_) {
+ goog.style.showElement(this.element_, false);
+ this.renderedVisible_ = false;
+ }
+ return;
+ }
+
+ var view2DState = frameState.view2DState;
+ var center = view2DState.center;
+ var projection = view2DState.projection;
+ var pointResolution =
+ projection.getPointResolution(view2DState.resolution, center);
+ var projectionUnits = projection.getUnits();
+
+ var cosLatitude;
+ if (projectionUnits == ol.ProjectionUnits.DEGREES &&
+ (this.units_ == ol.control.ScaleLineUnits.METRIC ||
+ this.units_ == ol.control.ScaleLineUnits.IMPERIAL)) {
+
+ // Convert pointResolution from degrees to meters
+ this.toEPSG4326_ = null;
+ cosLatitude = Math.cos(goog.math.toRadians(center.y));
+ pointResolution *= Math.PI * cosLatitude * ol.sphere.NORMAL.radius / 180;
+
+ } else if (projectionUnits == ol.ProjectionUnits.METERS &&
+ this.units_ == ol.control.ScaleLineUnits.DEGREES) {
+
+ // Convert pointResolution from meters to degrees
+ if (goog.isNull(this.toEPSG4326_)) {
+ this.toEPSG4326_ = ol.projection.getTransform(
+ projection, ol.projection.getFromCode('EPSG:4326'));
+ }
+ var vertex = [center.x, center.y];
+ vertex = this.toEPSG4326_(vertex, vertex, 2);
+ cosLatitude = Math.cos(goog.math.toRadians(vertex[1]));
+ pointResolution *= 180 / (Math.PI * cosLatitude * ol.sphere.NORMAL.radius);
+
+ } else {
+
+ this.toEPSG4326_ = null;
+ goog.asserts.assert(
+ ((this.units_ == ol.control.ScaleLineUnits.METRIC ||
+ this.units_ == ol.control.ScaleLineUnits.IMPERIAL) &&
+ projectionUnits == ol.ProjectionUnits.METERS) ||
+ (this.units_ == ol.control.ScaleLineUnits.DEGREES &&
+ projectionUnits == ol.ProjectionUnits.DEGREES));
+
+ }
+
+ var nominalCount = this.minWidth_ * pointResolution;
+ var suffix = '';
+ if (this.units_ == ol.control.ScaleLineUnits.DEGREES) {
+ if (nominalCount < 1 / 60) {
+ suffix = '\u2033'; // seconds
+ pointResolution *= 3600;
+ } else if (nominalCount < 1) {
+ suffix = '\u2032'; // minutes
+ pointResolution *= 60;
+ } else {
+ suffix = '\u00b0'; // degrees
+ }
+ } else if (this.units_ == ol.control.ScaleLineUnits.IMPERIAL) {
+ if (nominalCount < 0.9144) {
+ suffix = 'in';
+ pointResolution /= 0.0254;
+ } else if (nominalCount < 1609.344) {
+ suffix = 'ft';
+ pointResolution /= 0.3048;
+ } else {
+ suffix = 'mi';
+ pointResolution /= 1609.344;
+ }
+ } else if (this.units_ == ol.control.ScaleLineUnits.NAUTICAL) {
+ pointResolution /= 1852;
+ suffix = 'nm';
+ } else if (this.units_ == ol.control.ScaleLineUnits.METRIC) {
+ if (nominalCount < 1) {
+ suffix = 'mm';
+ pointResolution *= 1000;
+ } else if (nominalCount < 1000) {
+ suffix = 'm';
+ } else {
+ suffix = 'km';
+ pointResolution /= 1000;
+ }
+ } else if (this.units_ == ol.control.ScaleLineUnits.US) {
+ if (nominalCount < 0.9144) {
+ suffix = 'in';
+ pointResolution *= 39.37;
+ } else if (nominalCount < 1609.344) {
+ suffix = 'ft';
+ pointResolution /= 0.30480061;
+ } else {
+ suffix = 'mi';
+ pointResolution /= 1609.3472;
+ }
+ } else {
+ goog.asserts.assert(false);
+ }
+
+ var i = 3 * Math.floor(
+ Math.log(this.minWidth_ * pointResolution) / Math.log(10));
+ var count, width;
+ while (true) {
+ count = ol.control.ScaleLine.LEADING_DIGITS[i % 3] *
+ Math.pow(10, Math.floor(i / 3));
+ width = Math.round(count / pointResolution);
+ if (width >= this.minWidth_) {
+ break;
+ }
+ ++i;
+ }
+
+ var html = count + suffix;
+ if (this.renderedHTML_ != html) {
+ this.innerElement_.innerHTML = html;
+ this.renderedHTML_ = html;
+ }
+
+ if (this.renderedWidth_ != width) {
+ this.innerElement_.style.width = width + 'px';
+ this.renderedWidth_ = width;
+ }
+
+ if (!this.renderedVisible_) {
+ goog.style.showElement(this.element_, true);
+ this.renderedVisible_ = true;
+ }
+
+};
diff --git a/src/ol/control/zoomcontrol.js b/src/ol/control/zoomcontrol.js
index 1f5354e3dd..ffacacf55f 100644
--- a/src/ol/control/zoomcontrol.js
+++ b/src/ol/control/zoomcontrol.js
@@ -6,7 +6,6 @@ goog.require('goog.dom');
goog.require('goog.dom.TagName');
goog.require('goog.events');
goog.require('goog.events.EventType');
-goog.require('ol.BrowserFeature');
goog.require('ol.control.Control');
@@ -24,20 +23,23 @@ ol.control.ZOOM_DURATION = 250;
*/
ol.control.Zoom = function(zoomOptions) {
- var eventType = ol.BrowserFeature.HAS_TOUCH ?
- goog.events.EventType.TOUCHEND : goog.events.EventType.CLICK;
-
var inElement = goog.dom.createDom(goog.dom.TagName.A, {
'href': '#zoomIn',
'class': 'ol-zoom-in'
});
- goog.events.listen(inElement, eventType, this.handleIn_, false, this);
+ goog.events.listen(inElement, [
+ goog.events.EventType.TOUCHEND,
+ goog.events.EventType.CLICK
+ ], this.handleIn_, false, this);
var outElement = goog.dom.createDom(goog.dom.TagName.A, {
'href': '#zoomOut',
'class': 'ol-zoom-out'
});
- goog.events.listen(outElement, eventType, this.handleOut_, false, this);
+ goog.events.listen(outElement, [
+ goog.events.EventType.TOUCHEND,
+ goog.events.EventType.CLICK
+ ], this.handleOut_, false, this);
var element = goog.dom.createDom(
goog.dom.TagName.DIV, 'ol-zoom ol-unselectable', inElement, outElement);
diff --git a/src/ol/extent.js b/src/ol/extent.js
index 3606dfc63c..5595382e7c 100644
--- a/src/ol/extent.js
+++ b/src/ol/extent.js
@@ -108,8 +108,10 @@ ol.Extent.prototype.getTopRight = function() {
* @return {ol.Extent} Extent.
*/
ol.Extent.prototype.transform = function(transformFn) {
- var a = transformFn(new ol.Coordinate(this.minX, this.minY));
- var b = transformFn(new ol.Coordinate(this.maxX, this.maxY));
- return new ol.Extent(Math.min(a.x, b.x), Math.min(a.y, b.y),
- Math.max(a.x, b.x), Math.max(a.y, b.y));
+ var input = [this.minX, this.minY, this.maxX, this.maxY];
+ input = transformFn(input, input, 2);
+ return new ol.Extent(Math.min(input[0], input[2]),
+ Math.min(input[1], input[3]),
+ Math.max(input[0], input[2]),
+ Math.max(input[1], input[3]));
};
diff --git a/src/ol/geolocation.js b/src/ol/geolocation.js
index 201257e2eb..5920f92328 100644
--- a/src/ol/geolocation.js
+++ b/src/ol/geolocation.js
@@ -76,11 +76,13 @@ ol.Geolocation.prototype.disposeInternal = function() {
ol.Geolocation.prototype.handleProjectionChanged_ = function() {
var projection = this.getProjection();
if (goog.isDefAndNotNull(projection)) {
- this.transformCoords_ = ol.projection.getTransform(
+ this.transformFn_ = ol.projection.getTransform(
ol.projection.getFromCode('EPSG:4326'), projection);
if (!goog.isNull(this.position_)) {
+ var vertex = [this.position_.x, this.position_.y];
+ vertex = this.transformFn_(vertex, vertex, 2);
this.set(ol.GeolocationProperty.POSITION,
- this.transformCoords_(this.position_));
+ new ol.Coordinate(vertex[0], vertex[1]));
}
}
};
@@ -108,8 +110,10 @@ ol.Geolocation.prototype.positionChange_ = function(position) {
this.set(ol.GeolocationProperty.HEADING, goog.isNull(coords.heading) ?
undefined : goog.math.toRadians(coords.heading));
this.position_ = new ol.Coordinate(coords.longitude, coords.latitude);
+ var vertex = [coords.longitude, coords.latitude];
+ vertex = this.transformFn_(vertex, vertex, 2);
this.set(ol.GeolocationProperty.POSITION,
- this.transformCoords_(this.position_));
+ new ol.Coordinate(vertex[0], vertex[1]));
this.set(ol.GeolocationProperty.SPEED,
goog.isNull(coords.speed) ? undefined : coords.speed);
};
@@ -230,7 +234,9 @@ goog.exportProperty(
/**
* @private
- * @param {ol.Coordinate} coordinate Coordinate.
- * @return {ol.Coordinate} Coordinate.
+ * @param {Array.} input Input coordinate values.
+ * @param {Array.=} opt_output Output array of coordinate values.
+ * @param {number=} opt_dimension Dimension (default is 2).
+ * @return {Array.} Output coordinate values.
*/
-ol.Geolocation.prototype.transformCoords_ = goog.functions.identity;
+ol.Geolocation.prototype.transformFn_ = goog.functions.identity;
diff --git a/src/ol/interaction/dragpaninteraction.js b/src/ol/interaction/dragpaninteraction.js
index 4281be71fb..4827c92e2f 100644
--- a/src/ol/interaction/dragpaninteraction.js
+++ b/src/ol/interaction/dragpaninteraction.js
@@ -80,7 +80,7 @@ ol.interaction.DragPan.prototype.handleDragEnd = function(mapBrowserEvent) {
var map = mapBrowserEvent.map;
var view = map.getView();
- view.setHint(ol.ViewHint.PANNING, -1);
+ view.setHint(ol.ViewHint.INTERACTING, -1);
if (this.kinetic_ && this.kinetic_.end()) {
var distance = this.kinetic_.getDistance();
@@ -111,7 +111,7 @@ ol.interaction.DragPan.prototype.handleDragStart = function(mapBrowserEvent) {
}
var map = mapBrowserEvent.map;
map.requestRenderFrame();
- map.getView().setHint(ol.ViewHint.PANNING, 1);
+ map.getView().setHint(ol.ViewHint.INTERACTING, 1);
return true;
} else {
return false;
diff --git a/src/ol/interaction/touchinteraction.js b/src/ol/interaction/touchinteraction.js
index c71d5997de..1e96fe7ecb 100644
--- a/src/ol/interaction/touchinteraction.js
+++ b/src/ol/interaction/touchinteraction.js
@@ -31,6 +31,7 @@ ol.interaction.Touch = function() {
/**
* @type {Array.