diff --git a/Makefile b/Makefile index 03e40aa7ea..bc4332d56a 100644 --- a/Makefile +++ b/Makefile @@ -86,7 +86,7 @@ check-deps: done ;\ .PHONY: ci -ci: lint build test test-rendering test-node compile-examples check-examples apidoc +ci: lint build test test-rendering compile-examples check-examples apidoc .PHONY: compile-examples compile-examples: build/compiled-examples/all.combined.js @@ -135,10 +135,6 @@ serve: build/test_requires.js build/test_rendering_requires.js test: build/timestamps/node-modules-timestamp build/test_requires.js node tasks/test.js -.PHONY: test-node -test-node: build/timestamps/node-modules-timestamp - ./node_modules/.bin/mocha test/node --fgrep 'has a path that maps to the provide' - .PHONY: test-coverage test-coverage: build/timestamps/node-modules-timestamp node tasks/test-coverage.js @@ -256,7 +252,7 @@ build/timestamps/eslint-timestamp: $(SRC_JS) $(SPEC_JS) $(SPEC_RENDERING_JS) \ build/timestamps/node-modules-timestamp @mkdir -p $(@D) @echo "Running eslint..." - @./node_modules/.bin/eslint tasks test test_rendering src examples + @./node_modules/.bin/eslint --quiet tasks test test_rendering src examples @touch $@ build/timestamps/node-modules-timestamp: package.json diff --git a/changelog/upgrade-notes.md b/changelog/upgrade-notes.md index 82818a00f1..83e3fbd231 100644 --- a/changelog/upgrade-notes.md +++ b/changelog/upgrade-notes.md @@ -18,6 +18,8 @@ A number of internal types have been renamed. This will not affect those who us * rename `ol.CollectionEventType` to `ol.Collection.EventType` * rename `ol.CollectionEvent` to `ol.Collection.Event` + * rename `ol.ViewHint` to `ol.View.Hint` + * rename `ol.ViewProperty` to `ol.View.Property` * rename `ol.render.webgl.imagereplay.shader.Default.Locations` to `ol.render.webgl.imagereplay.defaultshader.Locations` * rename `ol.render.webgl.imagereplay.shader.DefaultFragment` to `ol.render.webgl.imagereplay.defaultshader.Fragment` * rename `ol.render.webgl.imagereplay.shader.DefaultVertex` to `ol.render.webgl.imagereplay.defaultshader.Vertex` @@ -28,6 +30,7 @@ A number of internal types have been renamed. This will not affect those who us * rename `ol.renderer.webgl.tilelayer.shader.Fragment` to `ol.renderer.webgl.tilelayershader.Fragment` * rename `ol.renderer.webgl.tilelayer.shader.Locations` to `ol.renderer.webgl.tilelayershader.Locations` * rename `ol.renderer.webgl.tilelayer.shader.Vertex` to `ol.renderer.webgl.tilelayershader.Vertex` + * rename `ol.webgl.WebGLContextEventType` to `ol.webgl.ContextEventType` * rename `ol.webgl.shader.Fragment` to `ol.webgl.Fragment` * rename `ol.webgl.shader.Vertex` to `ol.webgl.Vertex` diff --git a/examples/custom-interactions.js b/examples/custom-interactions.js index aa3977d0f8..8f01d2e5dd 100644 --- a/examples/custom-interactions.js +++ b/examples/custom-interactions.js @@ -1,3 +1,4 @@ +goog.require('ol'); goog.require('ol.Feature'); goog.require('ol.Map'); goog.require('ol.View'); diff --git a/examples/vector-wfs-getfeature.js b/examples/vector-wfs-getfeature.js index d1905ac0a2..8761aa3b9e 100644 --- a/examples/vector-wfs-getfeature.js +++ b/examples/vector-wfs-getfeature.js @@ -40,16 +40,15 @@ var map = new ol.Map({ }); // generate a GetFeature request -var f = ol.format.ogc.filter; var featureRequest = new ol.format.WFS().writeGetFeature({ srsName: 'EPSG:3857', featureNS: 'http://openstreemap.org', featurePrefix: 'osm', featureTypes: ['water_areas'], outputFormat: 'application/json', - filter: f.and( - f.like('name', 'Mississippi*'), - f.equalTo('waterway', 'riverbank') + filter: ol.format.ogc.filter.and( + ol.format.ogc.filter.like('name', 'Mississippi*'), + ol.format.ogc.filter.equalTo('waterway', 'riverbank') ) }); diff --git a/externs/olx.js b/externs/olx.js index 79739d8aa7..9d4134119e 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -1260,7 +1260,7 @@ olx.control.OverviewMapOptions.prototype.view; * minWidth: (number|undefined), * render: (function(ol.MapEvent)|undefined), * target: (Element|undefined), - * units: (ol.control.ScaleLineUnits|string|undefined)}} + * units: (ol.control.ScaleLine.Units|string|undefined)}} */ olx.control.ScaleLineOptions; @@ -1300,7 +1300,7 @@ olx.control.ScaleLineOptions.prototype.target; /** * Units. Default is `metric`. - * @type {ol.control.ScaleLineUnits|string|undefined} + * @type {ol.control.ScaleLine.Units|string|undefined} * @api stable */ olx.control.ScaleLineOptions.prototype.units; @@ -4190,7 +4190,7 @@ olx.source.TileUTFGridOptions.prototype.url; * reprojectionErrorThreshold: (number|undefined), * state: (ol.source.State|undefined), * tileClass: (function(new: ol.ImageTile, ol.TileCoord, - * ol.TileState, string, ?string, + * ol.Tile.State, string, ?string, * ol.TileLoadFunctionType)|undefined), * tileGrid: (ol.tilegrid.TileGrid|undefined), * tileLoadFunction: (ol.TileLoadFunctionType|undefined), @@ -4275,7 +4275,7 @@ olx.source.TileImageOptions.prototype.state; /** * Class used to instantiate image tiles. Default is {@link ol.ImageTile}. * @type {function(new: ol.ImageTile, ol.TileCoord, - * ol.TileState, string, ?string, + * ol.Tile.State, string, ?string, * ol.TileLoadFunctionType)|undefined} * @api */ @@ -4359,7 +4359,7 @@ olx.source.TileImageOptions.prototype.wrapX; * projection: ol.ProjectionLike, * state: (ol.source.State|undefined), * tileClass: (function(new: ol.VectorTile, ol.TileCoord, - * ol.TileState, string, ol.format.Feature, + * ol.Tile.State, string, ol.format.Feature, * ol.TileLoadFunctionType)|undefined), * tileGrid: (ol.tilegrid.TileGrid|undefined), * tileLoadFunction: (ol.TileLoadFunctionType|undefined), @@ -4424,7 +4424,7 @@ olx.source.VectorTileOptions.prototype.state; /** * Class used to instantiate image tiles. Default is {@link ol.VectorTile}. * @type {function(new: ol.VectorTile, ol.TileCoord, - * ol.TileState, string, ol.format.Feature, + * ol.Tile.State, string, ol.format.Feature, * ol.TileLoadFunctionType)|undefined} * @api */ @@ -5922,7 +5922,7 @@ olx.source.VectorOptions.prototype.wrapX; * tileLoadFunction: (ol.TileLoadFunctionType|undefined), * urls: (Array.|undefined), * tileClass: (function(new: ol.ImageTile, ol.TileCoord, - * ol.TileState, string, ?string, + * ol.Tile.State, string, ?string, * ol.TileLoadFunctionType)|undefined), * wrapX: (boolean|undefined)}} */ @@ -6017,7 +6017,7 @@ olx.source.WMTSOptions.prototype.style; /** * Class used to instantiate image tiles. Default is {@link ol.ImageTile}. * @type {function(new: ol.ImageTile, ol.TileCoord, - * ol.TileState, string, ?string, + * ol.Tile.State, string, ?string, * ol.TileLoadFunctionType)|undefined} * @api */ diff --git a/package.json b/package.json index 292a67b02d..13f21d2fc9 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,6 @@ "postinstall": "closure-util update", "start": "node tasks/serve.js", "pretest": "eslint tasks test test_rendering src examples", - "test-node": "mocha test/node", "test": "node tasks/test.js", "debug-server": "node tasks/serve-lib.js" }, @@ -35,7 +34,6 @@ "browserify": "13.1.0", "closure-util": "1.15.0", "derequire": "2.0.3", - "eslint-plugin-openlayers-internal": "file:rules", "fs-extra": "0.30.0", "glob": "7.0.5", "handlebars": "4.0.5", @@ -57,6 +55,7 @@ "debounce": "^1.0.0", "eslint": "3.2.2", "eslint-config-openlayers": "5.0.0", + "eslint-plugin-openlayers-internal": "2.1.0", "expect.js": "0.3.1", "gaze": "^1.0.0", "istanbul": "0.4.4", @@ -98,8 +97,11 @@ ], "no-constant-condition": 0, "openlayers-internal/no-duplicate-requires": 2, + "openlayers-internal/no-missing-requires": 1, "openlayers-internal/no-unused-requires": 2, + "openlayers-internal/one-provide": 1, "openlayers-internal/requires-first": 2, + "openlayers-internal/valid-provide": 2, "openlayers-internal/valid-requires": 2 } }, diff --git a/rules/index.js b/rules/index.js index f625cac35b..2b38047b87 100644 --- a/rules/index.js +++ b/rules/index.js @@ -3,8 +3,11 @@ module.exports = { rules: { 'no-duplicate-requires': require('./no-duplicate-requires').rule, + 'no-missing-requires': require('./no-missing-requires').rule, 'no-unused-requires': require('./no-unused-requires').rule, + 'one-provide': require('./one-provide').rule, 'requires-first': require('./requires-first').rule, + 'valid-provide': require('./valid-provide').rule, 'valid-requires': require('./valid-requires').rule } }; diff --git a/rules/no-missing-requires.js b/rules/no-missing-requires.js new file mode 100644 index 0000000000..e0ef07dda4 --- /dev/null +++ b/rules/no-missing-requires.js @@ -0,0 +1,90 @@ +'use strict'; + +const util = require('./util'); + +/** + * Unfortunately fragile RegExp to follow. Here is the logic: + * + * 1. check if a name looks like a const (ol.foo.BOO_HOO must have a "_") + * if so, require the "namespace" (ol.foo) + * 2. check if a name looks like a class (ol.foo.Bar or ol.foo.XYZ) + * if so, require the class (ol.foo.Bar) + * 3. otherwise, lop off the last part of a name and require the rest + * (e.g. ol.foo.bar would require ol.foo) + */ + +const CONST_RE = /^(ol(\.[a-z]\w*)*)\.[A-Z]+_([_A-Z])+$/; +const CLASS_RE = /^(ol(\.[a-z]\w*)*\.[A-Z]\w*)(\.\w+)*$/; + +exports.rule = { + meta: { + docs: { + description: 'ensure there are goog.require() calls for all used symbols' + }, + fixable: 'code' + }, + + create: function(context) { + const defined = {}; + + return { + + ExpressionStatement: function(statement) { + if (util.isRequireStatement(statement) || util.isProvideStatement(statement)) { + const expression = statement.expression; + const arg = expression.arguments[0]; + if (!arg || !arg.value) { + return; + } + defined[arg.value] = true; + } + }, + + MemberExpression: function(expression) { + const parent = expression.parent; + if (parent.type !== 'MemberExpression') { + const name = util.getName(expression); + if (name && name.startsWith('ol.')) { + // check if the name looks like a const + let match = name.match(CONST_RE); + if (match) { + if (!defined[match[1]]) { + context.report(expression, `Missing goog.require('${match[1]}')`); + } + return; + } + // check if the name looks like a class + match = name.match(CLASS_RE); + if (match) { + const className = match[1]; + const parts = className.split('.'); + const lastPart = parts[parts.length - 1]; + if (lastPart.toUpperCase() === lastPart) { + // unfortunately ambiguous: + // ol.has.WEBGL -> require('ol.has') + // ol.source.XYZ -> require('ol.source.XYZ') + const objectName = parts.slice(0, -1).join('.'); + if (!defined[className] && !defined[objectName]) { + context.report(expression, `Missing goog.require('${className}') or goog.require('${objectName}')`); + } + return; + } + if (!defined[className]) { + context.report(expression, `Missing goog.require('${className}')`); + } + return; + } + // otherwise, assume the object should be required + const parts = name.split('.'); + parts.pop(); + const objectName = parts.join('.'); + if (!defined[objectName]) { + context.report(expression, `Missing goog.require('${objectName}')`); + } + } + } + } + + }; + } +}; diff --git a/rules/no-unused-requires.js b/rules/no-unused-requires.js index 2436bb4447..13ba97ca67 100644 --- a/rules/no-unused-requires.js +++ b/rules/no-unused-requires.js @@ -2,25 +2,6 @@ const util = require('./util'); -function getName(node) { - if (node.type !== 'MemberExpression') { - return; - } - if (node.property.type !== 'Identifier' || node.property.computed) { - return; - } - let objectName; - if (node.object.type === 'Identifier' && !node.object.computed) { - objectName = node.object.name; - } else if (node.object.type === 'MemberExpression' && !node.object.computed) { - objectName = getName(node.object); - } - if (!objectName) { - return; - } - return `${objectName}.${node.property.name}`; -} - exports.rule = { meta: { docs: { @@ -48,20 +29,15 @@ exports.rule = { } const name = arg.value; - const ancestors = context.getAncestors(); - const parent = ancestors[ancestors.length - 1]; - if (!parent) { - return; - } - requireStatements[name] = statement; } }, MemberExpression: function(node) { - const name = getName(node); + const name = util.getName(node); if (name in requireStatements) { - const requiredAncestor = context.getAncestors().some(ancestorNode => !!requireStatements[getName(ancestorNode)]); + const requiredAncestor = context.getAncestors().some( + ancestorNode => !!requireStatements[util.getName(ancestorNode)]); if (!requiredAncestor) { usedNames[name] = true; } @@ -73,7 +49,8 @@ exports.rule = { if (name in requireStatements) { const ancestors = context.getAncestors(); if (ancestors.length && ancestors[0].type === 'MemberExpression') { - const requiredAncestor = context.getAncestors().some(ancestorNode => !!requireStatements[getName(ancestorNode)]); + const requiredAncestor = ancestors.some( + ancestorNode => !!requireStatements[util.getName(ancestorNode)]); if (!requiredAncestor) { usedNames[name] = true; } diff --git a/rules/one-provide.js b/rules/one-provide.js new file mode 100644 index 0000000000..092a88ee2e --- /dev/null +++ b/rules/one-provide.js @@ -0,0 +1,28 @@ +'use strict'; + +const util = require('./util'); + +exports.rule = { + meta: { + docs: { + description: 'disallow multiple goog.provide() calls' + } + }, + + create: function(context) { + let hasProvide = false; + + return { + ExpressionStatement: function(statement) { + if (util.isProvideStatement(statement)) { + if (hasProvide) { + const name = statement.expression.arguments[0].value; + context.report(statement, `Extra goog.provide('${name}')`); + } else { + hasProvide = true; + } + } + } + }; + } +}; diff --git a/rules/package.json b/rules/package.json index 5ff7b3b4db..bdd4291e0e 100644 --- a/rules/package.json +++ b/rules/package.json @@ -1,6 +1,11 @@ { "name": "eslint-plugin-openlayers-internal", - "version": "1.0.0", + "version": "2.1.0", "description": "Custom ESLint rules for the OpenLayers project", - "main": "index.js" + "main": "index.js", + "repository": { + "type": "git", + "url": "git://github.com/openlayers/ol3.git" + }, + "license": "BSD-2-Clause" } diff --git a/rules/util.js b/rules/util.js index 605a5d7a9e..a7c163b92b 100644 --- a/rules/util.js +++ b/rules/util.js @@ -28,3 +28,22 @@ exports.isRequireExpression = function(node) { exports.isRequireStatement = function(node) { return isGoogStatement(node, 'require'); }; + +var getName = exports.getName = function(node) { + if (node.type !== 'MemberExpression') { + return; + } + if (node.property.type !== 'Identifier' || node.property.computed) { + return; + } + let objectName; + if (node.object.type === 'Identifier' && !node.object.computed) { + objectName = node.object.name; + } else if (node.object.type === 'MemberExpression' && !node.object.computed) { + objectName = getName(node.object); + } + if (!objectName) { + return; + } + return `${objectName}.${node.property.name}`; +}; diff --git a/rules/valid-provide.js b/rules/valid-provide.js new file mode 100644 index 0000000000..9d11bed23b --- /dev/null +++ b/rules/valid-provide.js @@ -0,0 +1,72 @@ +'use strict'; + +const path = require('path'); +const util = require('./util'); + +function longestCommonPrefix(path1, path2) { + const parts1 = path.resolve(path1).split(path.sep); + const parts2 = path.resolve(path2).split(path.sep); + const common = []; + for (let i = 0, ii = parts1.length; i < ii; ++i) { + if (parts1[i] === parts2[i]) { + common.push(parts1[i]); + } else { + break; + } + } + return common.join(path.sep); +} + +exports.rule = { + meta: { + docs: { + description: 'require the first goog.provide() has an arg named like the file path' + } + }, + + create: function(context) { + let gotFirst = false; + return { + CallExpression: function(expression) { + if (gotFirst) { + return; + } + if (util.isProvideExpression(expression)) { + gotFirst = true; + const parent = expression.parent; + if (parent.type !== 'ExpressionStatement') { + return context.report(expression, 'Expected goog.provide() to in an expression statement'); + } + + if (parent.parent.type !== 'Program') { + return context.report(expression, 'Expected goog.provide() to be at the top level'); + } + + if (expression.arguments.length !== 1) { + return context.report(expression, 'Expected one argument for goog.require()'); + } + + const arg = expression.arguments[0]; + if (arg.type !== 'Literal' || !arg.value || typeof arg.value !== 'string') { + return context.report(expression, 'Expected goog.require() to be called with a string'); + } + + const filePath = context.getFilename(); + const sourceRoot = path.join(longestCommonPrefix(__dirname, filePath), 'src'); + const requirePath = path.relative(sourceRoot, filePath); + let ext; + if (path.basename(requirePath) === 'index.js') { + ext = path.sep + 'index.js'; + } else { + ext = '.js'; + } + const name = arg.value; + const expectedPath = name.split('.').join(path.sep) + ext; + if (expectedPath.toLowerCase() !== requirePath.toLowerCase()) { + return context.report(expression, `Expected goog.provide('${name}') to be like ${requirePath}`); + } + } + } + }; + } +}; diff --git a/rules/valid-requires.js b/rules/valid-requires.js index e98a4e00aa..3643abc629 100644 --- a/rules/valid-requires.js +++ b/rules/valid-requires.js @@ -13,13 +13,12 @@ exports.rule = { return { CallExpression: function(expression) { if (util.isRequireExpression(expression)) { - const ancestors = context.getAncestors(); - const parent = ancestors[ancestors.length - 1]; + const parent = expression.parent; if (parent.type !== 'ExpressionStatement') { return context.report(expression, 'Expected goog.require() to in an expression statement'); } - if (ancestors.length !== 2) { + if (parent.parent.type !== 'Program') { return context.report(expression, 'Expected goog.require() to be at the top level'); } diff --git a/src/ol/animation.js b/src/ol/animation.js index d8ccfa4dda..b32d4de422 100644 --- a/src/ol/animation.js +++ b/src/ol/animation.js @@ -1,7 +1,7 @@ goog.provide('ol.animation'); goog.require('ol'); -goog.require('ol.ViewHint'); +goog.require('ol.View'); goog.require('ol.coordinate'); goog.require('ol.easing'); @@ -28,14 +28,14 @@ ol.animation.bounce = function(options) { function(map, frameState) { if (frameState.time < start) { frameState.animate = true; - frameState.viewHints[ol.ViewHint.ANIMATING] += 1; + frameState.viewHints[ol.View.Hint.ANIMATING] += 1; return true; } else if (frameState.time < start + duration) { var delta = easing((frameState.time - start) / duration); var deltaResolution = resolution - frameState.viewState.resolution; frameState.animate = true; frameState.viewState.resolution += delta * deltaResolution; - frameState.viewHints[ol.ViewHint.ANIMATING] += 1; + frameState.viewHints[ol.View.Hint.ANIMATING] += 1; return true; } else { return false; @@ -67,7 +67,7 @@ ol.animation.pan = function(options) { function(map, frameState) { if (frameState.time < start) { frameState.animate = true; - frameState.viewHints[ol.ViewHint.ANIMATING] += 1; + frameState.viewHints[ol.View.Hint.ANIMATING] += 1; return true; } else if (frameState.time < start + duration) { var delta = 1 - easing((frameState.time - start) / duration); @@ -76,7 +76,7 @@ ol.animation.pan = function(options) { frameState.animate = true; frameState.viewState.center[0] += delta * deltaX; frameState.viewState.center[1] += delta * deltaY; - frameState.viewHints[ol.ViewHint.ANIMATING] += 1; + frameState.viewHints[ol.View.Hint.ANIMATING] += 1; return true; } else { return false; @@ -109,7 +109,7 @@ ol.animation.rotate = function(options) { function(map, frameState) { if (frameState.time < start) { frameState.animate = true; - frameState.viewHints[ol.ViewHint.ANIMATING] += 1; + frameState.viewHints[ol.View.Hint.ANIMATING] += 1; return true; } else if (frameState.time < start + duration) { var delta = 1 - easing((frameState.time - start) / duration); @@ -123,7 +123,7 @@ ol.animation.rotate = function(options) { ol.coordinate.rotate(center, deltaRotation); ol.coordinate.add(center, anchor); } - frameState.viewHints[ol.ViewHint.ANIMATING] += 1; + frameState.viewHints[ol.View.Hint.ANIMATING] += 1; return true; } else { return false; @@ -153,7 +153,7 @@ ol.animation.zoom = function(options) { function(map, frameState) { if (frameState.time < start) { frameState.animate = true; - frameState.viewHints[ol.ViewHint.ANIMATING] += 1; + frameState.viewHints[ol.View.Hint.ANIMATING] += 1; return true; } else if (frameState.time < start + duration) { var delta = 1 - easing((frameState.time - start) / duration); @@ -161,7 +161,7 @@ ol.animation.zoom = function(options) { sourceResolution - frameState.viewState.resolution; frameState.animate = true; frameState.viewState.resolution += delta * deltaResolution; - frameState.viewHints[ol.ViewHint.ANIMATING] += 1; + frameState.viewHints[ol.View.Hint.ANIMATING] += 1; return true; } else { return false; diff --git a/src/ol/assertionerror.js b/src/ol/assertionerror.js new file mode 100644 index 0000000000..cc3c723885 --- /dev/null +++ b/src/ol/assertionerror.js @@ -0,0 +1,36 @@ +goog.provide('ol.AssertionError'); + +goog.require('ol'); + +/** + * Error object thrown when an assertion failed. This is an ECMA-262 Error, + * extended with a `code` property. + * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error} + * @constructor + * @extends {Error} + * @implements {oli.AssertionError} + * @param {number} code Error code. + */ +ol.AssertionError = function(code) { + + /** + * @type {string} + */ + this.message = 'Assertion failed. See ' + + (ol.VERSION ? 'http://openlayers.org/en/' + ol.VERSION.split('-')[0] : '') + + '/doc/errors/#' + code + ' for details.'; + + /** + * Error code. The meaning of the code can be found on + * {@link http://openlayers.org/en/latest/errors.html} (replace `latest` with + * the version found in the OpenLayers script's header comment if a version + * other than the latest is used). + * @type {number} + * @api + */ + this.code = code; + + this.name = 'AssertionError'; + +}; +ol.inherits(ol.AssertionError, Error); diff --git a/src/ol/asserts.js b/src/ol/asserts.js new file mode 100644 index 0000000000..d9cf9c2339 --- /dev/null +++ b/src/ol/asserts.js @@ -0,0 +1,15 @@ +goog.provide('ol.asserts'); + +goog.require('ol'); +goog.require('ol.AssertionError'); + + +/** + * @param {*} assertion Assertion we expected to be truthy. + * @param {number} errorCode Error code. + */ +ol.asserts.assert = function(assertion, errorCode) { + if (!assertion) { + throw new ol.AssertionError(errorCode); + } +}; diff --git a/src/ol/color.js b/src/ol/color.js index 178bca7521..69a39c4bef 100644 --- a/src/ol/color.js +++ b/src/ol/color.js @@ -159,7 +159,7 @@ ol.color.fromStringInternal_ = function(s) { if (ol.color.hexColorRe_.exec(s)) { // hex var n = s.length - 1; // number of hex digits - ol.assert(n == 3 || n == 6, 54); // Hex color should have 3 or 6 digits + ol.asserts.assert(n == 3 || n == 6, 54); // Hex color should have 3 or 6 digits var d = n == 3 ? 1 : 2; // number of digits per channel r = parseInt(s.substr(1 + 0 * d, d), 16); g = parseInt(s.substr(1 + 1 * d, d), 16); @@ -183,7 +183,7 @@ ol.color.fromStringInternal_ = function(s) { b = Number(match[3]); color = ol.color.normalize([r, g, b, 1]); } else { - ol.assert(false, 14); // Invalid color + ol.asserts.assert(false, 14); // Invalid color } return /** @type {ol.Color} */ (color); }; diff --git a/src/ol/control/overviewmap.js b/src/ol/control/overviewmap.js index 7d368eb373..3e16a5e616 100644 --- a/src/ol/control/overviewmap.js +++ b/src/ol/control/overviewmap.js @@ -1,7 +1,5 @@ goog.provide('ol.control.OverviewMap'); -goog.require('ol.events'); -goog.require('ol.events.EventType'); goog.require('ol'); goog.require('ol.Collection'); goog.require('ol.Map'); @@ -10,11 +8,13 @@ goog.require('ol.Object'); goog.require('ol.ObjectEventType'); goog.require('ol.Overlay'); goog.require('ol.OverlayPositioning'); -goog.require('ol.ViewProperty'); +goog.require('ol.View'); goog.require('ol.control.Control'); goog.require('ol.coordinate'); goog.require('ol.css'); goog.require('ol.dom'); +goog.require('ol.events'); +goog.require('ol.events.EventType'); goog.require('ol.extent'); @@ -211,7 +211,7 @@ ol.control.OverviewMap.prototype.handleMapPropertyChange_ = function(event) { */ ol.control.OverviewMap.prototype.bindView_ = function(view) { ol.events.listen(view, - ol.Object.getChangeEventType(ol.ViewProperty.ROTATION), + ol.Object.getChangeEventType(ol.View.Property.ROTATION), this.handleRotationChanged_, this); }; @@ -223,7 +223,7 @@ ol.control.OverviewMap.prototype.bindView_ = function(view) { */ ol.control.OverviewMap.prototype.unbindView_ = function(view) { ol.events.unlisten(view, - ol.Object.getChangeEventType(ol.ViewProperty.ROTATION), + ol.Object.getChangeEventType(ol.View.Property.ROTATION), this.handleRotationChanged_, this); }; diff --git a/src/ol/control/scaleline.js b/src/ol/control/scaleline.js index 2b28824552..9d3171eb3e 100644 --- a/src/ol/control/scaleline.js +++ b/src/ol/control/scaleline.js @@ -1,37 +1,15 @@ goog.provide('ol.control.ScaleLine'); -goog.provide('ol.control.ScaleLineUnits'); -goog.require('ol.events'); goog.require('ol'); goog.require('ol.Object'); +goog.require('ol.asserts'); goog.require('ol.control.Control'); goog.require('ol.css'); +goog.require('ol.events'); goog.require('ol.proj.METERS_PER_UNIT'); goog.require('ol.proj.Units'); -/** - * @enum {string} - */ -ol.control.ScaleLineProperty = { - UNITS: 'units' -}; - - -/** - * Units for the scale line. Supported values are `'degrees'`, `'imperial'`, - * `'nautical'`, `'metric'`, `'us'`. - * @enum {string} - */ -ol.control.ScaleLineUnits = { - DEGREES: 'degrees', - IMPERIAL: 'imperial', - NAUTICAL: 'nautical', - METRIC: 'metric', - US: 'us' -}; - - /** * @classdesc * A control displaying rough y-axis distances, calculated for the center of the @@ -107,11 +85,11 @@ ol.control.ScaleLine = function(opt_options) { }); ol.events.listen( - this, ol.Object.getChangeEventType(ol.control.ScaleLineProperty.UNITS), + this, ol.Object.getChangeEventType(ol.control.ScaleLine.Property.UNITS), this.handleUnitsChanged_, this); - this.setUnits(/** @type {ol.control.ScaleLineUnits} */ (options.units) || - ol.control.ScaleLineUnits.METRIC); + this.setUnits(/** @type {ol.control.ScaleLine.Units} */ (options.units) || + ol.control.ScaleLine.Units.METRIC); }; ol.inherits(ol.control.ScaleLine, ol.control.Control); @@ -126,14 +104,14 @@ ol.control.ScaleLine.LEADING_DIGITS = [1, 2, 5]; /** * Return the units to use in the scale line. - * @return {ol.control.ScaleLineUnits|undefined} The units to use in the scale + * @return {ol.control.ScaleLine.Units|undefined} The units to use in the scale * line. * @observable * @api stable */ ol.control.ScaleLine.prototype.getUnits = function() { - return /** @type {ol.control.ScaleLineUnits|undefined} */ ( - this.get(ol.control.ScaleLineProperty.UNITS)); + return /** @type {ol.control.ScaleLine.Units|undefined} */ ( + this.get(ol.control.ScaleLine.Property.UNITS)); }; @@ -164,12 +142,12 @@ ol.control.ScaleLine.prototype.handleUnitsChanged_ = function() { /** * Set the units to use in the scale line. - * @param {ol.control.ScaleLineUnits} units The units to use in the scale line. + * @param {ol.control.ScaleLine.Units} units The units to use in the scale line. * @observable * @api stable */ ol.control.ScaleLine.prototype.setUnits = function(units) { - this.set(ol.control.ScaleLineProperty.UNITS, units); + this.set(ol.control.ScaleLine.Property.UNITS, units); }; @@ -197,7 +175,7 @@ ol.control.ScaleLine.prototype.updateElement_ = function() { var nominalCount = this.minWidth_ * pointResolution; var suffix = ''; var units = this.getUnits(); - if (units == ol.control.ScaleLineUnits.DEGREES) { + if (units == ol.control.ScaleLine.Units.DEGREES) { var metersPerDegree = ol.proj.METERS_PER_UNIT[ol.proj.Units.DEGREES]; pointResolution /= metersPerDegree; if (nominalCount < metersPerDegree / 60) { @@ -209,7 +187,7 @@ ol.control.ScaleLine.prototype.updateElement_ = function() { } else { suffix = '\u00b0'; // degrees } - } else if (units == ol.control.ScaleLineUnits.IMPERIAL) { + } else if (units == ol.control.ScaleLine.Units.IMPERIAL) { if (nominalCount < 0.9144) { suffix = 'in'; pointResolution /= 0.0254; @@ -220,10 +198,10 @@ ol.control.ScaleLine.prototype.updateElement_ = function() { suffix = 'mi'; pointResolution /= 1609.344; } - } else if (units == ol.control.ScaleLineUnits.NAUTICAL) { + } else if (units == ol.control.ScaleLine.Units.NAUTICAL) { pointResolution /= 1852; suffix = 'nm'; - } else if (units == ol.control.ScaleLineUnits.METRIC) { + } else if (units == ol.control.ScaleLine.Units.METRIC) { if (nominalCount < 1) { suffix = 'mm'; pointResolution *= 1000; @@ -233,7 +211,7 @@ ol.control.ScaleLine.prototype.updateElement_ = function() { suffix = 'km'; pointResolution /= 1000; } - } else if (units == ol.control.ScaleLineUnits.US) { + } else if (units == ol.control.ScaleLine.Units.US) { if (nominalCount < 0.9144) { suffix = 'in'; pointResolution *= 39.37; @@ -245,7 +223,7 @@ ol.control.ScaleLine.prototype.updateElement_ = function() { pointResolution /= 1609.3472; } } else { - ol.assert(false, 33); // Invalid units + ol.asserts.assert(false, 33); // Invalid units } var i = 3 * Math.floor( @@ -282,3 +260,26 @@ ol.control.ScaleLine.prototype.updateElement_ = function() { } }; + + +/** + * @enum {string} + * @api + */ +ol.control.ScaleLine.Property = { + UNITS: 'units' +}; + + +/** + * Units for the scale line. Supported values are `'degrees'`, `'imperial'`, + * `'nautical'`, `'metric'`, `'us'`. + * @enum {string} + */ +ol.control.ScaleLine.Units = { + DEGREES: 'degrees', + IMPERIAL: 'imperial', + NAUTICAL: 'nautical', + METRIC: 'metric', + US: 'us' +}; diff --git a/src/ol/control/zoomslider.js b/src/ol/control/zoomslider.js index 5f92a8441e..0878207992 100644 --- a/src/ol/control/zoomslider.js +++ b/src/ol/control/zoomslider.js @@ -2,16 +2,16 @@ goog.provide('ol.control.ZoomSlider'); -goog.require('ol.events'); -goog.require('ol.events.Event'); -goog.require('ol.events.EventType'); -goog.require('ol.pointer.PointerEventHandler'); -goog.require('ol.ViewHint'); +goog.require('ol.View'); goog.require('ol.animation'); goog.require('ol.control.Control'); goog.require('ol.css'); goog.require('ol.easing'); +goog.require('ol.events'); +goog.require('ol.events.Event'); +goog.require('ol.events.EventType'); goog.require('ol.math'); +goog.require('ol.pointer.PointerEventHandler'); /** @@ -255,7 +255,7 @@ ol.control.ZoomSlider.prototype.handleContainerClick_ = function(event) { ol.control.ZoomSlider.prototype.handleDraggerStart_ = function(event) { if (!this.dragging_ && event.originalEvent.target === this.element.firstElementChild) { - this.getMap().getView().setHint(ol.ViewHint.INTERACTING, 1); + this.getMap().getView().setHint(ol.View.Hint.INTERACTING, 1); this.previousX_ = event.clientX; this.previousY_ = event.clientY; this.dragging_ = true; @@ -306,7 +306,7 @@ ol.control.ZoomSlider.prototype.handleDraggerEnd_ = function(event) { if (this.dragging_) { var map = this.getMap(); var view = map.getView(); - view.setHint(ol.ViewHint.INTERACTING, -1); + view.setHint(ol.View.Hint.INTERACTING, -1); map.beforeRender(ol.animation.zoom({ resolution: /** @type {number} */ (this.currentResolution_), duration: this.duration_, diff --git a/src/ol/events/eventtype.js b/src/ol/events/eventtype.js new file mode 100644 index 0000000000..987650f00d --- /dev/null +++ b/src/ol/events/eventtype.js @@ -0,0 +1,35 @@ +goog.provide('ol.events.EventType'); + +/** + * @enum {string} + * @const + */ +ol.events.EventType = { + /** + * Generic change event. Triggered when the revision counter is increased. + * @event ol.events.Event#change + * @api + */ + CHANGE: 'change', + + CLICK: 'click', + DBLCLICK: 'dblclick', + DRAGENTER: 'dragenter', + DRAGOVER: 'dragover', + DROP: 'drop', + ERROR: 'error', + KEYDOWN: 'keydown', + KEYPRESS: 'keypress', + LOAD: 'load', + MOUSEDOWN: 'mousedown', + MOUSEMOVE: 'mousemove', + MOUSEOUT: 'mouseout', + MOUSEUP: 'mouseup', + MOUSEWHEEL: 'mousewheel', + MSPOINTERDOWN: 'mspointerdown', + RESIZE: 'resize', + TOUCHSTART: 'touchstart', + TOUCHMOVE: 'touchmove', + TOUCHEND: 'touchend', + WHEEL: 'wheel' +}; diff --git a/src/ol/events.js b/src/ol/events/index.js similarity index 89% rename from src/ol/events.js rename to src/ol/events/index.js index 20fe8e97c6..fd2f96fb20 100644 --- a/src/ol/events.js +++ b/src/ol/events/index.js @@ -1,57 +1,8 @@ goog.provide('ol.events'); -goog.provide('ol.events.EventType'); -goog.provide('ol.events.KeyCode'); goog.require('ol.obj'); -/** - * @enum {string} - * @const - */ -ol.events.EventType = { - /** - * Generic change event. Triggered when the revision counter is increased. - * @event ol.events.Event#change - * @api - */ - CHANGE: 'change', - - CLICK: 'click', - DBLCLICK: 'dblclick', - DRAGENTER: 'dragenter', - DRAGOVER: 'dragover', - DROP: 'drop', - ERROR: 'error', - KEYDOWN: 'keydown', - KEYPRESS: 'keypress', - LOAD: 'load', - MOUSEDOWN: 'mousedown', - MOUSEMOVE: 'mousemove', - MOUSEOUT: 'mouseout', - MOUSEUP: 'mouseup', - MOUSEWHEEL: 'mousewheel', - MSPOINTERDOWN: 'mspointerdown', - RESIZE: 'resize', - TOUCHSTART: 'touchstart', - TOUCHMOVE: 'touchmove', - TOUCHEND: 'touchend', - WHEEL: 'wheel' -}; - - -/** - * @enum {number} - * @const - */ -ol.events.KeyCode = { - LEFT: 37, - UP: 38, - RIGHT: 39, - DOWN: 40 -}; - - /** * @param {ol.EventsKey} listenerObj Listener object. * @return {ol.EventsListenerFunctionType} Bound listener. diff --git a/src/ol/events/keycode.js b/src/ol/events/keycode.js new file mode 100644 index 0000000000..5a6ec4535a --- /dev/null +++ b/src/ol/events/keycode.js @@ -0,0 +1,12 @@ +goog.provide('ol.events.KeyCode'); + +/** + * @enum {number} + * @const + */ +ol.events.KeyCode = { + LEFT: 37, + UP: 38, + RIGHT: 39, + DOWN: 40 +}; diff --git a/src/ol/extent.js b/src/ol/extent.js index f9da4b4605..f7430cef6d 100644 --- a/src/ol/extent.js +++ b/src/ol/extent.js @@ -526,7 +526,7 @@ ol.extent.getCorner = function(extent, corner) { } else if (corner === ol.extent.Corner.TOP_RIGHT) { coordinate = ol.extent.getTopRight(extent); } else { - ol.assert(false, 13); // Invalid corner + ol.asserts.assert(false, 13); // Invalid corner } return /** @type {!ol.Coordinate} */ (coordinate); }; diff --git a/src/ol/feature.js b/src/ol/feature.js index a9f351c2bb..0bb9b6b2c5 100644 --- a/src/ol/feature.js +++ b/src/ol/feature.js @@ -301,7 +301,7 @@ ol.Feature.createStyleFunction = function(obj) { if (Array.isArray(obj)) { styles = obj; } else { - ol.assert(obj instanceof ol.style.Style, + ol.asserts.assert(obj instanceof ol.style.Style, 41); // Expected an `ol.style.Style` or an array of `ol.style.Style` styles = [obj]; } diff --git a/src/ol/featureloader.js b/src/ol/featureloader.js index 26c42432b9..1e1cf46bd5 100644 --- a/src/ol/featureloader.js +++ b/src/ol/featureloader.js @@ -1,6 +1,6 @@ goog.provide('ol.featureloader'); -goog.require('ol.TileState'); +goog.require('ol.Tile'); goog.require('ol.format.FormatType'); goog.require('ol.xml'); @@ -93,7 +93,7 @@ ol.featureloader.tile = function(url, format) { * @this {ol.VectorTile} */ function() { - this.setState(ol.TileState.ERROR); + this.setState(ol.Tile.State.ERROR); }); }; diff --git a/src/ol/format/esrijson.js b/src/ol/format/esrijson.js index b183f80b12..97691101c8 100644 --- a/src/ol/format/esrijson.js +++ b/src/ol/format/esrijson.js @@ -282,7 +282,7 @@ ol.format.EsriJSON.writePointGeometry_ = function(geometry, opt_options) { y: coordinates[1] }); } else { - ol.assert(false, 34); // Invalid geometry layout + ol.asserts.assert(false, 34); // Invalid geometry layout } return /** @type {EsriJSONGeometry} */ (esriJSON); }; diff --git a/src/ol/format/geojson.js b/src/ol/format/geojson.js index c0342f1495..b5f82272fc 100644 --- a/src/ol/format/geojson.js +++ b/src/ol/format/geojson.js @@ -422,7 +422,7 @@ ol.format.GeoJSON.prototype.readFeaturesFromObject = function( opt_options)); } } else { - ol.assert(false, 35); // Unknown GeoJSON object type + ol.asserts.assert(false, 35); // Unknown GeoJSON object type } return /** Array. */ (features); }; @@ -478,7 +478,7 @@ ol.format.GeoJSON.prototype.readProjectionFromObject = function(object) { // is fixed and widely deployed. projection = ol.proj.get('EPSG:' + crs.properties.code); } else { - ol.assert(false, 36); // Unknown SRS type + ol.asserts.assert(false, 36); // Unknown SRS type } } else { projection = this.defaultDataProjection; diff --git a/src/ol/format/kml.js b/src/ol/format/kml.js index 1f119b8665..83c0c3b3b1 100644 --- a/src/ol/format/kml.js +++ b/src/ol/format/kml.js @@ -981,7 +981,7 @@ ol.format.KML.readMultiGeometry_ = function(node, objectStack) { } else if (type == ol.geom.GeometryType.GEOMETRY_COLLECTION) { multiGeometry = new ol.geom.GeometryCollection(geometries); } else { - ol.assert(false, 37); // Unknown geometry type found + ol.asserts.assert(false, 37); // Unknown geometry type found } } else { multiGeometry = new ol.geom.GeometryCollection(geometries); @@ -1217,7 +1217,7 @@ ol.format.KML.PlacemarkStyleMapParser_ = function(node, objectStack) { } else if (typeof styleMapValue === 'string') { placemarkObject['styleUrl'] = styleMapValue; } else { - ol.assert(false, 38); // `styleMapValue` has an unknown type + ol.asserts.assert(false, 38); // `styleMapValue` has an unknown type } }; @@ -2067,7 +2067,7 @@ ol.format.KML.writeCoordinatesTextNode_ = function(node, coordinates, objectStac layout == ol.geom.GeometryLayout.XYZM) { dimension = 3; } else { - ol.assert(false, 34); // Invalid geometry layout + ol.asserts.assert(false, 34); // Invalid geometry layout } var d, i; @@ -2259,7 +2259,7 @@ ol.format.KML.writeMultiGeometry_ = function(node, geometry, objectStack) { (/** @type {ol.geom.MultiPolygon} */ (geometry)).getPolygons(); factory = ol.format.KML.POLYGON_NODE_FACTORY_; } else { - ol.assert(false, 39); // Unknown geometry type + ol.asserts.assert(false, 39); // Unknown geometry type } ol.xml.pushSerializeAndPop(context, ol.format.KML.MULTI_GEOMETRY_SERIALIZERS_, factory, diff --git a/src/ol/format/ogc/filter.js b/src/ol/format/ogc/filter.js deleted file mode 100644 index 46d96b32bb..0000000000 --- a/src/ol/format/ogc/filter.js +++ /dev/null @@ -1,745 +0,0 @@ -goog.provide('ol.format.ogc.filter'); -goog.provide('ol.format.ogc.filter.Filter'); -goog.provide('ol.format.ogc.filter.Logical'); -goog.provide('ol.format.ogc.filter.LogicalBinary'); -goog.provide('ol.format.ogc.filter.And'); -goog.provide('ol.format.ogc.filter.Or'); -goog.provide('ol.format.ogc.filter.Not'); -goog.provide('ol.format.ogc.filter.Bbox'); -goog.provide('ol.format.ogc.filter.Intersects'); -goog.provide('ol.format.ogc.filter.Within'); -goog.provide('ol.format.ogc.filter.Comparison'); -goog.provide('ol.format.ogc.filter.ComparisonBinary'); -goog.provide('ol.format.ogc.filter.EqualTo'); -goog.provide('ol.format.ogc.filter.NotEqualTo'); -goog.provide('ol.format.ogc.filter.LessThan'); -goog.provide('ol.format.ogc.filter.LessThanOrEqualTo'); -goog.provide('ol.format.ogc.filter.GreaterThan'); -goog.provide('ol.format.ogc.filter.GreaterThanOrEqualTo'); -goog.provide('ol.format.ogc.filter.IsNull'); -goog.provide('ol.format.ogc.filter.IsBetween'); -goog.provide('ol.format.ogc.filter.IsLike'); - - -/** - * Create a logical `` operator between two filter conditions. - * - * @param {!ol.format.ogc.filter.Filter} conditionA First filter condition. - * @param {!ol.format.ogc.filter.Filter} conditionB Second filter condition. - * @returns {!ol.format.ogc.filter.And} `` operator. - * @api - */ -ol.format.ogc.filter.and = function(conditionA, conditionB) { - return new ol.format.ogc.filter.And(conditionA, conditionB); -}; - - -/** - * Create a logical `` operator between two filter conditions. - * - * @param {!ol.format.ogc.filter.Filter} conditionA First filter condition. - * @param {!ol.format.ogc.filter.Filter} conditionB Second filter condition. - * @returns {!ol.format.ogc.filter.Or} `` operator. - * @api - */ -ol.format.ogc.filter.or = function(conditionA, conditionB) { - return new ol.format.ogc.filter.Or(conditionA, conditionB); -}; - - -/** - * Represents a logical `` operator for a filter condition. - * - * @param {!ol.format.ogc.filter.Filter} condition Filter condition. - * @returns {!ol.format.ogc.filter.Not} `` operator. - * @api - */ -ol.format.ogc.filter.not = function(condition) { - return new ol.format.ogc.filter.Not(condition); -}; - - -/** - * Create a `` operator to test whether a geometry-valued property - * intersects a fixed bounding box - * - * @param {!string} geometryName Geometry name to use. - * @param {!ol.Extent} extent Extent. - * @param {string=} opt_srsName SRS name. No srsName attribute will be - * set on geometries when this is not provided. - * @returns {!ol.format.ogc.filter.Bbox} `` operator. - * @api - */ -ol.format.ogc.filter.bbox = function(geometryName, extent, opt_srsName) { - return new ol.format.ogc.filter.Bbox(geometryName, extent, opt_srsName); -}; - -/** - * Create a `` operator to test whether a geometry-valued property - * intersects a given geometry. - * - * @param {!string} geometryName Geometry name to use. - * @param {!ol.geom.Geometry} geometry Geometry. - * @param {string=} opt_srsName SRS name. No srsName attribute will be - * set on geometries when this is not provided. - * @returns {!ol.format.ogc.filter.Intersects} `` operator. - * @api - */ -ol.format.ogc.filter.intersects = function(geometryName, geometry, opt_srsName) { - return new ol.format.ogc.filter.Intersects(geometryName, geometry, opt_srsName); -}; - -/** - * Create a `` operator to test whether a geometry-valued property - * is within a given geometry. - * - * @param {!string} geometryName Geometry name to use. - * @param {!ol.geom.Geometry} geometry Geometry. - * @param {string=} opt_srsName SRS name. No srsName attribute will be - * set on geometries when this is not provided. - * @returns {!ol.format.ogc.filter.Within} `` operator. - * @api - */ -ol.format.ogc.filter.within = function(geometryName, geometry, opt_srsName) { - return new ol.format.ogc.filter.Within(geometryName, geometry, opt_srsName); -}; - - -/** - * Creates a `` comparison operator. - * - * @param {!string} propertyName Name of the context property to compare. - * @param {!(string|number)} expression The value to compare. - * @param {boolean=} opt_matchCase Case-sensitive? - * @returns {!ol.format.ogc.filter.EqualTo} `` operator. - * @api - */ -ol.format.ogc.filter.equalTo = function(propertyName, expression, opt_matchCase) { - return new ol.format.ogc.filter.EqualTo(propertyName, expression, opt_matchCase); -}; - - -/** - * Creates a `` comparison operator. - * - * @param {!string} propertyName Name of the context property to compare. - * @param {!(string|number)} expression The value to compare. - * @param {boolean=} opt_matchCase Case-sensitive? - * @returns {!ol.format.ogc.filter.NotEqualTo} `` operator. - * @api - */ -ol.format.ogc.filter.notEqualTo = function(propertyName, expression, opt_matchCase) { - return new ol.format.ogc.filter.NotEqualTo(propertyName, expression, opt_matchCase); -}; - - -/** - * Creates a `` comparison operator. - * - * @param {!string} propertyName Name of the context property to compare. - * @param {!number} expression The value to compare. - * @returns {!ol.format.ogc.filter.LessThan} `` operator. - * @api - */ -ol.format.ogc.filter.lessThan = function(propertyName, expression) { - return new ol.format.ogc.filter.LessThan(propertyName, expression); -}; - - -/** - * Creates a `` comparison operator. - * - * @param {!string} propertyName Name of the context property to compare. - * @param {!number} expression The value to compare. - * @returns {!ol.format.ogc.filter.LessThanOrEqualTo} `` operator. - * @api - */ -ol.format.ogc.filter.lessThanOrEqualTo = function(propertyName, expression) { - return new ol.format.ogc.filter.LessThanOrEqualTo(propertyName, expression); -}; - - -/** - * Creates a `` comparison operator. - * - * @param {!string} propertyName Name of the context property to compare. - * @param {!number} expression The value to compare. - * @returns {!ol.format.ogc.filter.GreaterThan} `` operator. - * @api - */ -ol.format.ogc.filter.greaterThan = function(propertyName, expression) { - return new ol.format.ogc.filter.GreaterThan(propertyName, expression); -}; - - -/** - * Creates a `` comparison operator. - * - * @param {!string} propertyName Name of the context property to compare. - * @param {!number} expression The value to compare. - * @returns {!ol.format.ogc.filter.GreaterThanOrEqualTo} `` operator. - * @api - */ -ol.format.ogc.filter.greaterThanOrEqualTo = function(propertyName, expression) { - return new ol.format.ogc.filter.GreaterThanOrEqualTo(propertyName, expression); -}; - - -/** - * Creates a `` comparison operator to test whether a property value - * is null. - * - * @param {!string} propertyName Name of the context property to compare. - * @returns {!ol.format.ogc.filter.IsNull} `` operator. - * @api - */ -ol.format.ogc.filter.isNull = function(propertyName) { - return new ol.format.ogc.filter.IsNull(propertyName); -}; - - -/** - * Creates a `` comparison operator to test whether an expression - * value lies within a range given by a lower and upper bound (inclusive). - * - * @param {!string} propertyName Name of the context property to compare. - * @param {!number} lowerBoundary The lower bound of the range. - * @param {!number} upperBoundary The upper bound of the range. - * @returns {!ol.format.ogc.filter.IsBetween} `` operator. - * @api - */ -ol.format.ogc.filter.between = function(propertyName, lowerBoundary, upperBoundary) { - return new ol.format.ogc.filter.IsBetween(propertyName, lowerBoundary, upperBoundary); -}; - - -/** - * Represents a `` comparison operator that matches a string property - * value against a text pattern. - * - * @param {!string} propertyName Name of the context property to compare. - * @param {!string} pattern Text pattern. - * @param {string=} opt_wildCard Pattern character which matches any sequence of - * zero or more string characters. Default is '*'. - * @param {string=} opt_singleChar pattern character which matches any single - * string character. Default is '.'. - * @param {string=} opt_escapeChar Escape character which can be used to escape - * the pattern characters. Default is '!'. - * @param {boolean=} opt_matchCase Case-sensitive? - * @returns {!ol.format.ogc.filter.IsLike} `` operator. - * @api - */ -ol.format.ogc.filter.like = function(propertyName, pattern, - opt_wildCard, opt_singleChar, opt_escapeChar, opt_matchCase) { - return new ol.format.ogc.filter.IsLike(propertyName, pattern, - opt_wildCard, opt_singleChar, opt_escapeChar, opt_matchCase); -}; - - -/** - * @classdesc - * Abstract class; normally only used for creating subclasses and not instantiated in apps. - * Base class for WFS GetFeature filters. - * - * @constructor - * @param {!string} tagName The XML tag name for this filter. - * @struct - * @api - */ -ol.format.ogc.filter.Filter = function(tagName) { - - /** - * @private - * @type {!string} - */ - this.tagName_ = tagName; -}; - -/** - * The XML tag name for a filter. - * @returns {!string} Name. - */ -ol.format.ogc.filter.Filter.prototype.getTagName = function() { - return this.tagName_; -}; - - -// Logical filters - - -/** - * @classdesc - * Abstract class; normally only used for creating subclasses and not instantiated in apps. - * Base class for WFS GetFeature logical filters. - * - * @constructor - * @param {!string} tagName The XML tag name for this filter. - * @extends {ol.format.ogc.filter.Filter} - */ -ol.format.ogc.filter.Logical = function(tagName) { - ol.format.ogc.filter.Filter.call(this, tagName); -}; -ol.inherits(ol.format.ogc.filter.Logical, ol.format.ogc.filter.Filter); - - -/** - * @classdesc - * Abstract class; normally only used for creating subclasses and not instantiated in apps. - * Base class for WFS GetFeature binary logical filters. - * - * @constructor - * @param {!string} tagName The XML tag name for this filter. - * @param {!ol.format.ogc.filter.Filter} conditionA First filter condition. - * @param {!ol.format.ogc.filter.Filter} conditionB Second filter condition. - * @extends {ol.format.ogc.filter.Logical} - */ -ol.format.ogc.filter.LogicalBinary = function(tagName, conditionA, conditionB) { - - ol.format.ogc.filter.Logical.call(this, tagName); - - /** - * @public - * @type {!ol.format.ogc.filter.Filter} - */ - this.conditionA = conditionA; - - /** - * @public - * @type {!ol.format.ogc.filter.Filter} - */ - this.conditionB = conditionB; - -}; -ol.inherits(ol.format.ogc.filter.LogicalBinary, ol.format.ogc.filter.Logical); - - -/** - * @classdesc - * Represents a logical `` operator between two filter conditions. - * - * @constructor - * @param {!ol.format.ogc.filter.Filter} conditionA First filter condition. - * @param {!ol.format.ogc.filter.Filter} conditionB Second filter condition. - * @extends {ol.format.ogc.filter.LogicalBinary} - * @api - */ -ol.format.ogc.filter.And = function(conditionA, conditionB) { - ol.format.ogc.filter.LogicalBinary.call(this, 'And', conditionA, conditionB); -}; -ol.inherits(ol.format.ogc.filter.And, ol.format.ogc.filter.LogicalBinary); - - -/** - * @classdesc - * Represents a logical `` operator between two filter conditions. - * - * @constructor - * @param {!ol.format.ogc.filter.Filter} conditionA First filter condition. - * @param {!ol.format.ogc.filter.Filter} conditionB Second filter condition. - * @extends {ol.format.ogc.filter.LogicalBinary} - * @api - */ -ol.format.ogc.filter.Or = function(conditionA, conditionB) { - ol.format.ogc.filter.LogicalBinary.call(this, 'Or', conditionA, conditionB); -}; -ol.inherits(ol.format.ogc.filter.Or, ol.format.ogc.filter.LogicalBinary); - - -/** - * @classdesc - * Represents a logical `` operator for a filter condition. - * - * @constructor - * @param {!ol.format.ogc.filter.Filter} condition Filter condition. - * @extends {ol.format.ogc.filter.Logical} - * @api - */ -ol.format.ogc.filter.Not = function(condition) { - - ol.format.ogc.filter.Logical.call(this, 'Not'); - - /** - * @public - * @type {!ol.format.ogc.filter.Filter} - */ - this.condition = condition; -}; -ol.inherits(ol.format.ogc.filter.Not, ol.format.ogc.filter.Logical); - - -// Spatial filters - - -/** - * @classdesc - * Represents a `` operator to test whether a geometry-valued property - * intersects a fixed bounding box - * - * @constructor - * @param {!string} geometryName Geometry name to use. - * @param {!ol.Extent} extent Extent. - * @param {string=} opt_srsName SRS name. No srsName attribute will be - * set on geometries when this is not provided. - * @extends {ol.format.ogc.filter.Filter} - * @api - */ -ol.format.ogc.filter.Bbox = function(geometryName, extent, opt_srsName) { - - ol.format.ogc.filter.Filter.call(this, 'BBOX'); - - /** - * @public - * @type {!string} - */ - this.geometryName = geometryName; - - /** - * @public - * @type {ol.Extent} - */ - this.extent = extent; - - /** - * @public - * @type {string|undefined} - */ - this.srsName = opt_srsName; -}; -ol.inherits(ol.format.ogc.filter.Bbox, ol.format.ogc.filter.Filter); - - -/** - * @classdesc - * Represents a spatial operator to test whether a geometry-valued property - * relates to a given geometry. - * - * @constructor - * @param {!string} tagName The XML tag name for this filter. - * @param {!string} geometryName Geometry name to use. - * @param {!ol.geom.Geometry} geometry Geometry. - * @param {string=} opt_srsName SRS name. No srsName attribute will be - * set on geometries when this is not provided. - * @extends {ol.format.ogc.filter.Filter} - * @api - */ -ol.format.ogc.filter.Spatial = function(tagName, geometryName, geometry, opt_srsName) { - - ol.format.ogc.filter.Filter.call(this, tagName); - - /** - * @public - * @type {!string} - */ - this.geometryName = geometryName || 'the_geom'; - - /** - * @public - * @type {ol.geom.Geometry} - */ - this.geometry = geometry; - - /** - * @public - * @type {string|undefined} - */ - this.srsName = opt_srsName; -}; -ol.inherits(ol.format.ogc.filter.Spatial, ol.format.ogc.filter.Filter); - - -/** - * @classdesc - * Represents a `` operator to test whether a geometry-valued property - * intersects a given geometry. - * - * @constructor - * @param {!string} geometryName Geometry name to use. - * @param {!ol.geom.Geometry} geometry Geometry. - * @param {string=} opt_srsName SRS name. No srsName attribute will be - * set on geometries when this is not provided. - * @extends {ol.format.ogc.filter.Spatial} - * @api - */ -ol.format.ogc.filter.Intersects = function(geometryName, geometry, opt_srsName) { - - ol.format.ogc.filter.Spatial.call(this, 'Intersects', geometryName, geometry, opt_srsName); - -}; -ol.inherits(ol.format.ogc.filter.Intersects, ol.format.ogc.filter.Spatial); - - -/** - * @classdesc - * Represents a `` operator to test whether a geometry-valued property - * is within a given geometry. - * - * @constructor - * @param {!string} geometryName Geometry name to use. - * @param {!ol.geom.Geometry} geometry Geometry. - * @param {string=} opt_srsName SRS name. No srsName attribute will be - * set on geometries when this is not provided. - * @extends {ol.format.ogc.filter.Spatial} - * @api - */ -ol.format.ogc.filter.Within = function(geometryName, geometry, opt_srsName) { - - ol.format.ogc.filter.Spatial.call(this, 'Within', geometryName, geometry, opt_srsName); - -}; -ol.inherits(ol.format.ogc.filter.Within, ol.format.ogc.filter.Spatial); - - -// Property comparison filters - - -/** - * @classdesc - * Abstract class; normally only used for creating subclasses and not instantiated in apps. - * Base class for WFS GetFeature property comparison filters. - * - * @constructor - * @param {!string} tagName The XML tag name for this filter. - * @param {!string} propertyName Name of the context property to compare. - * @extends {ol.format.ogc.filter.Filter} - * @api - */ -ol.format.ogc.filter.Comparison = function(tagName, propertyName) { - - ol.format.ogc.filter.Filter.call(this, tagName); - - /** - * @public - * @type {!string} - */ - this.propertyName = propertyName; -}; -ol.inherits(ol.format.ogc.filter.Comparison, ol.format.ogc.filter.Filter); - - -/** - * @classdesc - * Abstract class; normally only used for creating subclasses and not instantiated in apps. - * Base class for WFS GetFeature property binary comparison filters. - * - * @constructor - * @param {!string} tagName The XML tag name for this filter. - * @param {!string} propertyName Name of the context property to compare. - * @param {!(string|number)} expression The value to compare. - * @param {boolean=} opt_matchCase Case-sensitive? - * @extends {ol.format.ogc.filter.Comparison} - * @api - */ -ol.format.ogc.filter.ComparisonBinary = function( - tagName, propertyName, expression, opt_matchCase) { - - ol.format.ogc.filter.Comparison.call(this, tagName, propertyName); - - /** - * @public - * @type {!(string|number)} - */ - this.expression = expression; - - /** - * @public - * @type {boolean|undefined} - */ - this.matchCase = opt_matchCase; -}; -ol.inherits(ol.format.ogc.filter.ComparisonBinary, ol.format.ogc.filter.Comparison); - - -/** - * @classdesc - * Represents a `` comparison operator. - * - * @constructor - * @param {!string} propertyName Name of the context property to compare. - * @param {!(string|number)} expression The value to compare. - * @param {boolean=} opt_matchCase Case-sensitive? - * @extends {ol.format.ogc.filter.ComparisonBinary} - * @api - */ -ol.format.ogc.filter.EqualTo = function(propertyName, expression, opt_matchCase) { - ol.format.ogc.filter.ComparisonBinary.call(this, 'PropertyIsEqualTo', propertyName, expression, opt_matchCase); -}; -ol.inherits(ol.format.ogc.filter.EqualTo, ol.format.ogc.filter.ComparisonBinary); - - -/** - * @classdesc - * Represents a `` comparison operator. - * - * @constructor - * @param {!string} propertyName Name of the context property to compare. - * @param {!(string|number)} expression The value to compare. - * @param {boolean=} opt_matchCase Case-sensitive? - * @extends {ol.format.ogc.filter.ComparisonBinary} - * @api - */ -ol.format.ogc.filter.NotEqualTo = function(propertyName, expression, opt_matchCase) { - ol.format.ogc.filter.ComparisonBinary.call(this, 'PropertyIsNotEqualTo', propertyName, expression, opt_matchCase); -}; -ol.inherits(ol.format.ogc.filter.NotEqualTo, ol.format.ogc.filter.ComparisonBinary); - - -/** - * @classdesc - * Represents a `` comparison operator. - * - * @constructor - * @param {!string} propertyName Name of the context property to compare. - * @param {!number} expression The value to compare. - * @extends {ol.format.ogc.filter.ComparisonBinary} - * @api - */ -ol.format.ogc.filter.LessThan = function(propertyName, expression) { - ol.format.ogc.filter.ComparisonBinary.call(this, 'PropertyIsLessThan', propertyName, expression); -}; -ol.inherits(ol.format.ogc.filter.LessThan, ol.format.ogc.filter.ComparisonBinary); - - -/** - * @classdesc - * Represents a `` comparison operator. - * - * @constructor - * @param {!string} propertyName Name of the context property to compare. - * @param {!number} expression The value to compare. - * @extends {ol.format.ogc.filter.ComparisonBinary} - * @api - */ -ol.format.ogc.filter.LessThanOrEqualTo = function(propertyName, expression) { - ol.format.ogc.filter.ComparisonBinary.call(this, 'PropertyIsLessThanOrEqualTo', propertyName, expression); -}; -ol.inherits(ol.format.ogc.filter.LessThanOrEqualTo, ol.format.ogc.filter.ComparisonBinary); - - -/** - * @classdesc - * Represents a `` comparison operator. - * - * @constructor - * @param {!string} propertyName Name of the context property to compare. - * @param {!number} expression The value to compare. - * @extends {ol.format.ogc.filter.ComparisonBinary} - * @api - */ -ol.format.ogc.filter.GreaterThan = function(propertyName, expression) { - ol.format.ogc.filter.ComparisonBinary.call(this, 'PropertyIsGreaterThan', propertyName, expression); -}; -ol.inherits(ol.format.ogc.filter.GreaterThan, ol.format.ogc.filter.ComparisonBinary); - - -/** - * @classdesc - * Represents a `` comparison operator. - * - * @constructor - * @param {!string} propertyName Name of the context property to compare. - * @param {!number} expression The value to compare. - * @extends {ol.format.ogc.filter.ComparisonBinary} - * @api - */ -ol.format.ogc.filter.GreaterThanOrEqualTo = function(propertyName, expression) { - ol.format.ogc.filter.ComparisonBinary.call(this, 'PropertyIsGreaterThanOrEqualTo', propertyName, expression); -}; -ol.inherits(ol.format.ogc.filter.GreaterThanOrEqualTo, ol.format.ogc.filter.ComparisonBinary); - - -/** - * @classdesc - * Represents a `` comparison operator. - * - * @constructor - * @param {!string} propertyName Name of the context property to compare. - * @extends {ol.format.ogc.filter.Comparison} - * @api - */ -ol.format.ogc.filter.IsNull = function(propertyName) { - ol.format.ogc.filter.Comparison.call(this, 'PropertyIsNull', propertyName); -}; -ol.inherits(ol.format.ogc.filter.IsNull, ol.format.ogc.filter.Comparison); - - -/** - * @classdesc - * Represents a `` comparison operator. - * - * @constructor - * @param {!string} propertyName Name of the context property to compare. - * @param {!number} lowerBoundary The lower bound of the range. - * @param {!number} upperBoundary The upper bound of the range. - * @extends {ol.format.ogc.filter.Comparison} - * @api - */ -ol.format.ogc.filter.IsBetween = function(propertyName, lowerBoundary, upperBoundary) { - ol.format.ogc.filter.Comparison.call(this, 'PropertyIsBetween', propertyName); - - /** - * @public - * @type {!number} - */ - this.lowerBoundary = lowerBoundary; - - /** - * @public - * @type {!number} - */ - this.upperBoundary = upperBoundary; -}; -ol.inherits(ol.format.ogc.filter.IsBetween, ol.format.ogc.filter.Comparison); - - -/** - * @classdesc - * Represents a `` comparison operator. - * - * @constructor - * @param {!string} propertyName Name of the context property to compare. - * @param {!string} pattern Text pattern. - * @param {string=} opt_wildCard Pattern character which matches any sequence of - * zero or more string characters. Default is '*'. - * @param {string=} opt_singleChar pattern character which matches any single - * string character. Default is '.'. - * @param {string=} opt_escapeChar Escape character which can be used to escape - * the pattern characters. Default is '!'. - * @param {boolean=} opt_matchCase Case-sensitive? - * @extends {ol.format.ogc.filter.Comparison} - * @api - */ -ol.format.ogc.filter.IsLike = function(propertyName, pattern, - opt_wildCard, opt_singleChar, opt_escapeChar, opt_matchCase) { - ol.format.ogc.filter.Comparison.call(this, 'PropertyIsLike', propertyName); - - /** - * @public - * @type {!string} - */ - this.pattern = pattern; - - /** - * @public - * @type {!string} - */ - this.wildCard = (opt_wildCard !== undefined) ? opt_wildCard : '*'; - - /** - * @public - * @type {!string} - */ - this.singleChar = (opt_singleChar !== undefined) ? opt_singleChar : '.'; - - /** - * @public - * @type {!string} - */ - this.escapeChar = (opt_escapeChar !== undefined) ? opt_escapeChar : '!'; - - /** - * @public - * @type {boolean|undefined} - */ - this.matchCase = opt_matchCase; -}; -ol.inherits(ol.format.ogc.filter.IsLike, ol.format.ogc.filter.Comparison); diff --git a/src/ol/format/ogc/filter/and.js b/src/ol/format/ogc/filter/and.js new file mode 100644 index 0000000000..c45b0a0066 --- /dev/null +++ b/src/ol/format/ogc/filter/and.js @@ -0,0 +1,19 @@ +goog.provide('ol.format.ogc.filter.And'); + +goog.require('ol'); +goog.require('ol.format.ogc.filter.LogicalBinary'); + +/** + * @classdesc + * Represents a logical `` operator between two filter conditions. + * + * @constructor + * @param {!ol.format.ogc.filter.Filter} conditionA First filter condition. + * @param {!ol.format.ogc.filter.Filter} conditionB Second filter condition. + * @extends {ol.format.ogc.filter.LogicalBinary} + * @api + */ +ol.format.ogc.filter.And = function(conditionA, conditionB) { + ol.format.ogc.filter.LogicalBinary.call(this, 'And', conditionA, conditionB); +}; +ol.inherits(ol.format.ogc.filter.And, ol.format.ogc.filter.LogicalBinary); diff --git a/src/ol/format/ogc/filter/bbox.js b/src/ol/format/ogc/filter/bbox.js new file mode 100644 index 0000000000..5fae3c1610 --- /dev/null +++ b/src/ol/format/ogc/filter/bbox.js @@ -0,0 +1,42 @@ +goog.provide('ol.format.ogc.filter.Bbox'); + +goog.require('ol'); +goog.require('ol.format.ogc.filter.Filter'); + + +/** + * @classdesc + * Represents a `` operator to test whether a geometry-valued property + * intersects a fixed bounding box + * + * @constructor + * @param {!string} geometryName Geometry name to use. + * @param {!ol.Extent} extent Extent. + * @param {string=} opt_srsName SRS name. No srsName attribute will be + * set on geometries when this is not provided. + * @extends {ol.format.ogc.filter.Filter} + * @api + */ +ol.format.ogc.filter.Bbox = function(geometryName, extent, opt_srsName) { + + ol.format.ogc.filter.Filter.call(this, 'BBOX'); + + /** + * @public + * @type {!string} + */ + this.geometryName = geometryName; + + /** + * @public + * @type {ol.Extent} + */ + this.extent = extent; + + /** + * @public + * @type {string|undefined} + */ + this.srsName = opt_srsName; +}; +ol.inherits(ol.format.ogc.filter.Bbox, ol.format.ogc.filter.Filter); diff --git a/src/ol/format/ogc/filter/comparison.js b/src/ol/format/ogc/filter/comparison.js new file mode 100644 index 0000000000..42f24da409 --- /dev/null +++ b/src/ol/format/ogc/filter/comparison.js @@ -0,0 +1,28 @@ +goog.provide('ol.format.ogc.filter.Comparison'); + +goog.require('ol'); +goog.require('ol.format.ogc.filter.Filter'); + + +/** + * @classdesc + * Abstract class; normally only used for creating subclasses and not instantiated in apps. + * Base class for WFS GetFeature property comparison filters. + * + * @constructor + * @param {!string} tagName The XML tag name for this filter. + * @param {!string} propertyName Name of the context property to compare. + * @extends {ol.format.ogc.filter.Filter} + * @api + */ +ol.format.ogc.filter.Comparison = function(tagName, propertyName) { + + ol.format.ogc.filter.Filter.call(this, tagName); + + /** + * @public + * @type {!string} + */ + this.propertyName = propertyName; +}; +ol.inherits(ol.format.ogc.filter.Comparison, ol.format.ogc.filter.Filter); diff --git a/src/ol/format/ogc/filter/comparisonbinary.js b/src/ol/format/ogc/filter/comparisonbinary.js new file mode 100644 index 0000000000..ffcc7cec33 --- /dev/null +++ b/src/ol/format/ogc/filter/comparisonbinary.js @@ -0,0 +1,37 @@ +goog.provide('ol.format.ogc.filter.ComparisonBinary'); + +goog.require('ol'); +goog.require('ol.format.ogc.filter.Comparison'); + + +/** + * @classdesc + * Abstract class; normally only used for creating subclasses and not instantiated in apps. + * Base class for WFS GetFeature property binary comparison filters. + * + * @constructor + * @param {!string} tagName The XML tag name for this filter. + * @param {!string} propertyName Name of the context property to compare. + * @param {!(string|number)} expression The value to compare. + * @param {boolean=} opt_matchCase Case-sensitive? + * @extends {ol.format.ogc.filter.Comparison} + * @api + */ +ol.format.ogc.filter.ComparisonBinary = function( + tagName, propertyName, expression, opt_matchCase) { + + ol.format.ogc.filter.Comparison.call(this, tagName, propertyName); + + /** + * @public + * @type {!(string|number)} + */ + this.expression = expression; + + /** + * @public + * @type {boolean|undefined} + */ + this.matchCase = opt_matchCase; +}; +ol.inherits(ol.format.ogc.filter.ComparisonBinary, ol.format.ogc.filter.Comparison); diff --git a/src/ol/format/ogc/filter/equalto.js b/src/ol/format/ogc/filter/equalto.js new file mode 100644 index 0000000000..7cc78dd2c7 --- /dev/null +++ b/src/ol/format/ogc/filter/equalto.js @@ -0,0 +1,21 @@ +goog.provide('ol.format.ogc.filter.EqualTo'); + +goog.require('ol'); +goog.require('ol.format.ogc.filter.ComparisonBinary'); + + +/** + * @classdesc + * Represents a `` comparison operator. + * + * @constructor + * @param {!string} propertyName Name of the context property to compare. + * @param {!(string|number)} expression The value to compare. + * @param {boolean=} opt_matchCase Case-sensitive? + * @extends {ol.format.ogc.filter.ComparisonBinary} + * @api + */ +ol.format.ogc.filter.EqualTo = function(propertyName, expression, opt_matchCase) { + ol.format.ogc.filter.ComparisonBinary.call(this, 'PropertyIsEqualTo', propertyName, expression, opt_matchCase); +}; +ol.inherits(ol.format.ogc.filter.EqualTo, ol.format.ogc.filter.ComparisonBinary); diff --git a/src/ol/format/ogc/filter/filter.js b/src/ol/format/ogc/filter/filter.js new file mode 100644 index 0000000000..4d91067333 --- /dev/null +++ b/src/ol/format/ogc/filter/filter.js @@ -0,0 +1,31 @@ +goog.provide('ol.format.ogc.filter.Filter'); + +goog.require('ol'); + + +/** + * @classdesc + * Abstract class; normally only used for creating subclasses and not instantiated in apps. + * Base class for WFS GetFeature filters. + * + * @constructor + * @param {!string} tagName The XML tag name for this filter. + * @struct + * @api + */ +ol.format.ogc.filter.Filter = function(tagName) { + + /** + * @private + * @type {!string} + */ + this.tagName_ = tagName; +}; + +/** + * The XML tag name for a filter. + * @returns {!string} Name. + */ +ol.format.ogc.filter.Filter.prototype.getTagName = function() { + return this.tagName_; +}; diff --git a/src/ol/format/ogc/filter/greaterthan.js b/src/ol/format/ogc/filter/greaterthan.js new file mode 100644 index 0000000000..bf6ec9bcb8 --- /dev/null +++ b/src/ol/format/ogc/filter/greaterthan.js @@ -0,0 +1,20 @@ +goog.provide('ol.format.ogc.filter.GreaterThan'); + +goog.require('ol'); +goog.require('ol.format.ogc.filter.ComparisonBinary'); + + +/** + * @classdesc + * Represents a `` comparison operator. + * + * @constructor + * @param {!string} propertyName Name of the context property to compare. + * @param {!number} expression The value to compare. + * @extends {ol.format.ogc.filter.ComparisonBinary} + * @api + */ +ol.format.ogc.filter.GreaterThan = function(propertyName, expression) { + ol.format.ogc.filter.ComparisonBinary.call(this, 'PropertyIsGreaterThan', propertyName, expression); +}; +ol.inherits(ol.format.ogc.filter.GreaterThan, ol.format.ogc.filter.ComparisonBinary); diff --git a/src/ol/format/ogc/filter/greaterthanorequalto.js b/src/ol/format/ogc/filter/greaterthanorequalto.js new file mode 100644 index 0000000000..7b2cf12bda --- /dev/null +++ b/src/ol/format/ogc/filter/greaterthanorequalto.js @@ -0,0 +1,20 @@ +goog.provide('ol.format.ogc.filter.GreaterThanOrEqualTo'); + +goog.require('ol'); +goog.require('ol.format.ogc.filter.ComparisonBinary'); + + +/** + * @classdesc + * Represents a `` comparison operator. + * + * @constructor + * @param {!string} propertyName Name of the context property to compare. + * @param {!number} expression The value to compare. + * @extends {ol.format.ogc.filter.ComparisonBinary} + * @api + */ +ol.format.ogc.filter.GreaterThanOrEqualTo = function(propertyName, expression) { + ol.format.ogc.filter.ComparisonBinary.call(this, 'PropertyIsGreaterThanOrEqualTo', propertyName, expression); +}; +ol.inherits(ol.format.ogc.filter.GreaterThanOrEqualTo, ol.format.ogc.filter.ComparisonBinary); diff --git a/src/ol/format/ogc/filter/index.js b/src/ol/format/ogc/filter/index.js new file mode 100644 index 0000000000..7878652524 --- /dev/null +++ b/src/ol/format/ogc/filter/index.js @@ -0,0 +1,233 @@ +goog.provide('ol.format.ogc.filter'); + +goog.require('ol'); +goog.require('ol.format.ogc.filter.And'); +goog.require('ol.format.ogc.filter.Bbox'); +goog.require('ol.format.ogc.filter.EqualTo'); +goog.require('ol.format.ogc.filter.GreaterThan'); +goog.require('ol.format.ogc.filter.GreaterThanOrEqualTo'); +goog.require('ol.format.ogc.filter.Intersects'); +goog.require('ol.format.ogc.filter.IsBetween'); +goog.require('ol.format.ogc.filter.IsLike'); +goog.require('ol.format.ogc.filter.IsNull'); +goog.require('ol.format.ogc.filter.LessThan'); +goog.require('ol.format.ogc.filter.LessThanOrEqualTo'); +goog.require('ol.format.ogc.filter.Not'); +goog.require('ol.format.ogc.filter.NotEqualTo'); +goog.require('ol.format.ogc.filter.Or'); +goog.require('ol.format.ogc.filter.Within'); + + +/** + * Create a logical `` operator between two filter conditions. + * + * @param {!ol.format.ogc.filter.Filter} conditionA First filter condition. + * @param {!ol.format.ogc.filter.Filter} conditionB Second filter condition. + * @returns {!ol.format.ogc.filter.And} `` operator. + * @api + */ +ol.format.ogc.filter.and = function(conditionA, conditionB) { + return new ol.format.ogc.filter.And(conditionA, conditionB); +}; + + +/** + * Create a logical `` operator between two filter conditions. + * + * @param {!ol.format.ogc.filter.Filter} conditionA First filter condition. + * @param {!ol.format.ogc.filter.Filter} conditionB Second filter condition. + * @returns {!ol.format.ogc.filter.Or} `` operator. + * @api + */ +ol.format.ogc.filter.or = function(conditionA, conditionB) { + return new ol.format.ogc.filter.Or(conditionA, conditionB); +}; + + +/** + * Represents a logical `` operator for a filter condition. + * + * @param {!ol.format.ogc.filter.Filter} condition Filter condition. + * @returns {!ol.format.ogc.filter.Not} `` operator. + * @api + */ +ol.format.ogc.filter.not = function(condition) { + return new ol.format.ogc.filter.Not(condition); +}; + + +/** + * Create a `` operator to test whether a geometry-valued property + * intersects a fixed bounding box + * + * @param {!string} geometryName Geometry name to use. + * @param {!ol.Extent} extent Extent. + * @param {string=} opt_srsName SRS name. No srsName attribute will be + * set on geometries when this is not provided. + * @returns {!ol.format.ogc.filter.Bbox} `` operator. + * @api + */ +ol.format.ogc.filter.bbox = function(geometryName, extent, opt_srsName) { + return new ol.format.ogc.filter.Bbox(geometryName, extent, opt_srsName); +}; + +/** + * Create a `` operator to test whether a geometry-valued property + * intersects a given geometry. + * + * @param {!string} geometryName Geometry name to use. + * @param {!ol.geom.Geometry} geometry Geometry. + * @param {string=} opt_srsName SRS name. No srsName attribute will be + * set on geometries when this is not provided. + * @returns {!ol.format.ogc.filter.Intersects} `` operator. + * @api + */ +ol.format.ogc.filter.intersects = function(geometryName, geometry, opt_srsName) { + return new ol.format.ogc.filter.Intersects(geometryName, geometry, opt_srsName); +}; + +/** + * Create a `` operator to test whether a geometry-valued property + * is within a given geometry. + * + * @param {!string} geometryName Geometry name to use. + * @param {!ol.geom.Geometry} geometry Geometry. + * @param {string=} opt_srsName SRS name. No srsName attribute will be + * set on geometries when this is not provided. + * @returns {!ol.format.ogc.filter.Within} `` operator. + * @api + */ +ol.format.ogc.filter.within = function(geometryName, geometry, opt_srsName) { + return new ol.format.ogc.filter.Within(geometryName, geometry, opt_srsName); +}; + + +/** + * Creates a `` comparison operator. + * + * @param {!string} propertyName Name of the context property to compare. + * @param {!(string|number)} expression The value to compare. + * @param {boolean=} opt_matchCase Case-sensitive? + * @returns {!ol.format.ogc.filter.EqualTo} `` operator. + * @api + */ +ol.format.ogc.filter.equalTo = function(propertyName, expression, opt_matchCase) { + return new ol.format.ogc.filter.EqualTo(propertyName, expression, opt_matchCase); +}; + + +/** + * Creates a `` comparison operator. + * + * @param {!string} propertyName Name of the context property to compare. + * @param {!(string|number)} expression The value to compare. + * @param {boolean=} opt_matchCase Case-sensitive? + * @returns {!ol.format.ogc.filter.NotEqualTo} `` operator. + * @api + */ +ol.format.ogc.filter.notEqualTo = function(propertyName, expression, opt_matchCase) { + return new ol.format.ogc.filter.NotEqualTo(propertyName, expression, opt_matchCase); +}; + + +/** + * Creates a `` comparison operator. + * + * @param {!string} propertyName Name of the context property to compare. + * @param {!number} expression The value to compare. + * @returns {!ol.format.ogc.filter.LessThan} `` operator. + * @api + */ +ol.format.ogc.filter.lessThan = function(propertyName, expression) { + return new ol.format.ogc.filter.LessThan(propertyName, expression); +}; + + +/** + * Creates a `` comparison operator. + * + * @param {!string} propertyName Name of the context property to compare. + * @param {!number} expression The value to compare. + * @returns {!ol.format.ogc.filter.LessThanOrEqualTo} `` operator. + * @api + */ +ol.format.ogc.filter.lessThanOrEqualTo = function(propertyName, expression) { + return new ol.format.ogc.filter.LessThanOrEqualTo(propertyName, expression); +}; + + +/** + * Creates a `` comparison operator. + * + * @param {!string} propertyName Name of the context property to compare. + * @param {!number} expression The value to compare. + * @returns {!ol.format.ogc.filter.GreaterThan} `` operator. + * @api + */ +ol.format.ogc.filter.greaterThan = function(propertyName, expression) { + return new ol.format.ogc.filter.GreaterThan(propertyName, expression); +}; + + +/** + * Creates a `` comparison operator. + * + * @param {!string} propertyName Name of the context property to compare. + * @param {!number} expression The value to compare. + * @returns {!ol.format.ogc.filter.GreaterThanOrEqualTo} `` operator. + * @api + */ +ol.format.ogc.filter.greaterThanOrEqualTo = function(propertyName, expression) { + return new ol.format.ogc.filter.GreaterThanOrEqualTo(propertyName, expression); +}; + + +/** + * Creates a `` comparison operator to test whether a property value + * is null. + * + * @param {!string} propertyName Name of the context property to compare. + * @returns {!ol.format.ogc.filter.IsNull} `` operator. + * @api + */ +ol.format.ogc.filter.isNull = function(propertyName) { + return new ol.format.ogc.filter.IsNull(propertyName); +}; + + +/** + * Creates a `` comparison operator to test whether an expression + * value lies within a range given by a lower and upper bound (inclusive). + * + * @param {!string} propertyName Name of the context property to compare. + * @param {!number} lowerBoundary The lower bound of the range. + * @param {!number} upperBoundary The upper bound of the range. + * @returns {!ol.format.ogc.filter.IsBetween} `` operator. + * @api + */ +ol.format.ogc.filter.between = function(propertyName, lowerBoundary, upperBoundary) { + return new ol.format.ogc.filter.IsBetween(propertyName, lowerBoundary, upperBoundary); +}; + + +/** + * Represents a `` comparison operator that matches a string property + * value against a text pattern. + * + * @param {!string} propertyName Name of the context property to compare. + * @param {!string} pattern Text pattern. + * @param {string=} opt_wildCard Pattern character which matches any sequence of + * zero or more string characters. Default is '*'. + * @param {string=} opt_singleChar pattern character which matches any single + * string character. Default is '.'. + * @param {string=} opt_escapeChar Escape character which can be used to escape + * the pattern characters. Default is '!'. + * @param {boolean=} opt_matchCase Case-sensitive? + * @returns {!ol.format.ogc.filter.IsLike} `` operator. + * @api + */ +ol.format.ogc.filter.like = function(propertyName, pattern, + opt_wildCard, opt_singleChar, opt_escapeChar, opt_matchCase) { + return new ol.format.ogc.filter.IsLike(propertyName, pattern, + opt_wildCard, opt_singleChar, opt_escapeChar, opt_matchCase); +}; diff --git a/src/ol/format/ogc/filter.jsdoc b/src/ol/format/ogc/filter/index.jsdoc similarity index 100% rename from src/ol/format/ogc/filter.jsdoc rename to src/ol/format/ogc/filter/index.jsdoc diff --git a/src/ol/format/ogc/filter/intersects.js b/src/ol/format/ogc/filter/intersects.js new file mode 100644 index 0000000000..3a0b91c230 --- /dev/null +++ b/src/ol/format/ogc/filter/intersects.js @@ -0,0 +1,25 @@ +goog.provide('ol.format.ogc.filter.Intersects'); + +goog.require('ol'); +goog.require('ol.format.ogc.filter.Spatial'); + + +/** + * @classdesc + * Represents a `` operator to test whether a geometry-valued property + * intersects a given geometry. + * + * @constructor + * @param {!string} geometryName Geometry name to use. + * @param {!ol.geom.Geometry} geometry Geometry. + * @param {string=} opt_srsName SRS name. No srsName attribute will be + * set on geometries when this is not provided. + * @extends {ol.format.ogc.filter.Spatial} + * @api + */ +ol.format.ogc.filter.Intersects = function(geometryName, geometry, opt_srsName) { + + ol.format.ogc.filter.Spatial.call(this, 'Intersects', geometryName, geometry, opt_srsName); + +}; +ol.inherits(ol.format.ogc.filter.Intersects, ol.format.ogc.filter.Spatial); diff --git a/src/ol/format/ogc/filter/isbetween.js b/src/ol/format/ogc/filter/isbetween.js new file mode 100644 index 0000000000..bf49ca85b1 --- /dev/null +++ b/src/ol/format/ogc/filter/isbetween.js @@ -0,0 +1,33 @@ +goog.provide('ol.format.ogc.filter.IsBetween'); + +goog.require('ol'); +goog.require('ol.format.ogc.filter.Comparison'); + + +/** + * @classdesc + * Represents a `` comparison operator. + * + * @constructor + * @param {!string} propertyName Name of the context property to compare. + * @param {!number} lowerBoundary The lower bound of the range. + * @param {!number} upperBoundary The upper bound of the range. + * @extends {ol.format.ogc.filter.Comparison} + * @api + */ +ol.format.ogc.filter.IsBetween = function(propertyName, lowerBoundary, upperBoundary) { + ol.format.ogc.filter.Comparison.call(this, 'PropertyIsBetween', propertyName); + + /** + * @public + * @type {!number} + */ + this.lowerBoundary = lowerBoundary; + + /** + * @public + * @type {!number} + */ + this.upperBoundary = upperBoundary; +}; +ol.inherits(ol.format.ogc.filter.IsBetween, ol.format.ogc.filter.Comparison); diff --git a/src/ol/format/ogc/filter/islike.js b/src/ol/format/ogc/filter/islike.js new file mode 100644 index 0000000000..f136a8b064 --- /dev/null +++ b/src/ol/format/ogc/filter/islike.js @@ -0,0 +1,58 @@ +goog.provide('ol.format.ogc.filter.IsLike'); + +goog.require('ol'); +goog.require('ol.format.ogc.filter.Comparison'); + + +/** + * @classdesc + * Represents a `` comparison operator. + * + * @constructor + * @param {!string} propertyName Name of the context property to compare. + * @param {!string} pattern Text pattern. + * @param {string=} opt_wildCard Pattern character which matches any sequence of + * zero or more string characters. Default is '*'. + * @param {string=} opt_singleChar pattern character which matches any single + * string character. Default is '.'. + * @param {string=} opt_escapeChar Escape character which can be used to escape + * the pattern characters. Default is '!'. + * @param {boolean=} opt_matchCase Case-sensitive? + * @extends {ol.format.ogc.filter.Comparison} + * @api + */ +ol.format.ogc.filter.IsLike = function(propertyName, pattern, + opt_wildCard, opt_singleChar, opt_escapeChar, opt_matchCase) { + ol.format.ogc.filter.Comparison.call(this, 'PropertyIsLike', propertyName); + + /** + * @public + * @type {!string} + */ + this.pattern = pattern; + + /** + * @public + * @type {!string} + */ + this.wildCard = (opt_wildCard !== undefined) ? opt_wildCard : '*'; + + /** + * @public + * @type {!string} + */ + this.singleChar = (opt_singleChar !== undefined) ? opt_singleChar : '.'; + + /** + * @public + * @type {!string} + */ + this.escapeChar = (opt_escapeChar !== undefined) ? opt_escapeChar : '!'; + + /** + * @public + * @type {boolean|undefined} + */ + this.matchCase = opt_matchCase; +}; +ol.inherits(ol.format.ogc.filter.IsLike, ol.format.ogc.filter.Comparison); diff --git a/src/ol/format/ogc/filter/isnull.js b/src/ol/format/ogc/filter/isnull.js new file mode 100644 index 0000000000..9d48fb03a5 --- /dev/null +++ b/src/ol/format/ogc/filter/isnull.js @@ -0,0 +1,19 @@ +goog.provide('ol.format.ogc.filter.IsNull'); + +goog.require('ol'); +goog.require('ol.format.ogc.filter.Comparison'); + + +/** + * @classdesc + * Represents a `` comparison operator. + * + * @constructor + * @param {!string} propertyName Name of the context property to compare. + * @extends {ol.format.ogc.filter.Comparison} + * @api + */ +ol.format.ogc.filter.IsNull = function(propertyName) { + ol.format.ogc.filter.Comparison.call(this, 'PropertyIsNull', propertyName); +}; +ol.inherits(ol.format.ogc.filter.IsNull, ol.format.ogc.filter.Comparison); diff --git a/src/ol/format/ogc/filter/lessthan.js b/src/ol/format/ogc/filter/lessthan.js new file mode 100644 index 0000000000..0d233aa8d2 --- /dev/null +++ b/src/ol/format/ogc/filter/lessthan.js @@ -0,0 +1,20 @@ +goog.provide('ol.format.ogc.filter.LessThan'); + +goog.require('ol'); +goog.require('ol.format.ogc.filter.ComparisonBinary'); + + +/** + * @classdesc + * Represents a `` comparison operator. + * + * @constructor + * @param {!string} propertyName Name of the context property to compare. + * @param {!number} expression The value to compare. + * @extends {ol.format.ogc.filter.ComparisonBinary} + * @api + */ +ol.format.ogc.filter.LessThan = function(propertyName, expression) { + ol.format.ogc.filter.ComparisonBinary.call(this, 'PropertyIsLessThan', propertyName, expression); +}; +ol.inherits(ol.format.ogc.filter.LessThan, ol.format.ogc.filter.ComparisonBinary); diff --git a/src/ol/format/ogc/filter/lessthanorequalto.js b/src/ol/format/ogc/filter/lessthanorequalto.js new file mode 100644 index 0000000000..dd618e242c --- /dev/null +++ b/src/ol/format/ogc/filter/lessthanorequalto.js @@ -0,0 +1,20 @@ +goog.provide('ol.format.ogc.filter.LessThanOrEqualTo'); + +goog.require('ol'); +goog.require('ol.format.ogc.filter.ComparisonBinary'); + + +/** + * @classdesc + * Represents a `` comparison operator. + * + * @constructor + * @param {!string} propertyName Name of the context property to compare. + * @param {!number} expression The value to compare. + * @extends {ol.format.ogc.filter.ComparisonBinary} + * @api + */ +ol.format.ogc.filter.LessThanOrEqualTo = function(propertyName, expression) { + ol.format.ogc.filter.ComparisonBinary.call(this, 'PropertyIsLessThanOrEqualTo', propertyName, expression); +}; +ol.inherits(ol.format.ogc.filter.LessThanOrEqualTo, ol.format.ogc.filter.ComparisonBinary); diff --git a/src/ol/format/ogc/filter/logical.js b/src/ol/format/ogc/filter/logical.js new file mode 100644 index 0000000000..9a346ac059 --- /dev/null +++ b/src/ol/format/ogc/filter/logical.js @@ -0,0 +1,19 @@ +goog.provide('ol.format.ogc.filter.Logical'); + +goog.require('ol'); +goog.require('ol.format.ogc.filter.Filter'); + + +/** + * @classdesc + * Abstract class; normally only used for creating subclasses and not instantiated in apps. + * Base class for WFS GetFeature logical filters. + * + * @constructor + * @param {!string} tagName The XML tag name for this filter. + * @extends {ol.format.ogc.filter.Filter} + */ +ol.format.ogc.filter.Logical = function(tagName) { + ol.format.ogc.filter.Filter.call(this, tagName); +}; +ol.inherits(ol.format.ogc.filter.Logical, ol.format.ogc.filter.Filter); diff --git a/src/ol/format/ogc/filter/logicalbinary.js b/src/ol/format/ogc/filter/logicalbinary.js new file mode 100644 index 0000000000..06eae237c5 --- /dev/null +++ b/src/ol/format/ogc/filter/logicalbinary.js @@ -0,0 +1,35 @@ +goog.provide('ol.format.ogc.filter.LogicalBinary'); + +goog.require('ol'); +goog.require('ol.format.ogc.filter.Logical'); + + +/** + * @classdesc + * Abstract class; normally only used for creating subclasses and not instantiated in apps. + * Base class for WFS GetFeature binary logical filters. + * + * @constructor + * @param {!string} tagName The XML tag name for this filter. + * @param {!ol.format.ogc.filter.Filter} conditionA First filter condition. + * @param {!ol.format.ogc.filter.Filter} conditionB Second filter condition. + * @extends {ol.format.ogc.filter.Logical} + */ +ol.format.ogc.filter.LogicalBinary = function(tagName, conditionA, conditionB) { + + ol.format.ogc.filter.Logical.call(this, tagName); + + /** + * @public + * @type {!ol.format.ogc.filter.Filter} + */ + this.conditionA = conditionA; + + /** + * @public + * @type {!ol.format.ogc.filter.Filter} + */ + this.conditionB = conditionB; + +}; +ol.inherits(ol.format.ogc.filter.LogicalBinary, ol.format.ogc.filter.Logical); diff --git a/src/ol/format/ogc/filter/not.js b/src/ol/format/ogc/filter/not.js new file mode 100644 index 0000000000..2e23622080 --- /dev/null +++ b/src/ol/format/ogc/filter/not.js @@ -0,0 +1,26 @@ +goog.provide('ol.format.ogc.filter.Not'); + +goog.require('ol'); +goog.require('ol.format.ogc.filter.Logical'); + + +/** + * @classdesc + * Represents a logical `` operator for a filter condition. + * + * @constructor + * @param {!ol.format.ogc.filter.Filter} condition Filter condition. + * @extends {ol.format.ogc.filter.Logical} + * @api + */ +ol.format.ogc.filter.Not = function(condition) { + + ol.format.ogc.filter.Logical.call(this, 'Not'); + + /** + * @public + * @type {!ol.format.ogc.filter.Filter} + */ + this.condition = condition; +}; +ol.inherits(ol.format.ogc.filter.Not, ol.format.ogc.filter.Logical); diff --git a/src/ol/format/ogc/filter/notequalto.js b/src/ol/format/ogc/filter/notequalto.js new file mode 100644 index 0000000000..fb56616f4f --- /dev/null +++ b/src/ol/format/ogc/filter/notequalto.js @@ -0,0 +1,21 @@ +goog.provide('ol.format.ogc.filter.NotEqualTo'); + +goog.require('ol'); +goog.require('ol.format.ogc.filter.ComparisonBinary'); + + +/** + * @classdesc + * Represents a `` comparison operator. + * + * @constructor + * @param {!string} propertyName Name of the context property to compare. + * @param {!(string|number)} expression The value to compare. + * @param {boolean=} opt_matchCase Case-sensitive? + * @extends {ol.format.ogc.filter.ComparisonBinary} + * @api + */ +ol.format.ogc.filter.NotEqualTo = function(propertyName, expression, opt_matchCase) { + ol.format.ogc.filter.ComparisonBinary.call(this, 'PropertyIsNotEqualTo', propertyName, expression, opt_matchCase); +}; +ol.inherits(ol.format.ogc.filter.NotEqualTo, ol.format.ogc.filter.ComparisonBinary); diff --git a/src/ol/format/ogc/filter/or.js b/src/ol/format/ogc/filter/or.js new file mode 100644 index 0000000000..c38778581c --- /dev/null +++ b/src/ol/format/ogc/filter/or.js @@ -0,0 +1,20 @@ +goog.provide('ol.format.ogc.filter.Or'); + +goog.require('ol'); +goog.require('ol.format.ogc.filter.LogicalBinary'); + + +/** + * @classdesc + * Represents a logical `` operator between two filter conditions. + * + * @constructor + * @param {!ol.format.ogc.filter.Filter} conditionA First filter condition. + * @param {!ol.format.ogc.filter.Filter} conditionB Second filter condition. + * @extends {ol.format.ogc.filter.LogicalBinary} + * @api + */ +ol.format.ogc.filter.Or = function(conditionA, conditionB) { + ol.format.ogc.filter.LogicalBinary.call(this, 'Or', conditionA, conditionB); +}; +ol.inherits(ol.format.ogc.filter.Or, ol.format.ogc.filter.LogicalBinary); diff --git a/src/ol/format/ogc/filter/spatial.js b/src/ol/format/ogc/filter/spatial.js new file mode 100644 index 0000000000..645bd74c08 --- /dev/null +++ b/src/ol/format/ogc/filter/spatial.js @@ -0,0 +1,43 @@ +goog.provide('ol.format.ogc.filter.Spatial'); + +goog.require('ol'); +goog.require('ol.format.ogc.filter.Filter'); + + +/** + * @classdesc + * Represents a spatial operator to test whether a geometry-valued property + * relates to a given geometry. + * + * @constructor + * @param {!string} tagName The XML tag name for this filter. + * @param {!string} geometryName Geometry name to use. + * @param {!ol.geom.Geometry} geometry Geometry. + * @param {string=} opt_srsName SRS name. No srsName attribute will be + * set on geometries when this is not provided. + * @extends {ol.format.ogc.filter.Filter} + * @api + */ +ol.format.ogc.filter.Spatial = function(tagName, geometryName, geometry, opt_srsName) { + + ol.format.ogc.filter.Filter.call(this, tagName); + + /** + * @public + * @type {!string} + */ + this.geometryName = geometryName || 'the_geom'; + + /** + * @public + * @type {ol.geom.Geometry} + */ + this.geometry = geometry; + + /** + * @public + * @type {string|undefined} + */ + this.srsName = opt_srsName; +}; +ol.inherits(ol.format.ogc.filter.Spatial, ol.format.ogc.filter.Filter); diff --git a/src/ol/format/ogc/filter/within.js b/src/ol/format/ogc/filter/within.js new file mode 100644 index 0000000000..4280ca4219 --- /dev/null +++ b/src/ol/format/ogc/filter/within.js @@ -0,0 +1,25 @@ +goog.provide('ol.format.ogc.filter.Within'); + +goog.require('ol'); +goog.require('ol.format.ogc.filter.Spatial'); + + +/** + * @classdesc + * Represents a `` operator to test whether a geometry-valued property + * is within a given geometry. + * + * @constructor + * @param {!string} geometryName Geometry name to use. + * @param {!ol.geom.Geometry} geometry Geometry. + * @param {string=} opt_srsName SRS name. No srsName attribute will be + * set on geometries when this is not provided. + * @extends {ol.format.ogc.filter.Spatial} + * @api + */ +ol.format.ogc.filter.Within = function(geometryName, geometry, opt_srsName) { + + ol.format.ogc.filter.Spatial.call(this, 'Within', geometryName, geometry, opt_srsName); + +}; +ol.inherits(ol.format.ogc.filter.Within, ol.format.ogc.filter.Spatial); diff --git a/src/ol/format/polyline.js b/src/ol/format/polyline.js index b00d2b2216..a7b3a8ad40 100644 --- a/src/ol/format/polyline.js +++ b/src/ol/format/polyline.js @@ -355,7 +355,7 @@ ol.format.Polyline.prototype.writeFeatureText = function(feature, opt_options) { if (geometry) { return this.writeGeometryText(geometry, opt_options); } else { - ol.assert(false, 40); // Expected `feature` to have a geometry + ol.asserts.assert(false, 40); // Expected `feature` to have a geometry return ''; } }; diff --git a/src/ol/format/wfs.js b/src/ol/format/wfs.js index b76bbbf747..185e5c97e2 100644 --- a/src/ol/format/wfs.js +++ b/src/ol/format/wfs.js @@ -386,7 +386,7 @@ ol.format.WFS.writeOgcFidFilter_ = function(node, fid, objectStack) { */ ol.format.WFS.writeDelete_ = function(node, feature, objectStack) { var context = objectStack[objectStack.length - 1]; - ol.assert(feature.getId() !== undefined, 26); // Features must have an id set + ol.asserts.assert(feature.getId() !== undefined, 26); // Features must have an id set var featureType = context['featureType']; var featurePrefix = context['featurePrefix']; featurePrefix = featurePrefix ? featurePrefix : @@ -410,7 +410,7 @@ ol.format.WFS.writeDelete_ = function(node, feature, objectStack) { */ ol.format.WFS.writeUpdate_ = function(node, feature, objectStack) { var context = objectStack[objectStack.length - 1]; - ol.assert(feature.getId() !== undefined, 27); // Features must have an id set + ol.asserts.assert(feature.getId() !== undefined, 27); // Features must have an id set var featureType = context['featureType']; var featurePrefix = context['featurePrefix']; featurePrefix = featurePrefix ? featurePrefix : @@ -802,7 +802,7 @@ ol.format.WFS.prototype.writeGetFeature = function(options) { } filter = options.filter; if (options.bbox) { - ol.assert(options.geometryName, + ol.asserts.assert(options.geometryName, 12); // `options.geometryName` must also be provided when `options.bbox` is set var bbox = ol.format.ogc.filter.bbox( /** @type {string} */ (options.geometryName), options.bbox, options.srsName); @@ -826,7 +826,7 @@ ol.format.WFS.prototype.writeGetFeature = function(options) { 'filter': filter, 'propertyNames': options.propertyNames ? options.propertyNames : [] }; - ol.assert(Array.isArray(options.featureTypes), + ol.asserts.assert(Array.isArray(options.featureTypes), 11); // `options.featureTypes` should be an Array ol.format.WFS.writeGetFeature_(node, /** @type {!Array.} */ (options.featureTypes), [context]); return node; diff --git a/src/ol/geom/simplegeometry.js b/src/ol/geom/simplegeometry.js index dbc739ec4a..083e598653 100644 --- a/src/ol/geom/simplegeometry.js +++ b/src/ol/geom/simplegeometry.js @@ -323,7 +323,7 @@ ol.geom.SimpleGeometry.prototype.translate = function(deltaX, deltaY) { * @param {Array.=} opt_dest Destination. * @return {Array.} Transformed flat coordinates. */ -ol.geom.transformSimpleGeometry2D = function(simpleGeometry, transform, opt_dest) { +ol.geom.SimpleGeometry.transform2D = function(simpleGeometry, transform, opt_dest) { var flatCoordinates = simpleGeometry.getFlatCoordinates(); if (!flatCoordinates) { return null; diff --git a/src/ol/imagecanvas.js b/src/ol/imagecanvas.js index 453c5e6cba..9b05fc87aa 100644 --- a/src/ol/imagecanvas.js +++ b/src/ol/imagecanvas.js @@ -1,5 +1,6 @@ goog.provide('ol.ImageCanvas'); +goog.require('ol'); goog.require('ol.ImageBase'); goog.require('ol.ImageState'); diff --git a/src/ol/imagetile.js b/src/ol/imagetile.js index 3fc9072891..27420d9573 100644 --- a/src/ol/imagetile.js +++ b/src/ol/imagetile.js @@ -1,7 +1,6 @@ goog.provide('ol.ImageTile'); goog.require('ol.Tile'); -goog.require('ol.TileState'); goog.require('ol.events'); goog.require('ol.events.EventType'); goog.require('ol.obj'); @@ -11,7 +10,7 @@ goog.require('ol.obj'); * @constructor * @extends {ol.Tile} * @param {ol.TileCoord} tileCoord Tile coordinate. - * @param {ol.TileState} state State. + * @param {ol.Tile.State} state State. * @param {string} src Image source URI. * @param {?string} crossOrigin Cross origin. * @param {ol.TileLoadFunctionType} tileLoadFunction Tile load function. @@ -63,13 +62,13 @@ ol.inherits(ol.ImageTile, ol.Tile); * @inheritDoc */ ol.ImageTile.prototype.disposeInternal = function() { - if (this.state == ol.TileState.LOADING) { + if (this.state == ol.Tile.State.LOADING) { this.unlistenImage_(); } if (this.interimTile) { this.interimTile.dispose(); } - this.state = ol.TileState.ABORT; + this.state = ol.Tile.State.ABORT; this.changed(); ol.Tile.prototype.disposeInternal.call(this); }; @@ -113,7 +112,7 @@ ol.ImageTile.prototype.getKey = function() { * @private */ ol.ImageTile.prototype.handleImageError_ = function() { - this.state = ol.TileState.ERROR; + this.state = ol.Tile.State.ERROR; this.unlistenImage_(); this.changed(); }; @@ -126,9 +125,9 @@ ol.ImageTile.prototype.handleImageError_ = function() { */ ol.ImageTile.prototype.handleImageLoad_ = function() { if (this.image_.naturalWidth && this.image_.naturalHeight) { - this.state = ol.TileState.LOADED; + this.state = ol.Tile.State.LOADED; } else { - this.state = ol.TileState.EMPTY; + this.state = ol.Tile.State.EMPTY; } this.unlistenImage_(); this.changed(); @@ -142,8 +141,8 @@ ol.ImageTile.prototype.handleImageLoad_ = function() { * @api */ ol.ImageTile.prototype.load = function() { - if (this.state == ol.TileState.IDLE || this.state == ol.TileState.ERROR) { - this.state = ol.TileState.LOADING; + if (this.state == ol.Tile.State.IDLE || this.state == ol.Tile.State.ERROR) { + this.state = ol.Tile.State.LOADING; this.changed(); goog.DEBUG && console.assert(!this.imageListenerKeys_, 'this.imageListenerKeys_ should be null'); diff --git a/src/ol/index.js b/src/ol/index.js index e195cff740..9f5f0422f4 100644 --- a/src/ol/index.js +++ b/src/ol/index.js @@ -173,7 +173,7 @@ ol.OVERVIEWMAP_MIN_RATIO = 0.1; * This can happen if the developer defines projections improperly and/or * with unlimited extents. * If too many tiles are required, no tiles are loaded and - * `ol.TileState.ERROR` state is set. Default is `100`. + * `ol.Tile.State.ERROR` state is set. Default is `100`. */ ol.RASTER_REPROJECTION_MAX_SOURCE_TILES = 100; @@ -303,48 +303,3 @@ if (typeof window !== 'undefined') { } else if (typeof self !== 'undefined') { ol.global = self; } - - -/** - * Error object thrown when an assertion failed. This is an ECMA-262 Error, - * extended with a `code` property. - * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error} - * @constructor - * @extends {Error} - * @implements {oli.AssertionError} - * @param {number} code Error code. - */ -ol.AssertionError = function(code) { - - /** - * @type {string} - */ - this.message = 'Assertion failed. See ' + - (ol.VERSION ? 'http://openlayers.org/en/' + ol.VERSION.split('-')[0] : '') + - '/doc/errors/#' + code + ' for details.'; - - /** - * Error code. The meaning of the code can be found on - * {@link http://openlayers.org/en/latest/errors.html} (replace `latest` with - * the version found in the OpenLayers script's header comment if a version - * other than the latest is used). - * @type {number} - * @api - */ - this.code = code; - - this.name = 'AssertionError'; - -}; -ol.inherits(ol.AssertionError, Error); - - -/** - * @param {*} assertion Assertion we expected to be truthy. - * @param {number} errorCode Error code. - */ -ol.assert = function(assertion, errorCode) { - if (!assertion) { - throw new ol.AssertionError(errorCode); - } -}; diff --git a/src/ol/interaction/dragpan.js b/src/ol/interaction/dragpan.js index fcad8b3af6..f69596ba12 100644 --- a/src/ol/interaction/dragpan.js +++ b/src/ol/interaction/dragpan.js @@ -1,9 +1,9 @@ goog.provide('ol.interaction.DragPan'); -goog.require('ol.ViewHint'); +goog.require('ol.View'); goog.require('ol.coordinate'); -goog.require('ol.functions'); goog.require('ol.events.condition'); +goog.require('ol.functions'); goog.require('ol.interaction.Pointer'); @@ -115,7 +115,7 @@ ol.interaction.DragPan.handleUpEvent_ = function(mapBrowserEvent) { dest = view.constrainCenter(dest); view.setCenter(dest); } - view.setHint(ol.ViewHint.INTERACTING, -1); + view.setHint(ol.View.Hint.INTERACTING, -1); map.render(); return false; } else { @@ -137,7 +137,7 @@ ol.interaction.DragPan.handleDownEvent_ = function(mapBrowserEvent) { var view = map.getView(); this.lastCentroid = null; if (!this.handlingDownUpSequence) { - view.setHint(ol.ViewHint.INTERACTING, 1); + view.setHint(ol.View.Hint.INTERACTING, 1); } map.render(); if (this.kineticPreRenderFn_ && diff --git a/src/ol/interaction/dragrotate.js b/src/ol/interaction/dragrotate.js index 3d3a85833f..487492e6de 100644 --- a/src/ol/interaction/dragrotate.js +++ b/src/ol/interaction/dragrotate.js @@ -1,9 +1,9 @@ goog.provide('ol.interaction.DragRotate'); goog.require('ol'); -goog.require('ol.ViewHint'); -goog.require('ol.functions'); +goog.require('ol.View'); goog.require('ol.events.condition'); +goog.require('ol.functions'); goog.require('ol.interaction.Interaction'); goog.require('ol.interaction.Pointer'); @@ -93,7 +93,7 @@ ol.interaction.DragRotate.handleUpEvent_ = function(mapBrowserEvent) { var map = mapBrowserEvent.map; var view = map.getView(); - view.setHint(ol.ViewHint.INTERACTING, -1); + view.setHint(ol.View.Hint.INTERACTING, -1); var rotation = view.getRotation(); ol.interaction.Interaction.rotate(map, view, rotation, undefined, this.duration_); @@ -115,7 +115,7 @@ ol.interaction.DragRotate.handleDownEvent_ = function(mapBrowserEvent) { if (ol.events.condition.mouseActionButton(mapBrowserEvent) && this.condition_(mapBrowserEvent)) { var map = mapBrowserEvent.map; - map.getView().setHint(ol.ViewHint.INTERACTING, 1); + map.getView().setHint(ol.View.Hint.INTERACTING, 1); map.render(); this.lastAngle_ = undefined; return true; diff --git a/src/ol/interaction/dragrotateandzoom.js b/src/ol/interaction/dragrotateandzoom.js index 8917568133..07ed84e985 100644 --- a/src/ol/interaction/dragrotateandzoom.js +++ b/src/ol/interaction/dragrotateandzoom.js @@ -1,7 +1,7 @@ goog.provide('ol.interaction.DragRotateAndZoom'); goog.require('ol'); -goog.require('ol.ViewHint'); +goog.require('ol.View'); goog.require('ol.events.condition'); goog.require('ol.interaction.Interaction'); goog.require('ol.interaction.Pointer'); @@ -116,7 +116,7 @@ ol.interaction.DragRotateAndZoom.handleUpEvent_ = function(mapBrowserEvent) { var map = mapBrowserEvent.map; var view = map.getView(); - view.setHint(ol.ViewHint.INTERACTING, -1); + view.setHint(ol.View.Hint.INTERACTING, -1); var direction = this.lastScaleDelta_ - 1; ol.interaction.Interaction.rotate(map, view, view.getRotation()); ol.interaction.Interaction.zoom(map, view, view.getResolution(), @@ -138,7 +138,7 @@ ol.interaction.DragRotateAndZoom.handleDownEvent_ = function(mapBrowserEvent) { } if (this.condition_(mapBrowserEvent)) { - mapBrowserEvent.map.getView().setHint(ol.ViewHint.INTERACTING, 1); + mapBrowserEvent.map.getView().setHint(ol.View.Hint.INTERACTING, 1); this.lastAngle_ = undefined; this.lastMagnitude_ = undefined; return true; diff --git a/src/ol/interaction/draw.js b/src/ol/interaction/draw.js index bd811df36a..e4eba5d6e4 100644 --- a/src/ol/interaction/draw.js +++ b/src/ol/interaction/draw.js @@ -312,7 +312,7 @@ ol.inherits(ol.interaction.Draw, ol.interaction.Pointer); * @return {ol.StyleFunction} Styles. */ ol.interaction.Draw.getDefaultStyleFunction = function() { - var styles = ol.style.createDefaultEditingStyles(); + var styles = ol.style.Style.createDefaultEditing(); return function(feature, resolution) { return styles[feature.getGeometry().getType()]; }; diff --git a/src/ol/interaction/modify.js b/src/ol/interaction/modify.js index 34d37b93c8..fcc9d4f07c 100644 --- a/src/ol/interaction/modify.js +++ b/src/ol/interaction/modify.js @@ -1,17 +1,17 @@ goog.provide('ol.interaction.Modify'); goog.provide('ol.interaction.ModifyEvent'); -goog.require('ol.events'); -goog.require('ol.events.Event'); -goog.require('ol.events.EventType'); goog.require('ol'); goog.require('ol.Collection'); goog.require('ol.Feature'); goog.require('ol.MapBrowserEvent.EventType'); goog.require('ol.MapBrowserPointerEvent'); -goog.require('ol.ViewHint'); +goog.require('ol.View'); goog.require('ol.array'); goog.require('ol.coordinate'); +goog.require('ol.events'); +goog.require('ol.events.Event'); +goog.require('ol.events.EventType'); goog.require('ol.events.condition'); goog.require('ol.extent'); goog.require('ol.geom.GeometryType'); @@ -696,7 +696,7 @@ ol.interaction.Modify.handleEvent = function(mapBrowserEvent) { this.lastPointerEvent_ = mapBrowserEvent; var handled; - if (!mapBrowserEvent.map.getView().getHints()[ol.ViewHint.INTERACTING] && + if (!mapBrowserEvent.map.getView().getHints()[ol.View.Hint.INTERACTING] && mapBrowserEvent.type == ol.MapBrowserEvent.EventType.POINTERMOVE && !this.handlingDownUpSequence) { this.handlePointerMove_(mapBrowserEvent); @@ -1034,7 +1034,7 @@ ol.interaction.Modify.prototype.updateSegmentIndices_ = function( * @return {ol.StyleFunction} Styles. */ ol.interaction.Modify.getDefaultStyleFunction = function() { - var style = ol.style.createDefaultEditingStyles(); + var style = ol.style.Style.createDefaultEditing(); return function(feature, resolution) { return style[ol.geom.GeometryType.POINT]; }; diff --git a/src/ol/interaction/pinchrotate.js b/src/ol/interaction/pinchrotate.js index 21ce53fe22..5b6e125510 100644 --- a/src/ol/interaction/pinchrotate.js +++ b/src/ol/interaction/pinchrotate.js @@ -1,8 +1,8 @@ goog.provide('ol.interaction.PinchRotate'); goog.require('ol'); +goog.require('ol.View'); goog.require('ol.functions'); -goog.require('ol.ViewHint'); goog.require('ol.interaction.Interaction'); goog.require('ol.interaction.Pointer'); @@ -128,7 +128,7 @@ ol.interaction.PinchRotate.handleUpEvent_ = function(mapBrowserEvent) { if (this.targetPointers.length < 2) { var map = mapBrowserEvent.map; var view = map.getView(); - view.setHint(ol.ViewHint.INTERACTING, -1); + view.setHint(ol.View.Hint.INTERACTING, -1); if (this.rotating_) { var rotation = view.getRotation(); ol.interaction.Interaction.rotate( @@ -155,7 +155,7 @@ ol.interaction.PinchRotate.handleDownEvent_ = function(mapBrowserEvent) { this.rotating_ = false; this.rotationDelta_ = 0.0; if (!this.handlingDownUpSequence) { - map.getView().setHint(ol.ViewHint.INTERACTING, 1); + map.getView().setHint(ol.View.Hint.INTERACTING, 1); } map.render(); return true; diff --git a/src/ol/interaction/pinchzoom.js b/src/ol/interaction/pinchzoom.js index f101fea0b7..5497cf78ef 100644 --- a/src/ol/interaction/pinchzoom.js +++ b/src/ol/interaction/pinchzoom.js @@ -1,8 +1,8 @@ goog.provide('ol.interaction.PinchZoom'); goog.require('ol'); +goog.require('ol.View'); goog.require('ol.functions'); -goog.require('ol.ViewHint'); goog.require('ol.interaction.Interaction'); goog.require('ol.interaction.Pointer'); @@ -110,7 +110,7 @@ ol.interaction.PinchZoom.handleUpEvent_ = function(mapBrowserEvent) { if (this.targetPointers.length < 2) { var map = mapBrowserEvent.map; var view = map.getView(); - view.setHint(ol.ViewHint.INTERACTING, -1); + view.setHint(ol.View.Hint.INTERACTING, -1); var resolution = view.getResolution(); // Zoom to final resolution, with an animation, and provide a // direction not to zoom out/in if user was pinching in/out. @@ -138,7 +138,7 @@ ol.interaction.PinchZoom.handleDownEvent_ = function(mapBrowserEvent) { this.lastDistance_ = undefined; this.lastScaleDelta_ = 1; if (!this.handlingDownUpSequence) { - map.getView().setHint(ol.ViewHint.INTERACTING, 1); + map.getView().setHint(ol.View.Hint.INTERACTING, 1); } map.render(); return true; diff --git a/src/ol/interaction/select.js b/src/ol/interaction/select.js index ef634e00b0..b79f016914 100644 --- a/src/ol/interaction/select.js +++ b/src/ol/interaction/select.js @@ -225,7 +225,7 @@ ol.interaction.Select.prototype.getFeatures = function() { * @api */ ol.interaction.Select.prototype.getLayer = function(feature) { - ol.assert(feature instanceof ol.Feature, + ol.asserts.assert(feature instanceof ol.Feature, 42); // Expected an `ol.Feature`, but got an `ol.RenderFeature` var key = ol.getUid(feature); return /** @type {ol.layer.Vector} */ (this.featureLayerAssociation_[key]); @@ -342,7 +342,7 @@ ol.interaction.Select.prototype.setMap = function(map) { * @return {ol.StyleFunction} Styles. */ ol.interaction.Select.getDefaultStyleFunction = function() { - var styles = ol.style.createDefaultEditingStyles(); + var styles = ol.style.Style.createDefaultEditing(); ol.array.extend(styles[ol.geom.GeometryType.POLYGON], styles[ol.geom.GeometryType.LINE_STRING]); ol.array.extend(styles[ol.geom.GeometryType.GEOMETRY_COLLECTION], diff --git a/src/ol/layer/group.js b/src/ol/layer/group.js index f982001055..4406463e71 100644 --- a/src/ol/layer/group.js +++ b/src/ol/layer/group.js @@ -61,7 +61,7 @@ ol.layer.Group = function(opt_options) { if (Array.isArray(layers)) { layers = new ol.Collection(layers.slice()); } else { - ol.assert(layers instanceof ol.Collection, + ol.asserts.assert(layers instanceof ol.Collection, 43); // Expected `layers` to be an array or an `ol.Collection` layers = layers; } diff --git a/src/ol/layer/vector.js b/src/ol/layer/vector.js index e4681b9aca..3e532b816c 100644 --- a/src/ol/layer/vector.js +++ b/src/ol/layer/vector.js @@ -177,8 +177,8 @@ ol.layer.Vector.prototype.setRenderOrder = function(renderOrder) { * @api stable */ ol.layer.Vector.prototype.setStyle = function(style) { - this.style_ = style !== undefined ? style : ol.style.defaultStyleFunction; + this.style_ = style !== undefined ? style : ol.style.Style.defaultFunction; this.styleFunction_ = style === null ? - undefined : ol.style.createStyleFunction(this.style_); + undefined : ol.style.Style.createFunction(this.style_); this.changed(); }; diff --git a/src/ol/layer/vectortile.js b/src/ol/layer/vectortile.js index fd84333365..6a3410cb0e 100644 --- a/src/ol/layer/vectortile.js +++ b/src/ol/layer/vectortile.js @@ -58,7 +58,7 @@ ol.layer.VectorTile = function(opt_options) { this.setUseInterimTilesOnError(options.useInterimTilesOnError ? options.useInterimTilesOnError : true); - ol.assert(options.renderMode == undefined || + ol.asserts.assert(options.renderMode == undefined || options.renderMode == ol.layer.VectorTileRenderType.IMAGE || options.renderMode == ol.layer.VectorTileRenderType.HYBRID || options.renderMode == ol.layer.VectorTileRenderType.VECTOR, diff --git a/src/ol/map.js b/src/ol/map.js index 542a6ab91c..61ae009284 100644 --- a/src/ol/map.js +++ b/src/ol/map.js @@ -17,7 +17,6 @@ goog.require('ol.ObjectEventType'); goog.require('ol.RendererType'); goog.require('ol.TileQueue'); goog.require('ol.View'); -goog.require('ol.ViewHint'); goog.require('ol.array'); goog.require('ol.control'); goog.require('ol.dom'); @@ -29,7 +28,6 @@ goog.require('ol.functions'); goog.require('ol.has'); goog.require('ol.interaction'); goog.require('ol.layer.Group'); -goog.require('ol.transform'); goog.require('ol.obj'); goog.require('ol.proj.common'); goog.require('ol.renderer.Map'); @@ -38,6 +36,7 @@ goog.require('ol.renderer.dom.Map'); goog.require('ol.renderer.webgl.Map'); goog.require('ol.size'); goog.require('ol.structs.PriorityQueue'); +goog.require('ol.transform'); /** @@ -1003,11 +1002,11 @@ ol.Map.prototype.handlePostRender = function() { var maxNewLoads = maxTotalLoading; if (frameState) { var hints = frameState.viewHints; - if (hints[ol.ViewHint.ANIMATING]) { + if (hints[ol.View.Hint.ANIMATING]) { maxTotalLoading = this.loadTilesWhileAnimating_ ? 8 : 0; maxNewLoads = 2; } - if (hints[ol.ViewHint.INTERACTING]) { + if (hints[ol.View.Hint.INTERACTING]) { maxTotalLoading = this.loadTilesWhileInteracting_ ? 8 : 0; maxNewLoads = 2; } @@ -1299,8 +1298,8 @@ ol.Map.prototype.renderFrame_ = function(time) { this.postRenderFunctions_, frameState.postRenderFunctions); var idle = this.preRenderFunctions_.length === 0 && - !frameState.viewHints[ol.ViewHint.ANIMATING] && - !frameState.viewHints[ol.ViewHint.INTERACTING] && + !frameState.viewHints[ol.View.Hint.ANIMATING] && + !frameState.viewHints[ol.View.Hint.INTERACTING] && !ol.extent.equals(frameState.extent, this.previousExtent_); if (idle) { @@ -1444,8 +1443,8 @@ ol.Map.createOptionsInternal = function(options) { } else if (logo instanceof HTMLElement) { logos[ol.getUid(logo).toString()] = logo; } else if (logo) { - ol.assert(typeof logo.href == 'string', 44); // `logo.href` should be a string. - ol.assert(typeof logo.src == 'string', 45); // `logo.src` should be a string. + ol.asserts.assert(typeof logo.href == 'string', 44); // `logo.href` should be a string. + ol.asserts.assert(typeof logo.src == 'string', 45); // `logo.src` should be a string. logos[logo.src] = logo.href; } } @@ -1474,7 +1473,7 @@ ol.Map.createOptionsInternal = function(options) { } else if (typeof options.renderer === 'string') { rendererTypes = [options.renderer]; } else { - ol.assert(false, 46); // Incorrect format for `renderer` option + ol.asserts.assert(false, 46); // Incorrect format for `renderer` option } } else { rendererTypes = ol.DEFAULT_RENDERER_TYPES; @@ -1507,7 +1506,7 @@ ol.Map.createOptionsInternal = function(options) { if (Array.isArray(options.controls)) { controls = new ol.Collection(options.controls.slice()); } else { - ol.assert(options.controls instanceof ol.Collection, + ol.asserts.assert(options.controls instanceof ol.Collection, 47); // Expected `controls` to be an array or an `ol.Collection` controls = options.controls; } @@ -1520,7 +1519,7 @@ ol.Map.createOptionsInternal = function(options) { if (Array.isArray(options.interactions)) { interactions = new ol.Collection(options.interactions.slice()); } else { - ol.assert(options.interactions instanceof ol.Collection, + ol.asserts.assert(options.interactions instanceof ol.Collection, 48); // Expected `interactions` to be an array or an `ol.Collection` interactions = options.interactions; } @@ -1533,7 +1532,7 @@ ol.Map.createOptionsInternal = function(options) { if (Array.isArray(options.overlays)) { overlays = new ol.Collection(options.overlays.slice()); } else { - ol.assert(options.overlays instanceof ol.Collection, + ol.asserts.assert(options.overlays instanceof ol.Collection, 49); // Expected `overlays` to be an array or an `ol.Collection` overlays = options.overlays; } diff --git a/src/ol/math.js b/src/ol/math.js index 96892c6818..d5308896b6 100644 --- a/src/ol/math.js +++ b/src/ol/math.js @@ -46,7 +46,7 @@ ol.math.cosh = (function() { * @return {number} The smallest power of two greater than or equal to x. */ ol.math.roundUpToPowerOfTwo = function(x) { - ol.assert(0 < x, 29); // `x` must be greater than `0` + ol.asserts.assert(0 < x, 29); // `x` must be greater than `0` return Math.pow(2, Math.ceil(Math.log(x) / Math.LN2)); }; diff --git a/src/ol/pointer/touchsource.js b/src/ol/pointer/touchsource.js index 38e2842df6..e20dd8c072 100644 --- a/src/ol/pointer/touchsource.js +++ b/src/ol/pointer/touchsource.js @@ -148,7 +148,8 @@ ol.pointer.TouchSource.prototype.removePrimaryPointer_ = function(inPointer) { * @private */ ol.pointer.TouchSource.prototype.resetClickCount_ = function() { - this.resetId_ = ol.global.setTimeout( + var global = ol.global; + this.resetId_ = global.setTimeout( this.resetClickCountHandler_.bind(this), ol.pointer.TouchSource.CLICK_COUNT_TIMEOUT); }; @@ -167,8 +168,9 @@ ol.pointer.TouchSource.prototype.resetClickCountHandler_ = function() { * @private */ ol.pointer.TouchSource.prototype.cancelResetClickCount_ = function() { + var global = ol.global; if (this.resetId_ !== undefined) { - ol.global.clearTimeout(this.resetId_); + global.clearTimeout(this.resetId_); } }; @@ -440,7 +442,8 @@ ol.pointer.TouchSource.prototype.dedupSynthMouse_ = function(inEvent) { var lt = [t.clientX, t.clientY]; lts.push(lt); - ol.global.setTimeout(function() { + var global = ol.global; + global.setTimeout(function() { // remove touch after timeout ol.array.remove(lts, lt); }, ol.pointer.TouchSource.DEDUP_TIMEOUT); diff --git a/src/ol/proj/epsg3857.js b/src/ol/proj/epsg3857.js index 1c714aac9d..bd04762ad8 100644 --- a/src/ol/proj/epsg3857.js +++ b/src/ol/proj/epsg3857.js @@ -1,5 +1,6 @@ goog.provide('ol.proj.EPSG3857'); +goog.require('ol'); goog.require('ol.math'); goog.require('ol.proj'); goog.require('ol.proj.Projection'); diff --git a/src/ol/proj/epsg4326.js b/src/ol/proj/epsg4326.js index b30fd11d54..d1fff14687 100644 --- a/src/ol/proj/epsg4326.js +++ b/src/ol/proj/epsg4326.js @@ -1,5 +1,6 @@ goog.provide('ol.proj.EPSG4326'); +goog.require('ol'); goog.require('ol.proj'); goog.require('ol.proj.Projection'); goog.require('ol.proj.Units'); diff --git a/src/ol/render.js b/src/ol/render.js index d8c66a7b2d..12fd27216d 100644 --- a/src/ol/render.js +++ b/src/ol/render.js @@ -1,5 +1,6 @@ goog.provide('ol.render'); +goog.require('ol.has'); goog.require('ol.transform'); goog.require('ol.render.canvas.Immediate'); diff --git a/src/ol/render/box.js b/src/ol/render/box.js index 592e9621d7..6e44032ec2 100644 --- a/src/ol/render/box.js +++ b/src/ol/render/box.js @@ -2,6 +2,7 @@ goog.provide('ol.render.Box'); +goog.require('ol'); goog.require('ol.Disposable'); goog.require('ol.geom.Polygon'); diff --git a/src/ol/render/canvas/immediate.js b/src/ol/render/canvas/immediate.js index 22b7bc4f2c..bd254e271c 100644 --- a/src/ol/render/canvas/immediate.js +++ b/src/ol/render/canvas/immediate.js @@ -4,16 +4,18 @@ goog.provide('ol.render.canvas.Immediate'); -goog.require('ol.transform'); +goog.require('ol'); goog.require('ol.array'); goog.require('ol.color'); goog.require('ol.colorlike'); goog.require('ol.extent'); goog.require('ol.geom.GeometryType'); +goog.require('ol.geom.SimpleGeometry'); goog.require('ol.geom.flat.transform'); goog.require('ol.has'); goog.require('ol.render.VectorContext'); goog.require('ol.render.canvas'); +goog.require('ol.transform'); /** @@ -405,7 +407,7 @@ ol.render.canvas.Immediate.prototype.drawCircle = function(geometry) { if (this.strokeState_) { this.setContextStrokeState_(this.strokeState_); } - var pixelCoordinates = ol.geom.transformSimpleGeometry2D( + var pixelCoordinates = ol.geom.SimpleGeometry.transform2D( geometry, this.transform_, this.pixelCoordinates_); var dx = pixelCoordinates[2] - pixelCoordinates[0]; var dy = pixelCoordinates[3] - pixelCoordinates[1]; diff --git a/src/ol/render/event.js b/src/ol/render/event.js index d454b99f93..64560e32c4 100644 --- a/src/ol/render/event.js +++ b/src/ol/render/event.js @@ -1,6 +1,7 @@ goog.provide('ol.render.Event'); goog.provide('ol.render.EventType'); +goog.require('ol'); goog.require('ol.events.Event'); diff --git a/src/ol/render/feature.js b/src/ol/render/feature.js index 2e09b5885c..0412800169 100644 --- a/src/ol/render/feature.js +++ b/src/ol/render/feature.js @@ -1,6 +1,6 @@ goog.provide('ol.render.Feature'); - +goog.require('ol'); goog.require('ol.extent'); goog.require('ol.geom.GeometryType'); diff --git a/src/ol/render/webgl/imagereplay/index.js b/src/ol/render/webgl/imagereplay/index.js index 4fd0aff35d..c377dd3695 100644 --- a/src/ol/render/webgl/imagereplay/index.js +++ b/src/ol/render/webgl/imagereplay/index.js @@ -1,6 +1,7 @@ goog.provide('ol.render.webgl.ImageReplay'); goog.provide('ol.render.webgl.ReplayGroup'); +goog.require('ol'); goog.require('ol.extent'); goog.require('ol.obj'); goog.require('ol.render.ReplayGroup'); diff --git a/src/ol/render/webgl/immediate.js b/src/ol/render/webgl/immediate.js index 726e52698b..2b6d6b333b 100644 --- a/src/ol/render/webgl/immediate.js +++ b/src/ol/render/webgl/immediate.js @@ -1,5 +1,6 @@ goog.provide('ol.render.webgl.Immediate'); +goog.require('ol'); goog.require('ol.extent'); goog.require('ol.geom.GeometryType'); goog.require('ol.render.ReplayType'); diff --git a/src/ol/renderer/canvas/imagelayer.js b/src/ol/renderer/canvas/imagelayer.js index 2eb18ccb55..89ca3d474c 100644 --- a/src/ol/renderer/canvas/imagelayer.js +++ b/src/ol/renderer/canvas/imagelayer.js @@ -1,13 +1,14 @@ goog.provide('ol.renderer.canvas.ImageLayer'); -goog.require('ol.transform'); -goog.require('ol.functions'); -goog.require('ol.ViewHint'); +goog.require('ol'); +goog.require('ol.View'); goog.require('ol.dom'); goog.require('ol.extent'); +goog.require('ol.functions'); goog.require('ol.proj'); goog.require('ol.renderer.canvas.Layer'); goog.require('ol.source.ImageVector'); +goog.require('ol.transform'); /** @@ -160,7 +161,7 @@ ol.renderer.canvas.ImageLayer.prototype.prepareFrame = function(frameState, laye renderedExtent, layerState.extent); } - if (!hints[ol.ViewHint.ANIMATING] && !hints[ol.ViewHint.INTERACTING] && + if (!hints[ol.View.Hint.ANIMATING] && !hints[ol.View.Hint.INTERACTING] && !ol.extent.isEmpty(renderedExtent)) { var projection = viewState.projection; if (!ol.ENABLE_RASTER_REPROJECTION) { diff --git a/src/ol/renderer/canvas/layer.js b/src/ol/renderer/canvas/layer.js index 3de53c83bb..1bcf37b4cd 100644 --- a/src/ol/renderer/canvas/layer.js +++ b/src/ol/renderer/canvas/layer.js @@ -1,12 +1,13 @@ goog.provide('ol.renderer.canvas.Layer'); -goog.require('ol.transform'); +goog.require('ol'); goog.require('ol.extent'); goog.require('ol.render.Event'); goog.require('ol.render.EventType'); goog.require('ol.render.canvas'); goog.require('ol.render.canvas.Immediate'); goog.require('ol.renderer.Layer'); +goog.require('ol.transform'); /** diff --git a/src/ol/renderer/canvas/tilelayer.js b/src/ol/renderer/canvas/tilelayer.js index 47f781f0f1..8bd2cde1a2 100644 --- a/src/ol/renderer/canvas/tilelayer.js +++ b/src/ol/renderer/canvas/tilelayer.js @@ -4,7 +4,7 @@ goog.provide('ol.renderer.canvas.TileLayer'); goog.require('ol.transform'); goog.require('ol.TileRange'); -goog.require('ol.TileState'); +goog.require('ol.Tile'); goog.require('ol.array'); goog.require('ol.dom'); goog.require('ol.extent'); @@ -131,9 +131,9 @@ ol.renderer.canvas.TileLayer.prototype.prepareFrame = function( */ function(tile) { var tileState = tile.getState(); - return tileState == ol.TileState.LOADED || - tileState == ol.TileState.EMPTY || - tileState == ol.TileState.ERROR && !useInterimTilesOnError; + return tileState == ol.Tile.State.LOADED || + tileState == ol.Tile.State.EMPTY || + tileState == ol.Tile.State.ERROR && !useInterimTilesOnError; }); for (x = tileRange.minX; x <= tileRange.maxX; ++x) { for (y = tileRange.minY; y <= tileRange.maxY; ++y) { @@ -168,7 +168,7 @@ ol.renderer.canvas.TileLayer.prototype.prepareFrame = function( tilesToDraw = tilesToDrawByZ[currentZ]; for (tileCoordKey in tilesToDraw) { tile = tilesToDraw[tileCoordKey]; - if (tile.getState() == ol.TileState.LOADED) { + if (tile.getState() == ol.Tile.State.LOADED) { renderables.push(tile); } } diff --git a/src/ol/renderer/canvas/vectorlayer.js b/src/ol/renderer/canvas/vectorlayer.js index 92287cc9b5..05fd02e433 100644 --- a/src/ol/renderer/canvas/vectorlayer.js +++ b/src/ol/renderer/canvas/vectorlayer.js @@ -1,6 +1,7 @@ goog.provide('ol.renderer.canvas.VectorLayer'); -goog.require('ol.ViewHint'); +goog.require('ol'); +goog.require('ol.View'); goog.require('ol.dom'); goog.require('ol.extent'); goog.require('ol.render.EventType'); @@ -201,8 +202,8 @@ ol.renderer.canvas.VectorLayer.prototype.prepareFrame = function(frameState, lay frameState.attributions, vectorSource.getAttributions()); this.updateLogos(frameState, vectorSource); - var animating = frameState.viewHints[ol.ViewHint.ANIMATING]; - var interacting = frameState.viewHints[ol.ViewHint.INTERACTING]; + var animating = frameState.viewHints[ol.View.Hint.ANIMATING]; + var interacting = frameState.viewHints[ol.View.Hint.INTERACTING]; var updateWhileAnimating = vectorLayer.getUpdateWhileAnimating(); var updateWhileInteracting = vectorLayer.getUpdateWhileInteracting(); diff --git a/src/ol/renderer/canvas/vectortilelayer.js b/src/ol/renderer/canvas/vectortilelayer.js index 9683b105b0..3f41dc906c 100644 --- a/src/ol/renderer/canvas/vectortilelayer.js +++ b/src/ol/renderer/canvas/vectortilelayer.js @@ -1,5 +1,6 @@ goog.provide('ol.renderer.canvas.VectorTileLayer'); +goog.require('ol'); goog.require('ol.array'); goog.require('ol.extent'); goog.require('ol.proj'); diff --git a/src/ol/renderer/dom/imagelayer.js b/src/ol/renderer/dom/imagelayer.js index 6a2315292f..40e6e2913e 100644 --- a/src/ol/renderer/dom/imagelayer.js +++ b/src/ol/renderer/dom/imagelayer.js @@ -1,11 +1,13 @@ goog.provide('ol.renderer.dom.ImageLayer'); -goog.require('ol.transform'); -goog.require('ol.ViewHint'); +goog.require('ol'); +goog.require('ol.View'); +goog.require('ol.array'); goog.require('ol.dom'); goog.require('ol.extent'); goog.require('ol.proj'); goog.require('ol.renderer.dom.Layer'); +goog.require('ol.transform'); /** @@ -88,7 +90,7 @@ ol.renderer.dom.ImageLayer.prototype.prepareFrame = function(frameState, layerSt renderedExtent, layerState.extent); } - if (!hints[ol.ViewHint.ANIMATING] && !hints[ol.ViewHint.INTERACTING] && + if (!hints[ol.View.Hint.ANIMATING] && !hints[ol.View.Hint.INTERACTING] && !ol.extent.isEmpty(renderedExtent)) { var projection = viewState.projection; if (!ol.ENABLE_RASTER_REPROJECTION) { diff --git a/src/ol/renderer/dom/tilelayer.js b/src/ol/renderer/dom/tilelayer.js index 3bd2762f41..6633b91e0d 100644 --- a/src/ol/renderer/dom/tilelayer.js +++ b/src/ol/renderer/dom/tilelayer.js @@ -3,16 +3,16 @@ goog.provide('ol.renderer.dom.TileLayer'); -goog.require('ol.transform'); goog.require('ol'); +goog.require('ol.Tile'); goog.require('ol.TileRange'); -goog.require('ol.TileState'); -goog.require('ol.ViewHint'); +goog.require('ol.View'); goog.require('ol.array'); goog.require('ol.dom'); goog.require('ol.extent'); goog.require('ol.renderer.dom.Layer'); goog.require('ol.size'); +goog.require('ol.transform'); /** @@ -120,18 +120,18 @@ ol.renderer.dom.TileLayer.prototype.prepareFrame = function(frameState, layerSta for (y = tileRange.minY; y <= tileRange.maxY; ++y) { tile = tileSource.getTile(z, x, y, pixelRatio, projection); tileState = tile.getState(); - drawable = tileState == ol.TileState.LOADED || - tileState == ol.TileState.EMPTY || - tileState == ol.TileState.ERROR && !useInterimTilesOnError; + drawable = tileState == ol.Tile.State.LOADED || + tileState == ol.Tile.State.EMPTY || + tileState == ol.Tile.State.ERROR && !useInterimTilesOnError; if (!drawable && tile.interimTile) { tile = tile.interimTile; } tileState = tile.getState(); - if (tileState == ol.TileState.LOADED) { + if (tileState == ol.Tile.State.LOADED) { tilesToDrawByZ[z][tile.tileCoord.toString()] = tile; continue; - } else if (tileState == ol.TileState.EMPTY || - (tileState == ol.TileState.ERROR && + } else if (tileState == ol.Tile.State.EMPTY || + (tileState == ol.Tile.State.ERROR && !useInterimTilesOnError)) { continue; } @@ -225,8 +225,8 @@ ol.renderer.dom.TileLayer.prototype.prepareFrame = function(frameState, layerSta this.target.insertBefore(tileLayerZ.target, this.target.childNodes[0] || null); } } else { - if (!frameState.viewHints[ol.ViewHint.ANIMATING] && - !frameState.viewHints[ol.ViewHint.INTERACTING]) { + if (!frameState.viewHints[ol.View.Hint.ANIMATING] && + !frameState.viewHints[ol.View.Hint.INTERACTING]) { tileLayerZ.removeTilesOutsideExtent(extent, tmpTileRange); } } diff --git a/src/ol/renderer/dom/vectorlayer.js b/src/ol/renderer/dom/vectorlayer.js index 1f0e2e4152..47ddc19eb0 100644 --- a/src/ol/renderer/dom/vectorlayer.js +++ b/src/ol/renderer/dom/vectorlayer.js @@ -1,7 +1,7 @@ goog.provide('ol.renderer.dom.VectorLayer'); -goog.require('ol.transform'); -goog.require('ol.ViewHint'); +goog.require('ol'); +goog.require('ol.View'); goog.require('ol.dom'); goog.require('ol.extent'); goog.require('ol.render.Event'); @@ -10,6 +10,7 @@ goog.require('ol.render.canvas.Immediate'); goog.require('ol.render.canvas.ReplayGroup'); goog.require('ol.renderer.dom.Layer'); goog.require('ol.renderer.vector'); +goog.require('ol.transform'); /** @@ -217,8 +218,8 @@ ol.renderer.dom.VectorLayer.prototype.prepareFrame = function(frameState, layerS frameState.attributions, vectorSource.getAttributions()); this.updateLogos(frameState, vectorSource); - var animating = frameState.viewHints[ol.ViewHint.ANIMATING]; - var interacting = frameState.viewHints[ol.ViewHint.INTERACTING]; + var animating = frameState.viewHints[ol.View.Hint.ANIMATING]; + var interacting = frameState.viewHints[ol.View.Hint.INTERACTING]; var updateWhileAnimating = vectorLayer.getUpdateWhileAnimating(); var updateWhileInteracting = vectorLayer.getUpdateWhileInteracting(); diff --git a/src/ol/renderer/layer.js b/src/ol/renderer/layer.js index 20d5599598..23659bc023 100644 --- a/src/ol/renderer/layer.js +++ b/src/ol/renderer/layer.js @@ -1,14 +1,15 @@ goog.provide('ol.renderer.Layer'); -goog.require('ol.events'); -goog.require('ol.events.EventType'); goog.require('ol'); -goog.require('ol.functions'); goog.require('ol.ImageState'); goog.require('ol.Observable'); -goog.require('ol.TileState'); -goog.require('ol.transform'); +goog.require('ol.Tile'); +goog.require('ol.asserts'); +goog.require('ol.events'); +goog.require('ol.events.EventType'); +goog.require('ol.functions'); goog.require('ol.source.State'); +goog.require('ol.transform'); /** @@ -221,8 +222,8 @@ ol.renderer.Layer.prototype.updateLogos = function(frameState, source) { if (typeof logo === 'string') { frameState.logos[logo] = ''; } else if (logo) { - ol.assert(typeof logo.href == 'string', 44); // `logo.href` should be a string. - ol.assert(typeof logo.src == 'string', 45); // `logo.src` should be a string. + ol.asserts.assert(typeof logo.href == 'string', 44); // `logo.href` should be a string. + ol.asserts.assert(typeof logo.src == 'string', 45); // `logo.src` should be a string. frameState.logos[logo.src] = logo.href; } } @@ -306,7 +307,7 @@ ol.renderer.Layer.prototype.manageTilePyramid = function( for (y = tileRange.minY; y <= tileRange.maxY; ++y) { if (currentZ - z <= preload) { tile = tileSource.getTile(z, x, y, pixelRatio, projection); - if (tile.getState() == ol.TileState.IDLE) { + if (tile.getState() == ol.Tile.State.IDLE) { wantedTiles[tile.getKey()] = true; if (!tileQueue.isKeyQueued(tile.getKey())) { tileQueue.enqueue([tile, tileSourceKey, diff --git a/src/ol/renderer/map.js b/src/ol/renderer/map.js index bd1dea8922..a46d83ce1c 100644 --- a/src/ol/renderer/map.js +++ b/src/ol/renderer/map.js @@ -1,7 +1,6 @@ goog.provide('ol.renderer.Map'); goog.provide('ol.RendererType'); -goog.require('ol.transform'); goog.require('ol'); goog.require('ol.Disposable'); goog.require('ol.events'); @@ -9,7 +8,8 @@ goog.require('ol.events.EventType'); goog.require('ol.extent'); goog.require('ol.functions'); goog.require('ol.layer.Layer'); -goog.require('ol.style.iconImageCache'); +goog.require('ol.style'); +goog.require('ol.transform'); /** @@ -104,7 +104,8 @@ ol.renderer.Map.prototype.disposeInternal = function() { * @private */ ol.renderer.Map.expireIconCache_ = function(map, frameState) { - ol.style.iconImageCache.expire(); + var cache = ol.style.iconImageCache; + cache.expire(); }; diff --git a/src/ol/renderer/vector.js b/src/ol/renderer/vector.js index 8c98748c89..ebbf38cfe5 100644 --- a/src/ol/renderer/vector.js +++ b/src/ol/renderer/vector.js @@ -1,5 +1,6 @@ goog.provide('ol.renderer.vector'); +goog.require('ol'); goog.require('ol.render.ReplayType'); goog.require('ol.style.ImageState'); diff --git a/src/ol/renderer/webgl/imagelayer.js b/src/ol/renderer/webgl/imagelayer.js index 4051db1aed..213a782181 100644 --- a/src/ol/renderer/webgl/imagelayer.js +++ b/src/ol/renderer/webgl/imagelayer.js @@ -1,13 +1,14 @@ goog.provide('ol.renderer.webgl.ImageLayer'); -goog.require('ol.transform'); -goog.require('ol.ViewHint'); +goog.require('ol'); +goog.require('ol.View'); goog.require('ol.dom'); goog.require('ol.extent'); goog.require('ol.functions'); goog.require('ol.proj'); goog.require('ol.renderer.webgl.Layer'); goog.require('ol.source.ImageVector'); +goog.require('ol.transform'); goog.require('ol.webgl'); goog.require('ol.webgl.Context'); @@ -111,7 +112,7 @@ ol.renderer.webgl.ImageLayer.prototype.prepareFrame = function(frameState, layer renderedExtent = ol.extent.getIntersection( renderedExtent, layerState.extent); } - if (!hints[ol.ViewHint.ANIMATING] && !hints[ol.ViewHint.INTERACTING] && + if (!hints[ol.View.Hint.ANIMATING] && !hints[ol.View.Hint.INTERACTING] && !ol.extent.isEmpty(renderedExtent)) { var projection = viewState.projection; if (!ol.ENABLE_RASTER_REPROJECTION) { diff --git a/src/ol/renderer/webgl/layer.js b/src/ol/renderer/webgl/layer.js index b8e3e4b979..5ce02c846d 100644 --- a/src/ol/renderer/webgl/layer.js +++ b/src/ol/renderer/webgl/layer.js @@ -1,11 +1,12 @@ goog.provide('ol.renderer.webgl.Layer'); -goog.require('ol.transform'); +goog.require('ol'); goog.require('ol.render.Event'); goog.require('ol.render.EventType'); goog.require('ol.render.webgl.Immediate'); goog.require('ol.renderer.Layer'); goog.require('ol.renderer.webgl.defaultmapshader'); +goog.require('ol.transform'); goog.require('ol.vec.Mat4'); goog.require('ol.webgl'); goog.require('ol.webgl.Buffer'); diff --git a/src/ol/renderer/webgl/map.js b/src/ol/renderer/webgl/map.js index e9de9908fb..2da89295dc 100644 --- a/src/ol/renderer/webgl/map.js +++ b/src/ol/renderer/webgl/map.js @@ -24,7 +24,7 @@ goog.require('ol.structs.LRUCache'); goog.require('ol.structs.PriorityQueue'); goog.require('ol.webgl'); goog.require('ol.webgl.Context'); -goog.require('ol.webgl.WebGLContextEventType'); +goog.require('ol.webgl.ContextEventType'); /** @@ -91,9 +91,9 @@ ol.renderer.webgl.Map = function(container, map) { */ this.context_ = new ol.webgl.Context(this.canvas_, this.gl_); - ol.events.listen(this.canvas_, ol.webgl.WebGLContextEventType.LOST, + ol.events.listen(this.canvas_, ol.webgl.ContextEventType.LOST, this.handleWebGLContextLost, this); - ol.events.listen(this.canvas_, ol.webgl.WebGLContextEventType.RESTORED, + ol.events.listen(this.canvas_, ol.webgl.ContextEventType.RESTORED, this.handleWebGLContextRestored, this); /** diff --git a/src/ol/renderer/webgl/tilelayer.js b/src/ol/renderer/webgl/tilelayer.js index 838e18e01c..b561291397 100644 --- a/src/ol/renderer/webgl/tilelayer.js +++ b/src/ol/renderer/webgl/tilelayer.js @@ -3,15 +3,16 @@ goog.provide('ol.renderer.webgl.TileLayer'); -goog.require('ol.transform'); +goog.require('ol'); +goog.require('ol.Tile'); goog.require('ol.TileRange'); -goog.require('ol.TileState'); goog.require('ol.array'); goog.require('ol.extent'); goog.require('ol.math'); goog.require('ol.renderer.webgl.Layer'); goog.require('ol.renderer.webgl.tilelayershader'); goog.require('ol.size'); +goog.require('ol.transform'); goog.require('ol.webgl'); goog.require('ol.webgl.Buffer'); @@ -248,20 +249,20 @@ ol.renderer.webgl.TileLayer.prototype.prepareFrame = function(frameState, layerS } } tileState = tile.getState(); - drawable = tileState == ol.TileState.LOADED || - tileState == ol.TileState.EMPTY || - tileState == ol.TileState.ERROR && !useInterimTilesOnError; + drawable = tileState == ol.Tile.State.LOADED || + tileState == ol.Tile.State.EMPTY || + tileState == ol.Tile.State.ERROR && !useInterimTilesOnError; if (!drawable && tile.interimTile) { tile = tile.interimTile; } tileState = tile.getState(); - if (tileState == ol.TileState.LOADED) { + if (tileState == ol.Tile.State.LOADED) { if (mapRenderer.isTileTextureLoaded(tile)) { tilesToDrawByZ[z][tile.tileCoord.toString()] = tile; continue; } - } else if (tileState == ol.TileState.EMPTY || - (tileState == ol.TileState.ERROR && + } else if (tileState == ol.Tile.State.EMPTY || + (tileState == ol.Tile.State.ERROR && !useInterimTilesOnError)) { continue; } @@ -328,7 +329,7 @@ ol.renderer.webgl.TileLayer.prototype.prepareFrame = function(frameState, layerS * @param {ol.Tile} tile Tile. */ function(tile) { - if (tile.getState() == ol.TileState.LOADED && + if (tile.getState() == ol.Tile.State.LOADED && !mapRenderer.isTileTextureLoaded(tile) && !tileTextureQueue.isKeyQueued(tile.getKey())) { tileTextureQueue.enqueue([ diff --git a/src/ol/renderer/webgl/vectorlayer.js b/src/ol/renderer/webgl/vectorlayer.js index f93f7134d2..2d50ea630d 100644 --- a/src/ol/renderer/webgl/vectorlayer.js +++ b/src/ol/renderer/webgl/vectorlayer.js @@ -1,11 +1,12 @@ goog.provide('ol.renderer.webgl.VectorLayer'); -goog.require('ol.ViewHint'); +goog.require('ol'); +goog.require('ol.View'); goog.require('ol.extent'); -goog.require('ol.transform'); goog.require('ol.render.webgl.ReplayGroup'); goog.require('ol.renderer.vector'); goog.require('ol.renderer.webgl.Layer'); +goog.require('ol.transform'); /** @@ -190,8 +191,8 @@ ol.renderer.webgl.VectorLayer.prototype.prepareFrame = function(frameState, laye frameState.attributions, vectorSource.getAttributions()); this.updateLogos(frameState, vectorSource); - var animating = frameState.viewHints[ol.ViewHint.ANIMATING]; - var interacting = frameState.viewHints[ol.ViewHint.INTERACTING]; + var animating = frameState.viewHints[ol.View.Hint.ANIMATING]; + var interacting = frameState.viewHints[ol.View.Hint.INTERACTING]; var updateWhileAnimating = vectorLayer.getUpdateWhileAnimating(); var updateWhileInteracting = vectorLayer.getUpdateWhileInteracting(); diff --git a/src/ol/reproj/image.js b/src/ol/reproj/image.js index 3774e303a4..af3c73f682 100644 --- a/src/ol/reproj/image.js +++ b/src/ol/reproj/image.js @@ -1,9 +1,10 @@ goog.provide('ol.reproj.Image'); -goog.require('ol.events'); -goog.require('ol.events.EventType'); +goog.require('ol'); goog.require('ol.ImageBase'); goog.require('ol.ImageState'); +goog.require('ol.events'); +goog.require('ol.events.EventType'); goog.require('ol.extent'); goog.require('ol.reproj'); goog.require('ol.reproj.Triangulation'); diff --git a/src/ol/reproj/index.js b/src/ol/reproj/index.js index b033ed3ce0..1adae44257 100644 --- a/src/ol/reproj/index.js +++ b/src/ol/reproj/index.js @@ -1,5 +1,6 @@ goog.provide('ol.reproj'); +goog.require('ol'); goog.require('ol.dom'); goog.require('ol.extent'); goog.require('ol.math'); @@ -16,18 +17,18 @@ goog.require('ol.proj'); * @type {boolean} * @private */ -ol.reproj.browserAntialiasesClip_ = (function(winNav, winChrome) { +ol.reproj.browserAntialiasesClip_ = (function(global) { // Adapted from http://stackoverflow.com/questions/4565112/javascript-how-to-find-out-if-the-user-browser-is-chrome - var isOpera = winNav.userAgent.indexOf('OPR') > -1; - var isIEedge = winNav.userAgent.indexOf('Edge') > -1; + var isOpera = global.navigator.userAgent.indexOf('OPR') > -1; + var isIEedge = global.navigator.userAgent.indexOf('Edge') > -1; return !( - !winNav.userAgent.match('CriOS') && // Not Chrome on iOS - winChrome !== null && winChrome !== undefined && // Has chrome in window - winNav.vendor === 'Google Inc.' && // Vendor is Google. + !global.navigator.userAgent.match('CriOS') && // Not Chrome on iOS + global.chrome !== null && global.chrome !== undefined && // Has chrome in window + global.navigator.vendor === 'Google Inc.' && // Vendor is Google. isOpera == false && // Not Opera isIEedge == false // Not Edge ); -})(ol.global.navigator, ol.global.chrome); +})(ol.global); /** diff --git a/src/ol/reproj/tile.js b/src/ol/reproj/tile.js index 9eeae35b25..91f0b28a81 100644 --- a/src/ol/reproj/tile.js +++ b/src/ol/reproj/tile.js @@ -1,7 +1,7 @@ goog.provide('ol.reproj.Tile'); +goog.require('ol'); goog.require('ol.Tile'); -goog.require('ol.TileState'); goog.require('ol.events'); goog.require('ol.events.EventType'); goog.require('ol.extent'); @@ -36,7 +36,7 @@ ol.reproj.Tile = function(sourceProj, sourceTileGrid, pixelRatio, gutter, getTileFunction, opt_errorThreshold, opt_renderEdges) { - ol.Tile.call(this, tileCoord, ol.TileState.IDLE); + ol.Tile.call(this, tileCoord, ol.Tile.State.IDLE); /** * @private @@ -114,7 +114,7 @@ ol.reproj.Tile = function(sourceProj, sourceTileGrid, if (ol.extent.getArea(limitedTargetExtent) === 0) { // Tile is completely outside range -> EMPTY // TODO: is it actually correct that the source even creates the tile ? - this.state = ol.TileState.EMPTY; + this.state = ol.Tile.State.EMPTY; return; } @@ -138,7 +138,7 @@ ol.reproj.Tile = function(sourceProj, sourceTileGrid, if (!isFinite(sourceResolution) || sourceResolution <= 0) { // invalid sourceResolution -> EMPTY // probably edges of the projections when no extent is defined - this.state = ol.TileState.EMPTY; + this.state = ol.Tile.State.EMPTY; return; } @@ -155,7 +155,7 @@ ol.reproj.Tile = function(sourceProj, sourceTileGrid, if (this.triangulation_.getTriangles().length === 0) { // no valid triangles -> EMPTY - this.state = ol.TileState.EMPTY; + this.state = ol.Tile.State.EMPTY; return; } @@ -174,7 +174,7 @@ ol.reproj.Tile = function(sourceProj, sourceTileGrid, } if (!ol.extent.getArea(sourceExtent)) { - this.state = ol.TileState.EMPTY; + this.state = ol.Tile.State.EMPTY; } else { var sourceRange = sourceTileGrid.getTileRangeForExtentAndZ( sourceExtent, this.sourceZ_); @@ -182,7 +182,7 @@ ol.reproj.Tile = function(sourceProj, sourceTileGrid, var tilesRequired = sourceRange.getWidth() * sourceRange.getHeight(); if (goog.DEBUG && !(tilesRequired < ol.RASTER_REPROJECTION_MAX_SOURCE_TILES)) { console.assert(false, 'reasonable number of tiles is required'); - this.state = ol.TileState.ERROR; + this.state = ol.Tile.State.ERROR; return; } for (var srcX = sourceRange.minX; srcX <= sourceRange.maxX; srcX++) { @@ -195,7 +195,7 @@ ol.reproj.Tile = function(sourceProj, sourceTileGrid, } if (this.sourceTiles_.length === 0) { - this.state = ol.TileState.EMPTY; + this.state = ol.Tile.State.EMPTY; } } }; @@ -206,7 +206,7 @@ ol.inherits(ol.reproj.Tile, ol.Tile); * @inheritDoc */ ol.reproj.Tile.prototype.disposeInternal = function() { - if (this.state == ol.TileState.LOADING) { + if (this.state == ol.Tile.State.LOADING) { this.unlistenSources_(); } ol.Tile.prototype.disposeInternal.call(this); @@ -241,7 +241,7 @@ ol.reproj.Tile.prototype.getImage = function(opt_context) { ol.reproj.Tile.prototype.reproject_ = function() { var sources = []; this.sourceTiles_.forEach(function(tile, i, arr) { - if (tile && tile.getState() == ol.TileState.LOADED) { + if (tile && tile.getState() == ol.Tile.State.LOADED) { sources.push({ extent: this.sourceTileGrid_.getTileCoordExtent(tile.tileCoord), image: tile.getImage() @@ -251,7 +251,7 @@ ol.reproj.Tile.prototype.reproject_ = function() { this.sourceTiles_.length = 0; if (sources.length === 0) { - this.state = ol.TileState.ERROR; + this.state = ol.Tile.State.ERROR; } else { var z = this.wrappedTileCoord_[0]; var size = this.targetTileGrid_.getTileSize(z); @@ -267,7 +267,7 @@ ol.reproj.Tile.prototype.reproject_ = function() { targetResolution, targetExtent, this.triangulation_, sources, this.gutter_, this.renderEdges_); - this.state = ol.TileState.LOADED; + this.state = ol.Tile.State.LOADED; } this.changed(); }; @@ -277,8 +277,8 @@ ol.reproj.Tile.prototype.reproject_ = function() { * @inheritDoc */ ol.reproj.Tile.prototype.load = function() { - if (this.state == ol.TileState.IDLE) { - this.state = ol.TileState.LOADING; + if (this.state == ol.Tile.State.IDLE) { + this.state = ol.Tile.State.LOADING; this.changed(); var leftToLoad = 0; @@ -289,16 +289,16 @@ ol.reproj.Tile.prototype.load = function() { this.sourcesListenerKeys_ = []; this.sourceTiles_.forEach(function(tile, i, arr) { var state = tile.getState(); - if (state == ol.TileState.IDLE || state == ol.TileState.LOADING) { + if (state == ol.Tile.State.IDLE || state == ol.Tile.State.LOADING) { leftToLoad++; var sourceListenKey; sourceListenKey = ol.events.listen(tile, ol.events.EventType.CHANGE, function(e) { var state = tile.getState(); - if (state == ol.TileState.LOADED || - state == ol.TileState.ERROR || - state == ol.TileState.EMPTY) { + if (state == ol.Tile.State.LOADED || + state == ol.Tile.State.ERROR || + state == ol.Tile.State.EMPTY) { ol.events.unlistenByKey(sourceListenKey); leftToLoad--; goog.DEBUG && console.assert(leftToLoad >= 0, @@ -315,13 +315,14 @@ ol.reproj.Tile.prototype.load = function() { this.sourceTiles_.forEach(function(tile, i, arr) { var state = tile.getState(); - if (state == ol.TileState.IDLE) { + if (state == ol.Tile.State.IDLE) { tile.load(); } }); if (leftToLoad === 0) { - ol.global.setTimeout(this.reproject_.bind(this), 0); + var global = ol.global; + global.setTimeout(this.reproject_.bind(this), 0); } } }; diff --git a/src/ol/reproj/triangulation.js b/src/ol/reproj/triangulation.js index 8a1aa2c149..059c861a77 100644 --- a/src/ol/reproj/triangulation.js +++ b/src/ol/reproj/triangulation.js @@ -1,5 +1,6 @@ goog.provide('ol.reproj.Triangulation'); +goog.require('ol'); goog.require('ol.extent'); goog.require('ol.math'); goog.require('ol.proj'); diff --git a/src/ol/source/bingmaps.js b/src/ol/source/bingmaps.js index 74b0628024..ef327cc3e7 100644 --- a/src/ol/source/bingmaps.js +++ b/src/ol/source/bingmaps.js @@ -1,5 +1,6 @@ goog.provide('ol.source.BingMaps'); +goog.require('ol'); goog.require('ol.Attribution'); goog.require('ol.TileUrlFunction'); goog.require('ol.extent'); diff --git a/src/ol/source/cartodb.js b/src/ol/source/cartodb.js index 9d3f5f1b81..2006865a97 100644 --- a/src/ol/source/cartodb.js +++ b/src/ol/source/cartodb.js @@ -1,5 +1,6 @@ goog.provide('ol.source.CartoDB'); +goog.require('ol'); goog.require('ol.obj'); goog.require('ol.source.State'); goog.require('ol.source.XYZ'); diff --git a/src/ol/source/cluster.js b/src/ol/source/cluster.js index 074ce99acd..29057ce812 100644 --- a/src/ol/source/cluster.js +++ b/src/ol/source/cluster.js @@ -3,6 +3,8 @@ goog.provide('ol.source.Cluster'); +goog.require('ol'); +goog.require('ol.asserts'); goog.require('ol.Feature'); goog.require('ol.coordinate'); goog.require('ol.events.EventType'); @@ -55,7 +57,7 @@ ol.source.Cluster = function(options) { */ this.geometryFunction_ = options.geometryFunction || function(feature) { var geometry = /** @type {ol.geom.Point} */ (feature.getGeometry()); - ol.assert(geometry instanceof ol.geom.Point, + ol.asserts.assert(geometry instanceof ol.geom.Point, 10); // The default `geometryFunction` can only handle `ol.geom.Point` geometries return geometry; }; diff --git a/src/ol/source/image.js b/src/ol/source/image.js index 3336ef0593..a190f2cd0c 100644 --- a/src/ol/source/image.js +++ b/src/ol/source/image.js @@ -1,9 +1,10 @@ goog.provide('ol.source.Image'); goog.provide('ol.source.ImageEvent'); -goog.require('ol.events.Event'); +goog.require('ol'); goog.require('ol.ImageState'); goog.require('ol.array'); +goog.require('ol.events.Event'); goog.require('ol.extent'); goog.require('ol.proj'); goog.require('ol.reproj.Image'); diff --git a/src/ol/source/imagearcgisrest.js b/src/ol/source/imagearcgisrest.js index cae2c0b250..729392658c 100644 --- a/src/ol/source/imagearcgisrest.js +++ b/src/ol/source/imagearcgisrest.js @@ -2,6 +2,7 @@ goog.provide('ol.source.ImageArcGISRest'); goog.require('ol'); goog.require('ol.Image'); +goog.require('ol.asserts'); goog.require('ol.events'); goog.require('ol.events.EventType'); goog.require('ol.extent'); @@ -211,7 +212,7 @@ ol.source.ImageArcGISRest.prototype.getRequestUrl_ = function(extent, size, pixe .replace(/MapServer\/?$/, 'MapServer/export') .replace(/ImageServer\/?$/, 'ImageServer/exportImage'); if (modifiedUrl == url) { - ol.assert(false, 50); // `options.featureTypes` should be an Array + ol.asserts.assert(false, 50); // `options.featureTypes` should be an Array } return ol.uri.appendParams(modifiedUrl, params); }; diff --git a/src/ol/source/imagecanvas.js b/src/ol/source/imagecanvas.js index 83d66a3fd4..218d667e15 100644 --- a/src/ol/source/imagecanvas.js +++ b/src/ol/source/imagecanvas.js @@ -1,5 +1,6 @@ goog.provide('ol.source.ImageCanvas'); +goog.require('ol'); goog.require('ol.ImageCanvas'); goog.require('ol.extent'); goog.require('ol.source.Image'); diff --git a/src/ol/source/imagemapguide.js b/src/ol/source/imagemapguide.js index b018504e4d..486de8b62a 100644 --- a/src/ol/source/imagemapguide.js +++ b/src/ol/source/imagemapguide.js @@ -1,8 +1,9 @@ goog.provide('ol.source.ImageMapGuide'); +goog.require('ol'); +goog.require('ol.Image'); goog.require('ol.events'); goog.require('ol.events.EventType'); -goog.require('ol.Image'); goog.require('ol.extent'); goog.require('ol.obj'); goog.require('ol.source.Image'); diff --git a/src/ol/source/imagestatic.js b/src/ol/source/imagestatic.js index bfe00b5bff..15eb7df329 100644 --- a/src/ol/source/imagestatic.js +++ b/src/ol/source/imagestatic.js @@ -1,10 +1,11 @@ goog.provide('ol.source.ImageStatic'); -goog.require('ol.events'); -goog.require('ol.events.EventType'); +goog.require('ol'); goog.require('ol.Image'); goog.require('ol.ImageState'); goog.require('ol.dom'); +goog.require('ol.events'); +goog.require('ol.events.EventType'); goog.require('ol.extent'); goog.require('ol.proj'); goog.require('ol.source.Image'); diff --git a/src/ol/source/imagevector.js b/src/ol/source/imagevector.js index ae7f643b06..ae5a5f8937 100644 --- a/src/ol/source/imagevector.js +++ b/src/ol/source/imagevector.js @@ -1,13 +1,15 @@ goog.provide('ol.source.ImageVector'); +goog.require('ol'); +goog.require('ol.dom'); goog.require('ol.events'); goog.require('ol.events.EventType'); -goog.require('ol.transform'); -goog.require('ol.dom'); goog.require('ol.extent'); goog.require('ol.render.canvas.ReplayGroup'); goog.require('ol.renderer.vector'); goog.require('ol.source.ImageCanvas'); +goog.require('ol.style.Style'); +goog.require('ol.transform'); /** @@ -293,8 +295,8 @@ ol.source.ImageVector.prototype.renderFeature_ = function(feature, resolution, p * @api stable */ ol.source.ImageVector.prototype.setStyle = function(style) { - this.style_ = style !== undefined ? style : ol.style.defaultStyleFunction; + this.style_ = style !== undefined ? style : ol.style.Style.defaultFunction; this.styleFunction_ = !style ? - undefined : ol.style.createStyleFunction(this.style_); + undefined : ol.style.Style.createFunction(this.style_); this.changed(); }; diff --git a/src/ol/source/imagewms.js b/src/ol/source/imagewms.js index 5b0f1a3e8c..757f14b8d4 100644 --- a/src/ol/source/imagewms.js +++ b/src/ol/source/imagewms.js @@ -4,6 +4,7 @@ goog.provide('ol.source.ImageWMS'); goog.require('ol'); goog.require('ol.Image'); +goog.require('ol.asserts'); goog.require('ol.events'); goog.require('ol.events.EventType'); goog.require('ol.extent'); @@ -267,7 +268,7 @@ ol.source.ImageWMS.prototype.getImageLoadFunction = function() { */ ol.source.ImageWMS.prototype.getRequestUrl_ = function(extent, size, pixelRatio, projection, params) { - ol.assert(this.url_ !== undefined, 9); // `url` must be configured or set using `#setUrl()` + ol.asserts.assert(this.url_ !== undefined, 9); // `url` must be configured or set using `#setUrl()` params[this.v13_ ? 'CRS' : 'SRS'] = projection.getCode(); @@ -293,7 +294,7 @@ ol.source.ImageWMS.prototype.getRequestUrl_ = function(extent, size, pixelRatio, params['DPI'] = 90 * pixelRatio; break; default: - ol.assert(false, 8); // Unknown `serverType` configured + ol.asserts.assert(false, 8); // Unknown `serverType` configured break; } } diff --git a/src/ol/source/osm.js b/src/ol/source/osm.js index c1693c79d4..a100a7e656 100644 --- a/src/ol/source/osm.js +++ b/src/ol/source/osm.js @@ -1,5 +1,6 @@ goog.provide('ol.source.OSM'); +goog.require('ol'); goog.require('ol.Attribution'); goog.require('ol.source.XYZ'); diff --git a/src/ol/source/raster.js b/src/ol/source/raster.js index b27ad04750..b604684960 100644 --- a/src/ol/source/raster.js +++ b/src/ol/source/raster.js @@ -3,6 +3,7 @@ goog.provide('ol.RasterOperationType'); goog.provide('ol.source.RasterEvent'); goog.provide('ol.source.RasterEventType'); +goog.require('ol'); goog.require('ol.transform'); goog.require('ol.ImageCanvas'); goog.require('ol.TileQueue'); diff --git a/src/ol/source/stamen.js b/src/ol/source/stamen.js index ee5becf812..d17d0a0363 100644 --- a/src/ol/source/stamen.js +++ b/src/ol/source/stamen.js @@ -1,5 +1,6 @@ goog.provide('ol.source.Stamen'); +goog.require('ol'); goog.require('ol.Attribution'); goog.require('ol.source.OSM'); goog.require('ol.source.XYZ'); diff --git a/src/ol/source/tile.js b/src/ol/source/tile.js index ccb6a2909c..85c01333e8 100644 --- a/src/ol/source/tile.js +++ b/src/ol/source/tile.js @@ -2,8 +2,8 @@ goog.provide('ol.source.Tile'); goog.provide('ol.source.TileEvent'); goog.require('ol'); +goog.require('ol.Tile'); goog.require('ol.TileCache'); -goog.require('ol.TileState'); goog.require('ol.events.Event'); goog.require('ol.proj'); goog.require('ol.size'); @@ -118,7 +118,7 @@ ol.source.Tile.prototype.forEachLoadedTile = function(projection, z, tileRange, loaded = false; if (tileCache.containsKey(tileCoordKey)) { tile = /** @type {!ol.Tile} */ (tileCache.get(tileCoordKey)); - loaded = tile.getState() === ol.TileState.LOADED; + loaded = tile.getState() === ol.Tile.State.LOADED; if (loaded) { loaded = (callback(tile) !== false); } diff --git a/src/ol/source/tilearcgisrest.js b/src/ol/source/tilearcgisrest.js index ef8f3f0bdb..4e9e75f365 100644 --- a/src/ol/source/tilearcgisrest.js +++ b/src/ol/source/tilearcgisrest.js @@ -1,9 +1,10 @@ goog.provide('ol.source.TileArcGISRest'); goog.require('ol'); +goog.require('ol.asserts'); goog.require('ol.extent'); -goog.require('ol.obj'); goog.require('ol.math'); +goog.require('ol.obj'); goog.require('ol.size'); goog.require('ol.source.TileImage'); goog.require('ol.tilecoord'); @@ -110,7 +111,7 @@ ol.source.TileArcGISRest.prototype.getRequestUrl_ = function(tileCoord, tileSize .replace(/MapServer\/?$/, 'MapServer/export') .replace(/ImageServer\/?$/, 'ImageServer/exportImage'); if (modifiedUrl == url) { - ol.assert(false, 50); // Cannot determine Rest Service from url + ol.asserts.assert(false, 50); // Cannot determine Rest Service from url } return ol.uri.appendParams(modifiedUrl, params); }; diff --git a/src/ol/source/tiledebug.js b/src/ol/source/tiledebug.js index 83269bbc0f..4d40bb02ff 100644 --- a/src/ol/source/tiledebug.js +++ b/src/ol/source/tiledebug.js @@ -1,7 +1,7 @@ goog.provide('ol.source.TileDebug'); +goog.require('ol'); goog.require('ol.Tile'); -goog.require('ol.TileState'); goog.require('ol.dom'); goog.require('ol.size'); goog.require('ol.source.Tile'); @@ -17,7 +17,7 @@ goog.require('ol.source.Tile'); */ ol.DebugTile_ = function(tileCoord, tileSize, text) { - ol.Tile.call(this, tileCoord, ol.TileState.LOADED); + ol.Tile.call(this, tileCoord, ol.Tile.State.LOADED); /** * @private diff --git a/src/ol/source/tileimage.js b/src/ol/source/tileimage.js index d9f7d72c3d..2872b1ed77 100644 --- a/src/ol/source/tileimage.js +++ b/src/ol/source/tileimage.js @@ -1,8 +1,9 @@ goog.provide('ol.source.TileImage'); +goog.require('ol'); goog.require('ol.ImageTile'); +goog.require('ol.Tile'); goog.require('ol.TileCache'); -goog.require('ol.TileState'); goog.require('ol.events'); goog.require('ol.events.EventType'); goog.require('ol.proj'); @@ -50,7 +51,7 @@ ol.source.TileImage = function(options) { /** * @protected - * @type {function(new: ol.ImageTile, ol.TileCoord, ol.TileState, string, + * @type {function(new: ol.ImageTile, ol.TileCoord, ol.Tile.State, string, * ?string, ol.TileLoadFunctionType)} */ this.tileClass = options.tileClass !== undefined ? @@ -218,7 +219,7 @@ ol.source.TileImage.prototype.createTile_ = function(z, x, y, pixelRatio, projec this.tileUrlFunction(urlTileCoord, pixelRatio, projection) : undefined; var tile = new this.tileClass( tileCoord, - tileUrl !== undefined ? ol.TileState.IDLE : ol.TileState.EMPTY, + tileUrl !== undefined ? ol.Tile.State.IDLE : ol.Tile.State.EMPTY, tileUrl !== undefined ? tileUrl : '', this.crossOrigin, this.tileLoadFunction); @@ -302,18 +303,18 @@ ol.source.TileImage.prototype.getTileInternal = function(z, x, y, pixelRatio, pr // cases we attempt to assign an interim tile to the new tile. var /** @type {ol.Tile} */ interimTile = tile; if (tile.interimTile && tile.interimTile.key == key) { - goog.DEBUG && console.assert(tile.interimTile.getState() == ol.TileState.LOADED); + goog.DEBUG && console.assert(tile.interimTile.getState() == ol.Tile.State.LOADED); goog.DEBUG && console.assert(tile.interimTile.interimTile === null); tile = tile.interimTile; - if (interimTile.getState() == ol.TileState.LOADED) { + if (interimTile.getState() == ol.Tile.State.LOADED) { tile.interimTile = interimTile; } } else { tile = this.createTile_(z, x, y, pixelRatio, projection, key); - if (interimTile.getState() == ol.TileState.LOADED) { + if (interimTile.getState() == ol.Tile.State.LOADED) { tile.interimTile = interimTile; } else if (interimTile.interimTile && - interimTile.interimTile.getState() == ol.TileState.LOADED) { + interimTile.interimTile.getState() == ol.Tile.State.LOADED) { tile.interimTile = interimTile.interimTile; interimTile.interimTile = null; } diff --git a/src/ol/source/tilejson.js b/src/ol/source/tilejson.js index 18f6fbdbca..d3716a2f0c 100644 --- a/src/ol/source/tilejson.js +++ b/src/ol/source/tilejson.js @@ -7,6 +7,7 @@ goog.provide('ol.source.TileJSON'); goog.provide('ol.tilejson'); +goog.require('ol'); goog.require('ol.Attribution'); goog.require('ol.TileUrlFunction'); goog.require('ol.extent'); diff --git a/src/ol/source/tileutfgrid.js b/src/ol/source/tileutfgrid.js index c11c500345..26f90d53af 100644 --- a/src/ol/source/tileutfgrid.js +++ b/src/ol/source/tileutfgrid.js @@ -1,10 +1,11 @@ goog.provide('ol.source.TileUTFGrid'); goog.require('goog.async.nextTick'); +goog.require('ol'); goog.require('ol.Attribution'); goog.require('ol.Tile'); -goog.require('ol.TileState'); goog.require('ol.TileUrlFunction'); +goog.require('ol.asserts'); goog.require('ol.events'); goog.require('ol.events.EventType'); goog.require('ol.extent'); @@ -69,7 +70,7 @@ ol.source.TileUTFGrid = function(options) { } else if (options.tileJSON) { this.handleTileJSONResponse(options.tileJSON); } else { - ol.assert(false, 51); // Either `url` or `tileJSON` options must be provided + ol.asserts.assert(false, 51); // Either `url` or `tileJSON` options must be provided } }; ol.inherits(ol.source.TileUTFGrid, ol.source.Tile); @@ -236,7 +237,7 @@ ol.source.TileUTFGrid.prototype.getTile = function(z, x, y, pixelRatio, projecti var tileUrl = this.tileUrlFunction_(urlTileCoord, pixelRatio, projection); var tile = new ol.source.TileUTFGridTile_( tileCoord, - tileUrl !== undefined ? ol.TileState.IDLE : ol.TileState.EMPTY, + tileUrl !== undefined ? ol.Tile.State.IDLE : ol.Tile.State.EMPTY, tileUrl !== undefined ? tileUrl : '', this.tileGrid.getTileCoordExtent(tileCoord), this.preemptive_, @@ -262,7 +263,7 @@ ol.source.TileUTFGrid.prototype.useTile = function(z, x, y) { * @constructor * @extends {ol.Tile} * @param {ol.TileCoord} tileCoord Tile coordinate. - * @param {ol.TileState} state State. + * @param {ol.Tile.State} state State. * @param {string} src Image source URI. * @param {ol.Extent} extent Extent of the tile. * @param {boolean} preemptive Load the tile when visible (before it's needed). @@ -384,7 +385,7 @@ ol.source.TileUTFGridTile_.prototype.getData = function(coordinate) { * @template T */ ol.source.TileUTFGridTile_.prototype.forDataAtCoordinate = function(coordinate, callback, opt_this, opt_request) { - if (this.state == ol.TileState.IDLE && opt_request === true) { + if (this.state == ol.Tile.State.IDLE && opt_request === true) { ol.events.listenOnce(this, ol.events.EventType.CHANGE, function(e) { callback.call(opt_this, this.getData(coordinate)); }, this); @@ -413,7 +414,7 @@ ol.source.TileUTFGridTile_.prototype.getKey = function() { * @private */ ol.source.TileUTFGridTile_.prototype.handleError_ = function() { - this.state = ol.TileState.ERROR; + this.state = ol.Tile.State.ERROR; this.changed(); }; @@ -427,7 +428,7 @@ ol.source.TileUTFGridTile_.prototype.handleLoad_ = function(json) { this.keys_ = json.keys; this.data_ = json.data; - this.state = ol.TileState.EMPTY; + this.state = ol.Tile.State.EMPTY; this.changed(); }; @@ -436,8 +437,8 @@ ol.source.TileUTFGridTile_.prototype.handleLoad_ = function(json) { * @private */ ol.source.TileUTFGridTile_.prototype.loadInternal_ = function() { - if (this.state == ol.TileState.IDLE) { - this.state = ol.TileState.LOADING; + if (this.state == ol.Tile.State.IDLE) { + this.state = ol.Tile.State.LOADING; if (this.jsonp_) { ol.net.jsonp(this.src_, this.handleLoad_.bind(this), this.handleError_.bind(this)); diff --git a/src/ol/source/tilewms.js b/src/ol/source/tilewms.js index ad8070074d..f3f143f8e5 100644 --- a/src/ol/source/tilewms.js +++ b/src/ol/source/tilewms.js @@ -5,6 +5,7 @@ goog.provide('ol.source.TileWMS'); goog.require('ol'); +goog.require('ol.asserts'); goog.require('ol.extent'); goog.require('ol.obj'); goog.require('ol.math'); @@ -237,7 +238,7 @@ ol.source.TileWMS.prototype.getRequestUrl_ = function(tileCoord, tileSize, tileE params['DPI'] = 90 * pixelRatio; break; default: - ol.assert(false, 52); // Unknown `serverType` configured + ol.asserts.assert(false, 52); // Unknown `serverType` configured break; } } diff --git a/src/ol/source/urltile.js b/src/ol/source/urltile.js index 33b8071e5a..1cbc28bc19 100644 --- a/src/ol/source/urltile.js +++ b/src/ol/source/urltile.js @@ -1,6 +1,7 @@ goog.provide('ol.source.UrlTile'); -goog.require('ol.TileState'); +goog.require('ol'); +goog.require('ol.Tile'); goog.require('ol.TileUrlFunction'); goog.require('ol.source.Tile'); goog.require('ol.source.TileEvent'); @@ -109,15 +110,15 @@ ol.source.UrlTile.prototype.getUrls = function() { ol.source.UrlTile.prototype.handleTileChange = function(event) { var tile = /** @type {ol.Tile} */ (event.target); switch (tile.getState()) { - case ol.TileState.LOADING: + case ol.Tile.State.LOADING: this.dispatchEvent( new ol.source.TileEvent(ol.source.TileEventType.TILELOADSTART, tile)); break; - case ol.TileState.LOADED: + case ol.Tile.State.LOADED: this.dispatchEvent( new ol.source.TileEvent(ol.source.TileEventType.TILELOADEND, tile)); break; - case ol.TileState.ERROR: + case ol.Tile.State.ERROR: this.dispatchEvent( new ol.source.TileEvent(ol.source.TileEventType.TILELOADERROR, tile)); break; diff --git a/src/ol/source/vector.js b/src/ol/source/vector.js index dbefbe8352..a12c7bb089 100644 --- a/src/ol/source/vector.js +++ b/src/ol/source/vector.js @@ -9,11 +9,13 @@ goog.require('ol'); goog.require('ol.Collection'); goog.require('ol.ObjectEventType'); goog.require('ol.array'); +goog.require('ol.asserts'); goog.require('ol.events'); goog.require('ol.events.Event'); goog.require('ol.events.EventType'); goog.require('ol.extent'); goog.require('ol.featureloader'); +goog.require('ol.functions'); goog.require('ol.loadingstrategy'); goog.require('ol.obj'); goog.require('ol.source.Source'); @@ -101,7 +103,7 @@ ol.source.Vector = function(opt_options) { if (options.loader !== undefined) { this.loader_ = options.loader; } else if (this.url_ !== undefined) { - ol.assert(this.format_, 7); // `format` must be set when `url` is set + ol.asserts.assert(this.format_, 7); // `format` must be set when `url` is set // create a XHR feature loader for "url" and "format" this.loader_ = ol.featureloader.xhr(this.url_, /** @type {ol.format.Feature} */ (this.format_)); } @@ -257,7 +259,7 @@ ol.source.Vector.prototype.addToIndex_ = function(featureKey, feature) { valid = false; } } else { - ol.assert(!(featureKey in this.undefIdIndex_), + ol.asserts.assert(!(featureKey in this.undefIdIndex_), 30); // The passed `feature` was already added to the source this.undefIdIndex_[featureKey] = feature; } diff --git a/src/ol/source/vectortile.js b/src/ol/source/vectortile.js index b3fc3b5ee3..49a34b6ca4 100644 --- a/src/ol/source/vectortile.js +++ b/src/ol/source/vectortile.js @@ -1,6 +1,7 @@ goog.provide('ol.source.VectorTile'); -goog.require('ol.TileState'); +goog.require('ol'); +goog.require('ol.Tile'); goog.require('ol.VectorTile'); goog.require('ol.events'); goog.require('ol.events.EventType'); @@ -53,7 +54,7 @@ ol.source.VectorTile = function(options) { /** * @protected - * @type {function(new: ol.VectorTile, ol.TileCoord, ol.TileState, string, + * @type {function(new: ol.VectorTile, ol.TileCoord, ol.Tile.State, string, * ol.format.Feature, ol.TileLoadFunctionType)} */ this.tileClass = options.tileClass ? options.tileClass : ol.VectorTile; @@ -77,7 +78,7 @@ ol.source.VectorTile.prototype.getTile = function(z, x, y, pixelRatio, projectio this.tileUrlFunction(urlTileCoord, pixelRatio, projection) : undefined; var tile = new this.tileClass( tileCoord, - tileUrl !== undefined ? ol.TileState.IDLE : ol.TileState.EMPTY, + tileUrl !== undefined ? ol.Tile.State.IDLE : ol.Tile.State.EMPTY, tileUrl !== undefined ? tileUrl : '', this.format_, this.tileLoadFunction); ol.events.listen(tile, ol.events.EventType.CHANGE, diff --git a/src/ol/source/wmts.js b/src/ol/source/wmts.js index 61c3fa8cd5..a2e5a60e70 100644 --- a/src/ol/source/wmts.js +++ b/src/ol/source/wmts.js @@ -1,6 +1,7 @@ goog.provide('ol.source.WMTS'); goog.provide('ol.source.WMTSRequestEncoding'); +goog.require('ol'); goog.require('ol.TileUrlFunction'); goog.require('ol.array'); goog.require('ol.extent'); diff --git a/src/ol/source/xyz.js b/src/ol/source/xyz.js index a0f31bddda..17db092215 100644 --- a/src/ol/source/xyz.js +++ b/src/ol/source/xyz.js @@ -1,5 +1,6 @@ goog.provide('ol.source.XYZ'); +goog.require('ol'); goog.require('ol.source.TileImage'); goog.require('ol.tilegrid'); diff --git a/src/ol/source/zoomify.js b/src/ol/source/zoomify.js index cba5e88750..173647a9f4 100644 --- a/src/ol/source/zoomify.js +++ b/src/ol/source/zoomify.js @@ -2,7 +2,8 @@ goog.provide('ol.source.Zoomify'); goog.require('ol'); goog.require('ol.ImageTile'); -goog.require('ol.TileState'); +goog.require('ol.Tile'); +goog.require('ol.asserts'); goog.require('ol.dom'); goog.require('ol.extent'); goog.require('ol.source.TileImage'); @@ -64,7 +65,7 @@ ol.source.Zoomify = function(opt_options) { } break; default: - ol.assert(false, 53); // Unknown `tierSizeCalculation` configured + ol.asserts.assert(false, 53); // Unknown `tierSizeCalculation` configured break; } @@ -135,7 +136,7 @@ ol.inherits(ol.source.Zoomify, ol.source.TileImage); * @constructor * @extends {ol.ImageTile} * @param {ol.TileCoord} tileCoord Tile coordinate. - * @param {ol.TileState} state State. + * @param {ol.Tile.State} state State. * @param {string} src Image source URI. * @param {?string} crossOrigin Cross origin. * @param {ol.TileLoadFunctionType} tileLoadFunction Tile load function. @@ -168,7 +169,7 @@ ol.source.ZoomifyTile_.prototype.getImage = function(opt_context) { return this.zoomifyImageByContext_[key]; } else { var image = ol.ImageTile.prototype.getImage.call(this, opt_context); - if (this.state == ol.TileState.LOADED) { + if (this.state == ol.Tile.State.LOADED) { if (image.width == tileSize && image.height == tileSize) { this.zoomifyImageByContext_[key] = image; return image; diff --git a/src/ol/structs/lrucache.js b/src/ol/structs/lrucache.js index b8735f573b..39e9f1a1d8 100644 --- a/src/ol/structs/lrucache.js +++ b/src/ol/structs/lrucache.js @@ -1,5 +1,6 @@ goog.provide('ol.structs.LRUCache'); +goog.require('ol.asserts'); goog.require('ol.obj'); @@ -130,7 +131,7 @@ ol.structs.LRUCache.prototype.forEach = function(f, opt_this) { */ ol.structs.LRUCache.prototype.get = function(key) { var entry = this.entries_[key]; - ol.assert(entry !== undefined, + ol.asserts.assert(entry !== undefined, 15); // Tried to get a value for a key that does not exist in the cache if (entry === this.newest_) { return entry.value_; @@ -244,7 +245,7 @@ ol.structs.LRUCache.prototype.replace = function(key, value) { ol.structs.LRUCache.prototype.set = function(key, value) { goog.DEBUG && console.assert(!(key in {}), 'key is not a standard property of objects (e.g. "__proto__")'); - ol.assert(!(key in this.entries_), + ol.asserts.assert(!(key in this.entries_), 16); // Tried to set a value for a key that is used already var entry = /** @type {ol.LRUCacheEntry} */ ({ key_: key, diff --git a/src/ol/structs/priorityqueue.js b/src/ol/structs/priorityqueue.js index dc2dfb9270..c8bc69e5ea 100644 --- a/src/ol/structs/priorityqueue.js +++ b/src/ol/structs/priorityqueue.js @@ -1,5 +1,6 @@ goog.provide('ol.structs.PriorityQueue'); +goog.require('ol.asserts'); goog.require('ol.obj'); @@ -125,7 +126,7 @@ ol.structs.PriorityQueue.prototype.dequeue = function() { * @return {boolean} The element was added to the queue. */ ol.structs.PriorityQueue.prototype.enqueue = function(element) { - ol.assert(!(this.keyFunction_(element) in this.queuedElements_), + ol.asserts.assert(!(this.keyFunction_(element) in this.queuedElements_), 31); // Tried to enqueue an `element` that was already added to the queue var priority = this.priorityFunction_(element); if (priority != ol.structs.PriorityQueue.DROP) { diff --git a/src/ol/structs/rbush.js b/src/ol/structs/rbush.js index 0d3c56f244..78d4459c84 100644 --- a/src/ol/structs/rbush.js +++ b/src/ol/structs/rbush.js @@ -1,5 +1,6 @@ goog.provide('ol.structs.RBush'); +goog.require('ol'); goog.require('ol.ext.rbush'); goog.require('ol.extent'); goog.require('ol.obj'); diff --git a/src/ol/style/fill.js b/src/ol/style/fill.js index e78403faf3..5b503bc023 100644 --- a/src/ol/style/fill.js +++ b/src/ol/style/fill.js @@ -1,5 +1,6 @@ goog.provide('ol.style.Fill'); +goog.require('ol'); goog.require('ol.color'); diff --git a/src/ol/style/icon.js b/src/ol/style/icon.js index 5ea231e890..184ed424e1 100644 --- a/src/ol/style/icon.js +++ b/src/ol/style/icon.js @@ -1,13 +1,13 @@ goog.provide('ol.style.Icon'); goog.provide('ol.style.IconAnchorUnits'); goog.provide('ol.style.IconOrigin'); -goog.provide('ol.style.iconImageCache'); -goog.require('ol.events'); -goog.require('ol.events.EventTarget'); -goog.require('ol.events.EventType'); +goog.require('ol'); +goog.require('ol.asserts'); goog.require('ol.color'); -goog.require('ol.dom'); +goog.require('ol.events'); +goog.require('ol.events.EventType'); +goog.require('ol.style.IconImage'); goog.require('ol.style.Image'); goog.require('ol.style.ImageState'); @@ -101,15 +101,15 @@ ol.style.Icon = function(opt_options) { */ var src = options.src; - ol.assert(!(src !== undefined && image), + ol.asserts.assert(!(src !== undefined && image), 4); // `image` and `src` cannot be provided at the same time - ol.assert(!image || (image && imgSize), + ol.asserts.assert(!image || (image && imgSize), 5); // `imgSize` must be set when `image` is provided if ((src === undefined || src.length === 0) && image) { src = image.src || ol.getUid(image).toString(); } - ol.assert(src !== undefined && src.length > 0, + ol.asserts.assert(src !== undefined && src.length > 0, 6); // A defined and non-empty `src` or `image` must be provided /** @@ -126,9 +126,9 @@ ol.style.Icon = function(opt_options) { /** * @private - * @type {ol.style.IconImage_} + * @type {ol.style.IconImage} */ - this.iconImage_ = ol.style.IconImage_.get( + this.iconImage_ = ol.style.IconImage.get( image, /** @type {string} */ (src), imgSize, crossOrigin, imageState, color); /** @@ -362,372 +362,3 @@ ol.style.Icon.prototype.unlistenImageChange = function(listener, thisArg) { ol.events.unlisten(this.iconImage_, ol.events.EventType.CHANGE, listener, thisArg); }; - - -/** - * @constructor - * @param {Image|HTMLCanvasElement} image Image. - * @param {string|undefined} src Src. - * @param {ol.Size} size Size. - * @param {?string} crossOrigin Cross origin. - * @param {ol.style.ImageState} imageState Image state. - * @param {ol.Color} color Color. - * @extends {ol.events.EventTarget} - * @private - */ -ol.style.IconImage_ = function(image, src, size, crossOrigin, imageState, - color) { - - ol.events.EventTarget.call(this); - - /** - * @private - * @type {Image|HTMLCanvasElement} - */ - this.hitDetectionImage_ = null; - - /** - * @private - * @type {Image|HTMLCanvasElement} - */ - this.image_ = !image ? new Image() : image; - - if (crossOrigin !== null) { - this.image_.crossOrigin = crossOrigin; - } - - /** - * @private - * @type {HTMLCanvasElement} - */ - this.canvas_ = color ? - /** @type {HTMLCanvasElement} */ (document.createElement('CANVAS')) : - null; - - /** - * @private - * @type {ol.Color} - */ - this.color_ = color; - - /** - * @private - * @type {Array.} - */ - this.imageListenerKeys_ = null; - - /** - * @private - * @type {ol.style.ImageState} - */ - this.imageState_ = imageState; - - /** - * @private - * @type {ol.Size} - */ - this.size_ = size; - - /** - * @private - * @type {string|undefined} - */ - this.src_ = src; - - /** - * @private - * @type {boolean} - */ - this.tainting_ = false; - if (this.imageState_ == ol.style.ImageState.LOADED) { - this.determineTainting_(); - } - -}; -ol.inherits(ol.style.IconImage_, ol.events.EventTarget); - - -/** - * @param {Image|HTMLCanvasElement} image Image. - * @param {string} src Src. - * @param {ol.Size} size Size. - * @param {?string} crossOrigin Cross origin. - * @param {ol.style.ImageState} imageState Image state. - * @param {ol.Color} color Color. - * @return {ol.style.IconImage_} Icon image. - */ -ol.style.IconImage_.get = function(image, src, size, crossOrigin, imageState, - color) { - var iconImageCache = ol.style.iconImageCache; - var iconImage = iconImageCache.get(src, crossOrigin, color); - if (!iconImage) { - iconImage = new ol.style.IconImage_( - image, src, size, crossOrigin, imageState, color); - iconImageCache.set(src, crossOrigin, color, iconImage); - } - return iconImage; -}; - - -/** - * @private - */ -ol.style.IconImage_.prototype.determineTainting_ = function() { - var context = ol.dom.createCanvasContext2D(1, 1); - try { - context.drawImage(this.image_, 0, 0); - context.getImageData(0, 0, 1, 1); - } catch (e) { - this.tainting_ = true; - } -}; - - -/** - * @private - */ -ol.style.IconImage_.prototype.dispatchChangeEvent_ = function() { - this.dispatchEvent(ol.events.EventType.CHANGE); -}; - - -/** - * @private - */ -ol.style.IconImage_.prototype.handleImageError_ = function() { - this.imageState_ = ol.style.ImageState.ERROR; - this.unlistenImage_(); - this.dispatchChangeEvent_(); -}; - - -/** - * @private - */ -ol.style.IconImage_.prototype.handleImageLoad_ = function() { - this.imageState_ = ol.style.ImageState.LOADED; - if (this.size_) { - this.image_.width = this.size_[0]; - this.image_.height = this.size_[1]; - } - this.size_ = [this.image_.width, this.image_.height]; - this.unlistenImage_(); - this.determineTainting_(); - this.replaceColor_(); - this.dispatchChangeEvent_(); -}; - - -/** - * @param {number} pixelRatio Pixel ratio. - * @return {Image|HTMLCanvasElement} Image or Canvas element. - */ -ol.style.IconImage_.prototype.getImage = function(pixelRatio) { - return this.canvas_ ? this.canvas_ : this.image_; -}; - - -/** - * @return {ol.style.ImageState} Image state. - */ -ol.style.IconImage_.prototype.getImageState = function() { - return this.imageState_; -}; - - -/** - * @param {number} pixelRatio Pixel ratio. - * @return {Image|HTMLCanvasElement} Image element. - */ -ol.style.IconImage_.prototype.getHitDetectionImage = function(pixelRatio) { - if (!this.hitDetectionImage_) { - if (this.tainting_) { - var width = this.size_[0]; - var height = this.size_[1]; - var context = ol.dom.createCanvasContext2D(width, height); - context.fillRect(0, 0, width, height); - this.hitDetectionImage_ = context.canvas; - } else { - this.hitDetectionImage_ = this.image_; - } - } - return this.hitDetectionImage_; -}; - - -/** - * @return {ol.Size} Image size. - */ -ol.style.IconImage_.prototype.getSize = function() { - return this.size_; -}; - - -/** - * @return {string|undefined} Image src. - */ -ol.style.IconImage_.prototype.getSrc = function() { - return this.src_; -}; - - -/** - * Load not yet loaded URI. - */ -ol.style.IconImage_.prototype.load = function() { - if (this.imageState_ == ol.style.ImageState.IDLE) { - goog.DEBUG && console.assert(this.src_ !== undefined, - 'this.src_ must not be undefined'); - goog.DEBUG && console.assert(!this.imageListenerKeys_, - 'no listener keys existing'); - this.imageState_ = ol.style.ImageState.LOADING; - this.imageListenerKeys_ = [ - ol.events.listenOnce(this.image_, ol.events.EventType.ERROR, - this.handleImageError_, this), - ol.events.listenOnce(this.image_, ol.events.EventType.LOAD, - this.handleImageLoad_, this) - ]; - try { - this.image_.src = this.src_; - } catch (e) { - this.handleImageError_(); - } - } -}; - - -/** - * @private - */ -ol.style.IconImage_.prototype.replaceColor_ = function() { - if (this.tainting_ || this.color_ === null) { - return; - } - - this.canvas_.width = this.image_.width; - this.canvas_.height = this.image_.height; - - var ctx = this.canvas_.getContext('2d'); - ctx.drawImage(this.image_, 0, 0); - - var imgData = ctx.getImageData(0, 0, this.image_.width, this.image_.height); - var data = imgData.data; - var r = this.color_[0] / 255.0; - var g = this.color_[1] / 255.0; - var b = this.color_[2] / 255.0; - - for (var i = 0, ii = data.length; i < ii; i += 4) { - data[i] *= r; - data[i + 1] *= g; - data[i + 2] *= b; - } - ctx.putImageData(imgData, 0, 0); -}; - - -/** - * Discards event handlers which listen for load completion or errors. - * - * @private - */ -ol.style.IconImage_.prototype.unlistenImage_ = function() { - this.imageListenerKeys_.forEach(ol.events.unlistenByKey); - this.imageListenerKeys_ = null; -}; - - -/** - * @constructor - * @private - */ -ol.style.IconImageCache_ = function() { - - /** - * @type {Object.} - * @private - */ - this.cache_ = {}; - - /** - * @type {number} - * @private - */ - this.cacheSize_ = 0; - - /** - * @const - * @type {number} - * @private - */ - this.maxCacheSize_ = 32; -}; - - -/** - * @param {string} src Src. - * @param {?string} crossOrigin Cross origin. - * @param {ol.Color} color Color. - * @return {string} Cache key. - */ -ol.style.IconImageCache_.getKey = function(src, crossOrigin, color) { - goog.DEBUG && console.assert(crossOrigin !== undefined, - 'argument crossOrigin must be defined'); - var colorString = color ? ol.color.asString(color) : 'null'; - return crossOrigin + ':' + src + ':' + colorString; -}; - - -/** - * FIXME empty description for jsdoc - */ -ol.style.IconImageCache_.prototype.clear = function() { - this.cache_ = {}; - this.cacheSize_ = 0; -}; - - -/** - * FIXME empty description for jsdoc - */ -ol.style.IconImageCache_.prototype.expire = function() { - if (this.cacheSize_ > this.maxCacheSize_) { - var i = 0; - var key, iconImage; - for (key in this.cache_) { - iconImage = this.cache_[key]; - if ((i++ & 3) === 0 && !iconImage.hasListener()) { - delete this.cache_[key]; - --this.cacheSize_; - } - } - } -}; - - -/** - * @param {string} src Src. - * @param {?string} crossOrigin Cross origin. - * @param {ol.Color} color Color. - * @return {ol.style.IconImage_} Icon image. - */ -ol.style.IconImageCache_.prototype.get = function(src, crossOrigin, color) { - var key = ol.style.IconImageCache_.getKey(src, crossOrigin, color); - return key in this.cache_ ? this.cache_[key] : null; -}; - - -/** - * @param {string} src Src. - * @param {?string} crossOrigin Cross origin. - * @param {ol.Color} color Color. - * @param {ol.style.IconImage_} iconImage Icon image. - */ -ol.style.IconImageCache_.prototype.set = function(src, crossOrigin, color, - iconImage) { - var key = ol.style.IconImageCache_.getKey(src, crossOrigin, color); - this.cache_[key] = iconImage; - ++this.cacheSize_; -}; - - -ol.style.iconImageCache = new ol.style.IconImageCache_(); diff --git a/src/ol/style/iconimage.js b/src/ol/style/iconimage.js new file mode 100644 index 0000000000..fc73960301 --- /dev/null +++ b/src/ol/style/iconimage.js @@ -0,0 +1,280 @@ +goog.provide('ol.style.IconImage'); + +goog.require('ol'); +goog.require('ol.dom'); +goog.require('ol.events'); +goog.require('ol.events.EventTarget'); +goog.require('ol.events.EventType'); +goog.require('ol.style'); +goog.require('ol.style.ImageState'); + + +/** + * @constructor + * @param {Image|HTMLCanvasElement} image Image. + * @param {string|undefined} src Src. + * @param {ol.Size} size Size. + * @param {?string} crossOrigin Cross origin. + * @param {ol.style.ImageState} imageState Image state. + * @param {ol.Color} color Color. + * @extends {ol.events.EventTarget} + */ +ol.style.IconImage = function(image, src, size, crossOrigin, imageState, + color) { + + ol.events.EventTarget.call(this); + + /** + * @private + * @type {Image|HTMLCanvasElement} + */ + this.hitDetectionImage_ = null; + + /** + * @private + * @type {Image|HTMLCanvasElement} + */ + this.image_ = !image ? new Image() : image; + + if (crossOrigin !== null) { + this.image_.crossOrigin = crossOrigin; + } + + /** + * @private + * @type {HTMLCanvasElement} + */ + this.canvas_ = color ? + /** @type {HTMLCanvasElement} */ (document.createElement('CANVAS')) : + null; + + /** + * @private + * @type {ol.Color} + */ + this.color_ = color; + + /** + * @private + * @type {Array.} + */ + this.imageListenerKeys_ = null; + + /** + * @private + * @type {ol.style.ImageState} + */ + this.imageState_ = imageState; + + /** + * @private + * @type {ol.Size} + */ + this.size_ = size; + + /** + * @private + * @type {string|undefined} + */ + this.src_ = src; + + /** + * @private + * @type {boolean} + */ + this.tainting_ = false; + if (this.imageState_ == ol.style.ImageState.LOADED) { + this.determineTainting_(); + } + +}; +ol.inherits(ol.style.IconImage, ol.events.EventTarget); + + +/** + * @param {Image|HTMLCanvasElement} image Image. + * @param {string} src Src. + * @param {ol.Size} size Size. + * @param {?string} crossOrigin Cross origin. + * @param {ol.style.ImageState} imageState Image state. + * @param {ol.Color} color Color. + * @return {ol.style.IconImage} Icon image. + */ +ol.style.IconImage.get = function(image, src, size, crossOrigin, imageState, + color) { + var iconImageCache = ol.style.iconImageCache; + var iconImage = iconImageCache.get(src, crossOrigin, color); + if (!iconImage) { + iconImage = new ol.style.IconImage( + image, src, size, crossOrigin, imageState, color); + iconImageCache.set(src, crossOrigin, color, iconImage); + } + return iconImage; +}; + + +/** + * @private + */ +ol.style.IconImage.prototype.determineTainting_ = function() { + var context = ol.dom.createCanvasContext2D(1, 1); + try { + context.drawImage(this.image_, 0, 0); + context.getImageData(0, 0, 1, 1); + } catch (e) { + this.tainting_ = true; + } +}; + + +/** + * @private + */ +ol.style.IconImage.prototype.dispatchChangeEvent_ = function() { + this.dispatchEvent(ol.events.EventType.CHANGE); +}; + + +/** + * @private + */ +ol.style.IconImage.prototype.handleImageError_ = function() { + this.imageState_ = ol.style.ImageState.ERROR; + this.unlistenImage_(); + this.dispatchChangeEvent_(); +}; + + +/** + * @private + */ +ol.style.IconImage.prototype.handleImageLoad_ = function() { + this.imageState_ = ol.style.ImageState.LOADED; + if (this.size_) { + this.image_.width = this.size_[0]; + this.image_.height = this.size_[1]; + } + this.size_ = [this.image_.width, this.image_.height]; + this.unlistenImage_(); + this.determineTainting_(); + this.replaceColor_(); + this.dispatchChangeEvent_(); +}; + + +/** + * @param {number} pixelRatio Pixel ratio. + * @return {Image|HTMLCanvasElement} Image or Canvas element. + */ +ol.style.IconImage.prototype.getImage = function(pixelRatio) { + return this.canvas_ ? this.canvas_ : this.image_; +}; + + +/** + * @return {ol.style.ImageState} Image state. + */ +ol.style.IconImage.prototype.getImageState = function() { + return this.imageState_; +}; + + +/** + * @param {number} pixelRatio Pixel ratio. + * @return {Image|HTMLCanvasElement} Image element. + */ +ol.style.IconImage.prototype.getHitDetectionImage = function(pixelRatio) { + if (!this.hitDetectionImage_) { + if (this.tainting_) { + var width = this.size_[0]; + var height = this.size_[1]; + var context = ol.dom.createCanvasContext2D(width, height); + context.fillRect(0, 0, width, height); + this.hitDetectionImage_ = context.canvas; + } else { + this.hitDetectionImage_ = this.image_; + } + } + return this.hitDetectionImage_; +}; + + +/** + * @return {ol.Size} Image size. + */ +ol.style.IconImage.prototype.getSize = function() { + return this.size_; +}; + + +/** + * @return {string|undefined} Image src. + */ +ol.style.IconImage.prototype.getSrc = function() { + return this.src_; +}; + + +/** + * Load not yet loaded URI. + */ +ol.style.IconImage.prototype.load = function() { + if (this.imageState_ == ol.style.ImageState.IDLE) { + goog.DEBUG && console.assert(this.src_ !== undefined, + 'this.src_ must not be undefined'); + goog.DEBUG && console.assert(!this.imageListenerKeys_, + 'no listener keys existing'); + this.imageState_ = ol.style.ImageState.LOADING; + this.imageListenerKeys_ = [ + ol.events.listenOnce(this.image_, ol.events.EventType.ERROR, + this.handleImageError_, this), + ol.events.listenOnce(this.image_, ol.events.EventType.LOAD, + this.handleImageLoad_, this) + ]; + try { + this.image_.src = this.src_; + } catch (e) { + this.handleImageError_(); + } + } +}; + + +/** + * @private + */ +ol.style.IconImage.prototype.replaceColor_ = function() { + if (this.tainting_ || this.color_ === null) { + return; + } + + this.canvas_.width = this.image_.width; + this.canvas_.height = this.image_.height; + + var ctx = this.canvas_.getContext('2d'); + ctx.drawImage(this.image_, 0, 0); + + var imgData = ctx.getImageData(0, 0, this.image_.width, this.image_.height); + var data = imgData.data; + var r = this.color_[0] / 255.0; + var g = this.color_[1] / 255.0; + var b = this.color_[2] / 255.0; + + for (var i = 0, ii = data.length; i < ii; i += 4) { + data[i] *= r; + data[i + 1] *= g; + data[i + 2] *= b; + } + ctx.putImageData(imgData, 0, 0); +}; + + +/** + * Discards event handlers which listen for load completion or errors. + * + * @private + */ +ol.style.IconImage.prototype.unlistenImage_ = function() { + this.imageListenerKeys_.forEach(ol.events.unlistenByKey); + this.imageListenerKeys_ = null; +}; diff --git a/src/ol/style/iconimagecache.js b/src/ol/style/iconimagecache.js new file mode 100644 index 0000000000..d65ff94a5d --- /dev/null +++ b/src/ol/style/iconimagecache.js @@ -0,0 +1,96 @@ +goog.provide('ol.style.IconImageCache'); + +goog.require('ol.color'); + + +/** + * @constructor + */ +ol.style.IconImageCache = function() { + + /** + * @type {Object.} + * @private + */ + this.cache_ = {}; + + /** + * @type {number} + * @private + */ + this.cacheSize_ = 0; + + /** + * @const + * @type {number} + * @private + */ + this.maxCacheSize_ = 32; +}; + + +/** + * @param {string} src Src. + * @param {?string} crossOrigin Cross origin. + * @param {ol.Color} color Color. + * @return {string} Cache key. + */ +ol.style.IconImageCache.getKey = function(src, crossOrigin, color) { + goog.DEBUG && console.assert(crossOrigin !== undefined, + 'argument crossOrigin must be defined'); + var colorString = color ? ol.color.asString(color) : 'null'; + return crossOrigin + ':' + src + ':' + colorString; +}; + + +/** + * FIXME empty description for jsdoc + */ +ol.style.IconImageCache.prototype.clear = function() { + this.cache_ = {}; + this.cacheSize_ = 0; +}; + + +/** + * FIXME empty description for jsdoc + */ +ol.style.IconImageCache.prototype.expire = function() { + if (this.cacheSize_ > this.maxCacheSize_) { + var i = 0; + var key, iconImage; + for (key in this.cache_) { + iconImage = this.cache_[key]; + if ((i++ & 3) === 0 && !iconImage.hasListener()) { + delete this.cache_[key]; + --this.cacheSize_; + } + } + } +}; + + +/** + * @param {string} src Src. + * @param {?string} crossOrigin Cross origin. + * @param {ol.Color} color Color. + * @return {ol.style.IconImage} Icon image. + */ +ol.style.IconImageCache.prototype.get = function(src, crossOrigin, color) { + var key = ol.style.IconImageCache.getKey(src, crossOrigin, color); + return key in this.cache_ ? this.cache_[key] : null; +}; + + +/** + * @param {string} src Src. + * @param {?string} crossOrigin Cross origin. + * @param {ol.Color} color Color. + * @param {ol.style.IconImage} iconImage Icon image. + */ +ol.style.IconImageCache.prototype.set = function(src, crossOrigin, color, + iconImage) { + var key = ol.style.IconImageCache.getKey(src, crossOrigin, color); + this.cache_[key] = iconImage; + ++this.cacheSize_; +}; diff --git a/src/ol/style/index.js b/src/ol/style/index.js new file mode 100644 index 0000000000..d3efbe46e4 --- /dev/null +++ b/src/ol/style/index.js @@ -0,0 +1,5 @@ +goog.provide('ol.style'); + +goog.require('ol.style.IconImageCache'); + +ol.style.iconImageCache = new ol.style.IconImageCache(); diff --git a/src/ol/style.jsdoc b/src/ol/style/index.jsdoc similarity index 100% rename from src/ol/style.jsdoc rename to src/ol/style/index.jsdoc diff --git a/src/ol/style/style.js b/src/ol/style/style.js index e19e814963..17b9a43d5e 100644 --- a/src/ol/style/style.js +++ b/src/ol/style/style.js @@ -1,5 +1,6 @@ goog.provide('ol.style.Style'); +goog.require('ol.asserts'); goog.require('ol.geom.GeometryType'); goog.require('ol.style.Circle'); goog.require('ol.style.Fill'); @@ -31,7 +32,7 @@ ol.style.Style = function(opt_options) { * @private * @type {!ol.StyleGeometryFunction} */ - this.geometryFunction_ = ol.style.defaultGeometryFunction; + this.geometryFunction_ = ol.style.Style.defaultGeometryFunction; if (options.geometry !== undefined) { this.setGeometry(options.geometry); @@ -159,7 +160,7 @@ ol.style.Style.prototype.setGeometry = function(geometry) { return /** @type {ol.geom.Geometry} */ (feature.get(geometry)); }; } else if (!geometry) { - this.geometryFunction_ = ol.style.defaultGeometryFunction; + this.geometryFunction_ = ol.style.Style.defaultGeometryFunction; } else if (geometry !== undefined) { this.geometryFunction_ = function() { return /** @type {ol.geom.Geometry} */ (geometry); @@ -188,7 +189,7 @@ ol.style.Style.prototype.setZIndex = function(zIndex) { * A style function, a single style, or an array of styles. * @return {ol.StyleFunction} A style function. */ -ol.style.createStyleFunction = function(obj) { +ol.style.Style.createFunction = function(obj) { var styleFunction; if (typeof obj === 'function') { @@ -201,7 +202,7 @@ ol.style.createStyleFunction = function(obj) { if (Array.isArray(obj)) { styles = obj; } else { - ol.assert(obj instanceof ol.style.Style, + ol.asserts.assert(obj instanceof ol.style.Style, 41); // Expected an `ol.style.Style` or an array of `ol.style.Style` styles = [obj]; } @@ -217,7 +218,7 @@ ol.style.createStyleFunction = function(obj) { * @type {Array.} * @private */ -ol.style.defaultStyle_ = null; +ol.style.Style.default_ = null; /** @@ -225,13 +226,13 @@ ol.style.defaultStyle_ = null; * @param {number} resolution Resolution. * @return {Array.} Style. */ -ol.style.defaultStyleFunction = function(feature, resolution) { +ol.style.Style.defaultFunction = function(feature, resolution) { // We don't use an immediately-invoked function // and a closure so we don't get an error at script evaluation time in // browsers that do not support Canvas. (ol.style.Circle does // canvas.getContext('2d') at construction time, which will cause an.error // in such browsers.) - if (!ol.style.defaultStyle_) { + if (!ol.style.Style.default_) { var fill = new ol.style.Fill({ color: 'rgba(255,255,255,0.4)' }); @@ -239,7 +240,7 @@ ol.style.defaultStyleFunction = function(feature, resolution) { color: '#3399CC', width: 1.25 }); - ol.style.defaultStyle_ = [ + ol.style.Style.default_ = [ new ol.style.Style({ image: new ol.style.Circle({ fill: fill, @@ -251,7 +252,7 @@ ol.style.defaultStyleFunction = function(feature, resolution) { }) ]; } - return ol.style.defaultStyle_; + return ol.style.Style.default_; }; @@ -259,7 +260,7 @@ ol.style.defaultStyleFunction = function(feature, resolution) { * Default styles for editing features. * @return {Object.>} Styles */ -ol.style.createDefaultEditingStyles = function() { +ol.style.Style.createDefaultEditing = function() { /** @type {Object.>} */ var styles = {}; var white = [255, 255, 255, 1]; @@ -332,6 +333,6 @@ ol.style.createDefaultEditingStyles = function() { * for. * @return {ol.geom.Geometry|ol.render.Feature|undefined} Geometry to render. */ -ol.style.defaultGeometryFunction = function(feature) { +ol.style.Style.defaultGeometryFunction = function(feature) { return feature.getGeometry(); }; diff --git a/src/ol/tile.js b/src/ol/tile.js index 706e2087ed..6f7bf34084 100644 --- a/src/ol/tile.js +++ b/src/ol/tile.js @@ -1,23 +1,10 @@ goog.provide('ol.Tile'); -goog.provide('ol.TileState'); +goog.require('ol'); goog.require('ol.events.EventTarget'); goog.require('ol.events.EventType'); -/** - * @enum {number} - */ -ol.TileState = { - IDLE: 0, - LOADING: 1, - LOADED: 2, - ERROR: 3, - EMPTY: 4, - ABORT: 5 -}; - - /** * @classdesc * Base class for tiles. @@ -25,7 +12,7 @@ ol.TileState = { * @constructor * @extends {ol.events.EventTarget} * @param {ol.TileCoord} tileCoord Tile coordinate. - * @param {ol.TileState} state State. + * @param {ol.Tile.State} state State. */ ol.Tile = function(tileCoord, state) { @@ -38,7 +25,7 @@ ol.Tile = function(tileCoord, state) { /** * @protected - * @type {ol.TileState} + * @type {ol.Tile.State} */ this.state = state; @@ -98,7 +85,7 @@ ol.Tile.prototype.getTileCoord = function() { /** - * @return {ol.TileState} State. + * @return {ol.Tile.State} State. */ ol.Tile.prototype.getState = function() { return this.state; @@ -113,3 +100,16 @@ ol.Tile.prototype.getState = function() { * @api */ ol.Tile.prototype.load = function() {}; + + +/** + * @enum {number} + */ +ol.Tile.State = { + IDLE: 0, + LOADING: 1, + LOADED: 2, + ERROR: 3, + EMPTY: 4, + ABORT: 5 +}; diff --git a/src/ol/tilecache.js b/src/ol/tilecache.js index 8ca6d4b478..f72c4ed1cf 100644 --- a/src/ol/tilecache.js +++ b/src/ol/tilecache.js @@ -1,5 +1,6 @@ goog.provide('ol.TileCache'); +goog.require('ol'); goog.require('ol.structs.LRUCache'); goog.require('ol.tilecoord'); diff --git a/src/ol/tilegrid/index.js b/src/ol/tilegrid/index.js index ac643dd884..74c21dbfa1 100644 --- a/src/ol/tilegrid/index.js +++ b/src/ol/tilegrid/index.js @@ -1,5 +1,7 @@ goog.provide('ol.tilegrid'); +goog.require('ol'); +goog.require('ol.size'); goog.require('ol.extent'); goog.require('ol.extent.Corner'); goog.require('ol.obj'); diff --git a/src/ol/tilegrid/tilegrid.js b/src/ol/tilegrid/tilegrid.js index 9971bdbdd3..8b7f8309cd 100644 --- a/src/ol/tilegrid/tilegrid.js +++ b/src/ol/tilegrid/tilegrid.js @@ -1,6 +1,7 @@ goog.provide('ol.tilegrid.TileGrid'); goog.require('ol'); +goog.require('ol.asserts'); goog.require('ol.TileRange'); goog.require('ol.array'); goog.require('ol.extent'); @@ -32,7 +33,7 @@ ol.tilegrid.TileGrid = function(options) { * @type {!Array.} */ this.resolutions_ = options.resolutions; - ol.assert(ol.array.isSorted(this.resolutions_, function(a, b) { + ol.asserts.assert(ol.array.isSorted(this.resolutions_, function(a, b) { return b - a; }, true), 17); // `resolutions` must be sorted in descending order @@ -55,7 +56,7 @@ ol.tilegrid.TileGrid = function(options) { this.origins_ = null; if (options.origins !== undefined) { this.origins_ = options.origins; - ol.assert(this.origins_.length == this.resolutions_.length, + ol.asserts.assert(this.origins_.length == this.resolutions_.length, 20); // Number of `origins` and `resolutions` must be equal } @@ -66,7 +67,7 @@ ol.tilegrid.TileGrid = function(options) { this.origin_ = ol.extent.getTopLeft(extent); } - ol.assert( + ol.asserts.assert( (!this.origin_ && this.origins_) || (this.origin_ && !this.origins_), 18); // Either `origin` or `origins` must be configured, never both @@ -77,7 +78,7 @@ ol.tilegrid.TileGrid = function(options) { this.tileSizes_ = null; if (options.tileSizes !== undefined) { this.tileSizes_ = options.tileSizes; - ol.assert(this.tileSizes_.length == this.resolutions_.length, + ol.asserts.assert(this.tileSizes_.length == this.resolutions_.length, 19); // Number of `tileSizes` and `resolutions` must be equal } @@ -88,7 +89,7 @@ ol.tilegrid.TileGrid = function(options) { this.tileSize_ = options.tileSize !== undefined ? options.tileSize : !this.tileSizes_ ? ol.DEFAULT_TILE_SIZE : null; - ol.assert( + ol.asserts.assert( (!this.tileSize_ && this.tileSizes_) || (this.tileSize_ && !this.tileSizes_), 22); // Either `tileSize` or `tileSizes` must be configured, never both @@ -122,7 +123,7 @@ ol.tilegrid.TileGrid = function(options) { Math.min(0, size[0]), Math.max(size[0] - 1, -1), Math.min(0, size[1]), Math.max(size[1] - 1, -1)); if (this.minZoom <= z && z <= this.maxZoom && extent !== undefined) { - ol.assert(tileRange.containsTileRange( + ol.asserts.assert(tileRange.containsTileRange( this.getTileRangeForExtentAndZ(extent, z)), 21); // Tile range for `extent` must not exceed tilegrid width and height } diff --git a/src/ol/tilegrid/wmts.js b/src/ol/tilegrid/wmts.js index 185af866b7..da34871a48 100644 --- a/src/ol/tilegrid/wmts.js +++ b/src/ol/tilegrid/wmts.js @@ -1,5 +1,6 @@ goog.provide('ol.tilegrid.WMTS'); +goog.require('ol'); goog.require('ol.proj'); goog.require('ol.tilegrid.TileGrid'); diff --git a/src/ol/tilequeue.js b/src/ol/tilequeue.js index e273804eab..8da00bb94a 100644 --- a/src/ol/tilequeue.js +++ b/src/ol/tilequeue.js @@ -1,8 +1,9 @@ goog.provide('ol.TileQueue'); +goog.require('ol'); +goog.require('ol.Tile'); goog.require('ol.events'); goog.require('ol.events.EventType'); -goog.require('ol.TileState'); goog.require('ol.structs.PriorityQueue'); @@ -85,8 +86,8 @@ ol.TileQueue.prototype.getTilesLoading = function() { ol.TileQueue.prototype.handleTileChange = function(event) { var tile = /** @type {ol.Tile} */ (event.target); var state = tile.getState(); - if (state === ol.TileState.LOADED || state === ol.TileState.ERROR || - state === ol.TileState.EMPTY || state === ol.TileState.ABORT) { + if (state === ol.Tile.State.LOADED || state === ol.Tile.State.ERROR || + state === ol.Tile.State.EMPTY || state === ol.Tile.State.ABORT) { ol.events.unlisten(tile, ol.events.EventType.CHANGE, this.handleTileChange, this); var tileKey = tile.getKey(); @@ -111,7 +112,7 @@ ol.TileQueue.prototype.loadMoreTiles = function(maxTotalLoading, maxNewLoads) { this.getCount() > 0) { tile = /** @type {ol.Tile} */ (this.dequeue()[0]); tileKey = tile.getKey(); - if (tile.getState() === ol.TileState.IDLE && !(tileKey in this.tilesLoadingKeys_)) { + if (tile.getState() === ol.Tile.State.IDLE && !(tileKey in this.tilesLoadingKeys_)) { this.tilesLoadingKeys_[tileKey] = true; ++this.tilesLoading_; ++newLoads; diff --git a/src/ol/tilerange.js b/src/ol/tilerange.js index 727bc08771..546a74d8ba 100644 --- a/src/ol/tilerange.js +++ b/src/ol/tilerange.js @@ -1,5 +1,7 @@ goog.provide('ol.TileRange'); +goog.require('ol.asserts'); + /** * A representation of a contiguous block of tiles. A tile range is specified @@ -54,7 +56,7 @@ ol.TileRange.boundingTileRange = function(var_args) { tileCoordZ = tileCoord[0]; tileCoordX = tileCoord[1]; tileCoordY = tileCoord[2]; - ol.assert(tileCoordZ == tileCoord0Z, + ol.asserts.assert(tileCoordZ == tileCoord0Z, 23); // The passed `ol.TileCoord`s must all have the same `z` value tileRange.minX = Math.min(tileRange.minX, tileCoordX); tileRange.maxX = Math.max(tileRange.maxX, tileCoordX); diff --git a/src/ol/tileurlfunction.js b/src/ol/tileurlfunction.js index f03c4fef19..af6415227f 100644 --- a/src/ol/tileurlfunction.js +++ b/src/ol/tileurlfunction.js @@ -1,5 +1,6 @@ goog.provide('ol.TileUrlFunction'); +goog.require('ol.asserts'); goog.require('ol.math'); goog.require('ol.tilecoord'); @@ -34,7 +35,7 @@ ol.TileUrlFunction.createFromTemplate = function(template, tileGrid) { .replace(dashYRegEx, function() { var z = tileCoord[0]; var range = tileGrid.getFullTileRange(z); - ol.assert(range, 55); // The {-y} placeholder requires a tile grid with extent + ol.asserts.assert(range, 55); // The {-y} placeholder requires a tile grid with extent var y = range.getHeight() + tileCoord[2]; return y.toString(); }); diff --git a/src/ol/transform.js b/src/ol/transform.js index ec8dd97147..356aae0392 100644 --- a/src/ol/transform.js +++ b/src/ol/transform.js @@ -1,5 +1,8 @@ goog.provide('ol.transform'); +goog.require('ol.asserts'); + + /** * Collection of affine 2d transformation functions. The functions work on an * array of 6 elements. The element order is compatible with the [SVGMatrix @@ -199,7 +202,7 @@ ol.transform.compose = function(transform, dx1, dy1, sx, sy, angle, dx2, dy2) { */ ol.transform.invert = function(transform) { var det = ol.transform.determinant(transform); - ol.assert(det !== 0, 32); // Transformation matrix cannot be inverted + ol.asserts.assert(det !== 0, 32); // Transformation matrix cannot be inverted var a = transform[0]; var b = transform[1]; diff --git a/src/ol/typedefs.js b/src/ol/typedefs.js index 39f825cecb..5482829f31 100644 --- a/src/ol/typedefs.js +++ b/src/ol/typedefs.js @@ -1,3 +1,5 @@ +/* eslint-disable openlayers-internal/no-missing-requires */ + /** * File for all typedefs used by the compiler, and referenced by JSDoc. * diff --git a/src/ol/vectortile.js b/src/ol/vectortile.js index 2e8d9f3b6d..eef32d7778 100644 --- a/src/ol/vectortile.js +++ b/src/ol/vectortile.js @@ -1,7 +1,7 @@ goog.provide('ol.VectorTile'); +goog.require('ol'); goog.require('ol.Tile'); -goog.require('ol.TileState'); goog.require('ol.dom'); @@ -9,7 +9,7 @@ goog.require('ol.dom'); * @constructor * @extends {ol.Tile} * @param {ol.TileCoord} tileCoord Tile coordinate. - * @param {ol.TileState} state State. + * @param {ol.Tile.State} state State. * @param {string} src Data source url. * @param {ol.format.Feature} format Feature format. * @param {ol.TileLoadFunctionType} tileLoadFunction Tile load function. @@ -141,8 +141,8 @@ ol.VectorTile.prototype.getProjection = function() { * Load the tile. */ ol.VectorTile.prototype.load = function() { - if (this.state == ol.TileState.IDLE) { - this.setState(ol.TileState.LOADING); + if (this.state == ol.Tile.State.IDLE) { + this.setState(ol.Tile.State.LOADING); this.tileLoadFunction_(this, this.url_); this.loader_(null, NaN, null); } @@ -155,7 +155,7 @@ ol.VectorTile.prototype.load = function() { */ ol.VectorTile.prototype.setFeatures = function(features) { this.features_ = features; - this.setState(ol.TileState.LOADED); + this.setState(ol.Tile.State.LOADED); }; @@ -170,7 +170,7 @@ ol.VectorTile.prototype.setProjection = function(projection) { /** - * @param {ol.TileState} tileState Tile state. + * @param {ol.Tile.State} tileState Tile state. */ ol.VectorTile.prototype.setState = function(tileState) { this.state = tileState; diff --git a/src/ol/view.js b/src/ol/view.js index afeb8cf404..d8ce577c16 100644 --- a/src/ol/view.js +++ b/src/ol/view.js @@ -1,6 +1,4 @@ goog.provide('ol.View'); -goog.provide('ol.ViewHint'); -goog.provide('ol.ViewProperty'); goog.require('ol'); goog.require('ol.CenterConstraint'); @@ -8,6 +6,8 @@ goog.require('ol.Constraints'); goog.require('ol.Object'); goog.require('ol.ResolutionConstraint'); goog.require('ol.RotationConstraint'); +goog.require('ol.array'); +goog.require('ol.asserts'); goog.require('ol.coordinate'); goog.require('ol.extent'); goog.require('ol.geom.Polygon'); @@ -17,25 +17,6 @@ goog.require('ol.proj.METERS_PER_UNIT'); goog.require('ol.proj.Units'); -/** - * @enum {string} - */ -ol.ViewProperty = { - CENTER: 'center', - RESOLUTION: 'resolution', - ROTATION: 'rotation' -}; - - -/** - * @enum {number} - */ -ol.ViewHint = { - ANIMATING: 0, - INTERACTING: 1 -}; - - /** * @classdesc * An ol.View object represents a simple 2D view of the map. @@ -107,7 +88,7 @@ ol.View = function(opt_options) { * @type {Object.} */ var properties = {}; - properties[ol.ViewProperty.CENTER] = options.center !== undefined ? + properties[ol.View.Property.CENTER] = options.center !== undefined ? options.center : null; /** @@ -162,12 +143,12 @@ ol.View = function(opt_options) { centerConstraint, resolutionConstraint, rotationConstraint); if (options.resolution !== undefined) { - properties[ol.ViewProperty.RESOLUTION] = options.resolution; + properties[ol.View.Property.RESOLUTION] = options.resolution; } else if (options.zoom !== undefined) { - properties[ol.ViewProperty.RESOLUTION] = this.constrainResolution( + properties[ol.View.Property.RESOLUTION] = this.constrainResolution( this.maxResolution_, options.zoom - this.minZoom_); } - properties[ol.ViewProperty.ROTATION] = + properties[ol.View.Property.ROTATION] = options.rotation !== undefined ? options.rotation : 0; this.setProperties(properties); }; @@ -259,7 +240,7 @@ ol.View.prototype.constrainRotation = function(rotation, opt_delta) { */ ol.View.prototype.getCenter = function() { return /** @type {ol.Coordinate|undefined} */ ( - this.get(ol.ViewProperty.CENTER)); + this.get(ol.View.Property.CENTER)); }; @@ -289,11 +270,11 @@ ol.View.prototype.getHints = function(opt_hints) { */ ol.View.prototype.calculateExtent = function(size) { var center = /** @type {!ol.Coordinate} */ (this.getCenter()); - ol.assert(center, 1); // The view center is not defined + ol.asserts.assert(center, 1); // The view center is not defined var resolution = /** @type {!number} */ (this.getResolution()); - ol.assert(resolution !== undefined, 2); // The view resolution is not defined + ol.asserts.assert(resolution !== undefined, 2); // The view resolution is not defined var rotation = /** @type {!number} */ (this.getRotation()); - ol.assert(rotation !== undefined, 3); // The view rotation is not defined + ol.asserts.assert(rotation !== undefined, 3); // The view rotation is not defined return ol.extent.getForViewAndSize(center, resolution, rotation, size); }; @@ -337,7 +318,7 @@ ol.View.prototype.getProjection = function() { */ ol.View.prototype.getResolution = function() { return /** @type {number|undefined} */ ( - this.get(ol.ViewProperty.RESOLUTION)); + this.get(ol.View.Property.RESOLUTION)); }; @@ -400,7 +381,7 @@ ol.View.prototype.getResolutionForValueFunction = function(opt_power) { * @api stable */ ol.View.prototype.getRotation = function() { - return /** @type {number} */ (this.get(ol.ViewProperty.ROTATION)); + return /** @type {number} */ (this.get(ol.View.Property.ROTATION)); }; @@ -492,9 +473,9 @@ ol.View.prototype.getZoom = function() { */ ol.View.prototype.fit = function(geometry, size, opt_options) { if (!(geometry instanceof ol.geom.SimpleGeometry)) { - ol.assert(Array.isArray(geometry), + ol.asserts.assert(Array.isArray(geometry), 24); // Invalid extent or geometry provided as `geometry` - ol.assert(!ol.extent.isEmpty(geometry), + ol.asserts.assert(!ol.extent.isEmpty(geometry), 25); // Cannot fit empty extent provided as `geometry` geometry = ol.geom.Polygon.fromExtent(geometry); } @@ -621,12 +602,12 @@ ol.View.prototype.rotate = function(rotation, opt_anchor) { * @api stable */ ol.View.prototype.setCenter = function(center) { - this.set(ol.ViewProperty.CENTER, center); + this.set(ol.View.Property.CENTER, center); }; /** - * @param {ol.ViewHint} hint Hint. + * @param {ol.View.Hint} hint Hint. * @param {number} delta Delta. * @return {number} New value. */ @@ -647,7 +628,7 @@ ol.View.prototype.setHint = function(hint, delta) { * @api stable */ ol.View.prototype.setResolution = function(resolution) { - this.set(ol.ViewProperty.RESOLUTION, resolution); + this.set(ol.View.Property.RESOLUTION, resolution); }; @@ -658,7 +639,7 @@ ol.View.prototype.setResolution = function(resolution) { * @api stable */ ol.View.prototype.setRotation = function(rotation) { - this.set(ol.ViewProperty.ROTATION, rotation); + this.set(ol.View.Property.ROTATION, rotation); }; @@ -795,3 +776,22 @@ ol.View.createRotationConstraint_ = function(options) { return ol.RotationConstraint.disable; } }; + + +/** + * @enum {string} + */ +ol.View.Property = { + CENTER: 'center', + RESOLUTION: 'resolution', + ROTATION: 'rotation' +}; + + +/** + * @enum {number} + */ +ol.View.Hint = { + ANIMATING: 0, + INTERACTING: 1 +}; diff --git a/src/ol/webgl/buffer.js b/src/ol/webgl/buffer.js index 15650b606b..ce7f5d3803 100644 --- a/src/ol/webgl/buffer.js +++ b/src/ol/webgl/buffer.js @@ -4,16 +4,6 @@ goog.require('ol'); goog.require('ol.webgl'); -/** - * @enum {number} - */ -ol.webgl.BufferUsage = { - STATIC_DRAW: ol.webgl.STATIC_DRAW, - STREAM_DRAW: ol.webgl.STREAM_DRAW, - DYNAMIC_DRAW: ol.webgl.DYNAMIC_DRAW -}; - - /** * @constructor * @param {Array.=} opt_arr Array. @@ -33,7 +23,7 @@ ol.webgl.Buffer = function(opt_arr, opt_usage) { * @type {number} */ this.usage_ = opt_usage !== undefined ? - opt_usage : ol.webgl.BufferUsage.STATIC_DRAW; + opt_usage : ol.webgl.Buffer.Usage.STATIC_DRAW; }; @@ -52,3 +42,13 @@ ol.webgl.Buffer.prototype.getArray = function() { ol.webgl.Buffer.prototype.getUsage = function() { return this.usage_; }; + + +/** + * @enum {number} + */ +ol.webgl.Buffer.Usage = { + STATIC_DRAW: ol.webgl.STATIC_DRAW, + STREAM_DRAW: ol.webgl.STREAM_DRAW, + DYNAMIC_DRAW: ol.webgl.DYNAMIC_DRAW +}; diff --git a/src/ol/webgl/context.js b/src/ol/webgl/context.js index 5870be1635..cb4d481eba 100644 --- a/src/ol/webgl/context.js +++ b/src/ol/webgl/context.js @@ -6,7 +6,7 @@ goog.require('ol.array'); goog.require('ol.events'); goog.require('ol.obj'); goog.require('ol.webgl'); -goog.require('ol.webgl.WebGLContextEventType'); +goog.require('ol.webgl.ContextEventType'); /** @@ -87,9 +87,9 @@ ol.webgl.Context = function(canvas, gl) { 'Failed to get extension "OES_element_index_uint"'); } - ol.events.listen(this.canvas_, ol.webgl.WebGLContextEventType.LOST, + ol.events.listen(this.canvas_, ol.webgl.ContextEventType.LOST, this.handleWebGLContextLost, this); - ol.events.listen(this.canvas_, ol.webgl.WebGLContextEventType.RESTORED, + ol.events.listen(this.canvas_, ol.webgl.ContextEventType.RESTORED, this.handleWebGLContextRestored, this); }; diff --git a/src/ol/webgl/contexteventtype.js b/src/ol/webgl/contexteventtype.js new file mode 100644 index 0000000000..db41dcee97 --- /dev/null +++ b/src/ol/webgl/contexteventtype.js @@ -0,0 +1,10 @@ +goog.provide('ol.webgl.ContextEventType'); + + +/** + * @enum {string} + */ +ol.webgl.ContextEventType = { + LOST: 'webglcontextlost', + RESTORED: 'webglcontextrestored' +}; diff --git a/src/ol/webgl/index.js b/src/ol/webgl/index.js index c3486a5a07..224397a930 100644 --- a/src/ol/webgl/index.js +++ b/src/ol/webgl/index.js @@ -1,5 +1,4 @@ goog.provide('ol.webgl'); -goog.provide('ol.webgl.WebGLContextEventType'); /** Constants taken from goog.webgl @@ -268,15 +267,6 @@ ol.webgl.CONTEXT_IDS_ = [ ]; -/** - * @enum {string} - */ -ol.webgl.WebGLContextEventType = { - LOST: 'webglcontextlost', - RESTORED: 'webglcontextrestored' -}; - - /** * @param {HTMLCanvasElement} canvas Canvas. * @param {Object=} opt_attributes Attributes. diff --git a/test/.eslintrc b/test/.eslintrc new file mode 100644 index 0000000000..8404764dd1 --- /dev/null +++ b/test/.eslintrc @@ -0,0 +1,6 @@ +{ + "rules": { + "openlayers-internal/no-missing-requires": 0, + "openlayers-internal/valid-provide": 0 + } +} diff --git a/test/node/.eslintrc b/test/node/.eslintrc deleted file mode 100644 index efd65c09ef..0000000000 --- a/test/node/.eslintrc +++ /dev/null @@ -1,9 +0,0 @@ -{ - "env": { - "es6": true, - "mocha": true - }, - "rules": { - "strict": [2, "global"] - } -} diff --git a/test/node/one-provide.js b/test/node/one-provide.js deleted file mode 100644 index 83d25309bd..0000000000 --- a/test/node/one-provide.js +++ /dev/null @@ -1,70 +0,0 @@ -'use strict'; - -const assert = require('assert'); -const fs = require('fs'); -const glob = require('glob'); -const path = require('path'); - -const src = path.join(__dirname, '..', '..', 'src'); - -const PROVIDE_RE = /^goog.provide\('(.*)'\);/; - -describe('each file', () => { - - const provides = {}; - - before(done => { - glob('**/*.js', {cwd: src}, function(err, files) { - if (err) { - return done(err); - } - let count = files.length; - let called = false; - files.forEach(file => { - fs.readFile(path.join(src, file), (err, data) => { - if (!called && err) { - called = true; - return done(err); - } - provides[file] = []; - String(data).split('\n').forEach(line => { - const match = line.match(PROVIDE_RE); - if (match) { - provides[file].push(match[1]); - } - }); - --count; - if (count === 0 && !called) { - called = true; - return done(); - } - }); - }); - }); - }); - - it('has a single provide', () => { - for (let file in provides) { - assert.equal(provides[file].length, 1, 'expected a single provide: ' + file); - } - }); - - it('has a path that maps to the provide', () => { - for (let file in provides) { - const provide = provides[file][0]; - if (!provide) { - assert.equal(file, path.join('ol', 'typedefs.js'), 'only ol/typedefs.js can be missing a provide'); - continue; - } - let ext; - if (file.endsWith('index.js')) { - ext = path.sep + 'index.js'; - } else { - ext = '.js'; - } - const mapped = provide.split('.').map(part => part.toLowerCase()).join(path.sep) + ext; - assert.equal(file, mapped, 'expected path to be like the provide: ' + file); - } - }); - -}); diff --git a/test/spec/ol/assertionerror.test.js b/test/spec/ol/assertionerror.test.js new file mode 100644 index 0000000000..b81f69264e --- /dev/null +++ b/test/spec/ol/assertionerror.test.js @@ -0,0 +1,26 @@ +goog.provide('ol.AssertionError.test'); + +goog.require('ol'); +goog.require('ol.AssertionError'); + +describe('ol.AssertionError', function() { + it('generates a message', function() { + var error = new ol.AssertionError(42); + expect(error.message).to.be('Assertion failed. See /doc/errors/#42 for details.'); + }); + it('generates a message with a versioned url', function() { + var origVersion = ol.VERSION; + ol.VERSION = 'foo'; + var error = new ol.AssertionError(42); + expect(error.message).to.be('Assertion failed. See http://openlayers.org/en/foo/doc/errors/#42 for details.'); + ol.VERSION = origVersion; + }); + it('has an error code', function() { + var error = new ol.AssertionError(42); + expect(error.code).to.be(42); + }); + it('has a name', function() { + var error = new ol.AssertionError(42); + expect(error.name).to.be('AssertionError'); + }); +}); diff --git a/test/spec/ol/asserts.test.js b/test/spec/ol/asserts.test.js new file mode 100644 index 0000000000..4e250b3a85 --- /dev/null +++ b/test/spec/ol/asserts.test.js @@ -0,0 +1,16 @@ +goog.provide('ol.asserts.asserts.test'); + +goog.require('ol.asserts'); + + +describe('ol.asserts', function() { + + describe('ol.asserts.assert', function() { + it('throws an exception', function() { + expect(function() { + ol.asserts.assert(false, 42); + }).to.throwException(); + }); + }); + +}); diff --git a/test/spec/ol/format/wfs.test.js b/test/spec/ol/format/wfs.test.js index be299f04e9..908417d849 100644 --- a/test/spec/ol/format/wfs.test.js +++ b/test/spec/ol/format/wfs.test.js @@ -300,13 +300,14 @@ describe('ol.format.WFS', function() { ' ' + ' ' + ''; - var f = ol.format.ogc.filter; var serialized = new ol.format.WFS().writeGetFeature({ srsName: 'urn:ogc:def:crs:EPSG::4326', featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], - filter: f.or(f.equalTo('name', 'New York'), f.equalTo('area', 1234)) + filter: ol.format.ogc.filter.or( + ol.format.ogc.filter.equalTo('name', 'New York'), + ol.format.ogc.filter.equalTo('area', 1234)) }); expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); }); @@ -341,20 +342,19 @@ describe('ol.format.WFS', function() { ' ' + ' ' + ''; - var f = ol.format.ogc.filter; var serialized = new ol.format.WFS().writeGetFeature({ srsName: 'urn:ogc:def:crs:EPSG::4326', featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], - filter: f.or( - f.and( - f.greaterThan('area', 100), - f.greaterThanOrEqualTo('pop', 20000) + filter: ol.format.ogc.filter.or( + ol.format.ogc.filter.and( + ol.format.ogc.filter.greaterThan('area', 100), + ol.format.ogc.filter.greaterThanOrEqualTo('pop', 20000) ), - f.and( - f.lessThan('area', 100), - f.lessThanOrEqualTo('pop', 20000) + ol.format.ogc.filter.and( + ol.format.ogc.filter.lessThan('area', 100), + ol.format.ogc.filter.lessThanOrEqualTo('pop', 20000) ) ) }); @@ -374,13 +374,12 @@ describe('ol.format.WFS', function() { ' ' + ' ' + ''; - var f = ol.format.ogc.filter; var serialized = new ol.format.WFS().writeGetFeature({ srsName: 'urn:ogc:def:crs:EPSG::4326', featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], - filter: f.between('area', 100, 1000) + filter: ol.format.ogc.filter.between('area', 100, 1000) }); expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); }); @@ -396,13 +395,12 @@ describe('ol.format.WFS', function() { ' ' + ' ' + ''; - var f = ol.format.ogc.filter; var serialized = new ol.format.WFS().writeGetFeature({ srsName: 'urn:ogc:def:crs:EPSG::4326', featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], - filter: f.isNull('area') + filter: ol.format.ogc.filter.isNull('area') }); expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); }); @@ -419,13 +417,12 @@ describe('ol.format.WFS', function() { ' ' + ' ' + ''; - var f = ol.format.ogc.filter; var serialized = new ol.format.WFS().writeGetFeature({ srsName: 'urn:ogc:def:crs:EPSG::4326', featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], - filter: f.like('name', 'New*') + filter: ol.format.ogc.filter.like('name', 'New*') }); expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); }); @@ -442,13 +439,12 @@ describe('ol.format.WFS', function() { ' ' + ' ' + ''; - var f = ol.format.ogc.filter; var serialized = new ol.format.WFS().writeGetFeature({ srsName: 'urn:ogc:def:crs:EPSG::4326', featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], - filter: f.like('name', 'New*', '*', '.', '!', false) + filter: ol.format.ogc.filter.like('name', 'New*', '*', '.', '!', false) }); expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); }); @@ -467,13 +463,12 @@ describe('ol.format.WFS', function() { ' ' + ' ' + ''; - var f = ol.format.ogc.filter; var serialized = new ol.format.WFS().writeGetFeature({ srsName: 'urn:ogc:def:crs:EPSG::4326', featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], - filter: f.not(f.equalTo('name', 'New York')) + filter: ol.format.ogc.filter.not(ol.format.ogc.filter.equalTo('name', 'New York')) }); expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); }); @@ -500,15 +495,14 @@ describe('ol.format.WFS', function() { ' ' + ' ' + ''; - var f = ol.format.ogc.filter; var serialized = new ol.format.WFS().writeGetFeature({ srsName: 'urn:ogc:def:crs:EPSG::4326', featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], - filter: f.and( - f.equalTo('name', 'New York'), - f.bbox('the_geom', [1, 2, 3, 4], 'urn:ogc:def:crs:EPSG::4326') + filter: ol.format.ogc.filter.and( + ol.format.ogc.filter.equalTo('name', 'New York'), + ol.format.ogc.filter.bbox('the_geom', [1, 2, 3, 4], 'urn:ogc:def:crs:EPSG::4326') ) }); expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); @@ -534,11 +528,10 @@ describe('ol.format.WFS', function() { ' ' + ' ' + ''; - var f = ol.format.ogc.filter; var serialized = new ol.format.WFS().writeGetFeature({ srsName: 'EPSG:4326', featureTypes: ['area'], - filter: f.intersects( + filter: ol.format.ogc.filter.intersects( 'the_geom', new ol.geom.Polygon([[ [10, 20], @@ -572,11 +565,10 @@ describe('ol.format.WFS', function() { ' ' + ' ' + ''; - var f = ol.format.ogc.filter; var serialized = new ol.format.WFS().writeGetFeature({ srsName: 'EPSG:4326', featureTypes: ['area'], - filter: f.within( + filter: ol.format.ogc.filter.within( 'the_geom', new ol.geom.Polygon([[ [10, 20], diff --git a/test/spec/ol/geom/flat/transform.test.js b/test/spec/ol/geom/flat/transform.test.js index b6397d32d3..aa665c4ef4 100644 --- a/test/spec/ol/geom/flat/transform.test.js +++ b/test/spec/ol/geom/flat/transform.test.js @@ -1,6 +1,7 @@ goog.provide('ol.test.geom.flat.transform'); goog.require('ol.geom.MultiPolygon'); +goog.require('ol.geom.SimpleGeometry'); goog.require('ol.geom.flat.transform'); @@ -32,7 +33,7 @@ describe('ol.geom.flat.transform', function() { 0, -0.0004088332670837288, 4480.991370439071, 1529.5752568707105 ]; - var pixelCoordinates = ol.geom.transformSimpleGeometry2D( + var pixelCoordinates = ol.geom.SimpleGeometry.transform2D( multiPolygonGeometry, transform, []); expect(pixelCoordinates[0]).to.roughlyEqual(806.6035275946265, 1e-9); expect(pixelCoordinates[1]).to.roughlyEqual(160.48916296287916, 1e-9); diff --git a/test/spec/ol/imagetile.test.js b/test/spec/ol/imagetile.test.js index 3ab8c35f64..3986c7c4ff 100644 --- a/test/spec/ol/imagetile.test.js +++ b/test/spec/ol/imagetile.test.js @@ -1,10 +1,10 @@ goog.provide('ol.test.ImageTile'); +goog.require('ol.ImageTile'); +goog.require('ol.Tile'); goog.require('ol.events'); goog.require('ol.events.EventType'); goog.require('ol.source.Image'); -goog.require('ol.ImageTile'); -goog.require('ol.TileState'); describe('ol.ImageTile', function() { @@ -13,7 +13,7 @@ describe('ol.ImageTile', function() { it('can load idle tile', function(done) { var tileCoord = [0, 0, 0]; - var state = ol.TileState.IDLE; + var state = ol.Tile.State.IDLE; var src = 'spec/ol/data/osm-0-0-0.png'; var tileLoadFunction = ol.source.Image.defaultImageLoadFunction; var tile = new ol.ImageTile(tileCoord, state, src, null, tileLoadFunction); @@ -22,10 +22,10 @@ describe('ol.ImageTile', function() { ol.events.listen(tile, ol.events.EventType.CHANGE, function(event) { var state = tile.getState(); - if (previousState == ol.TileState.IDLE) { - expect(state).to.be(ol.TileState.LOADING); - } else if (previousState == ol.TileState.LOADING) { - expect(state).to.be(ol.TileState.LOADED); + if (previousState == ol.Tile.State.IDLE) { + expect(state).to.be(ol.Tile.State.LOADING); + } else if (previousState == ol.Tile.State.LOADING) { + expect(state).to.be(ol.Tile.State.LOADED); done(); } else { expect().fail(); @@ -38,7 +38,7 @@ describe('ol.ImageTile', function() { it('can load error tile', function(done) { var tileCoord = [0, 0, 0]; - var state = ol.TileState.ERROR; + var state = ol.Tile.State.ERROR; var src = 'spec/ol/data/osm-0-0-0.png'; var tileLoadFunction = ol.source.Image.defaultImageLoadFunction; var tile = new ol.ImageTile(tileCoord, state, src, null, tileLoadFunction); @@ -47,10 +47,10 @@ describe('ol.ImageTile', function() { ol.events.listen(tile, ol.events.EventType.CHANGE, function(event) { var state = tile.getState(); - if (previousState == ol.TileState.ERROR) { - expect(state).to.be(ol.TileState.LOADING); - } else if (previousState == ol.TileState.LOADING) { - expect(state).to.be(ol.TileState.LOADED); + if (previousState == ol.Tile.State.ERROR) { + expect(state).to.be(ol.Tile.State.LOADING); + } else if (previousState == ol.Tile.State.LOADING) { + expect(state).to.be(ol.Tile.State.LOADED); done(); } else { expect().fail(); diff --git a/test/spec/ol/interaction/draganddrop.test.js b/test/spec/ol/interaction/draganddrop.test.js index 330e2b9202..4178d26c95 100644 --- a/test/spec/ol/interaction/draganddrop.test.js +++ b/test/spec/ol/interaction/draganddrop.test.js @@ -1,14 +1,16 @@ goog.provide('ol.test.interaction.DragAndDrop'); -goog.require('ol.interaction.DragAndDrop'); +goog.require('ol'); goog.require('ol.View'); goog.require('ol.events.Event'); goog.require('ol.events.EventTarget'); goog.require('ol.format.GeoJSON'); +goog.require('ol.interaction.DragAndDrop'); describe('ol.interaction.DragAndDrop', function() { var viewport, map, interaction; + var global = ol.global; beforeEach(function() { viewport = new ol.events.EventTarget(); @@ -69,7 +71,7 @@ describe('ol.interaction.DragAndDrop', function() { }); describe('#handleDrop_', function() { - var origFileReader = ol.global.FileReader; + var origFileReader = global.FileReader; beforeEach(function() { FileReader = function() { @@ -83,7 +85,7 @@ describe('ol.interaction.DragAndDrop', function() { }); afterEach(function() { - ol.global.FileReader = origFileReader; + global.FileReader = origFileReader; }); it('reads dropped files', function(done) { diff --git a/test/spec/ol/interaction/mousewheelzoom.test.js b/test/spec/ol/interaction/mousewheelzoom.test.js index eeb8ee94b9..643289e171 100644 --- a/test/spec/ol/interaction/mousewheelzoom.test.js +++ b/test/spec/ol/interaction/mousewheelzoom.test.js @@ -5,7 +5,10 @@ goog.require('ol.Map'); goog.require('ol.MapBrowserEvent'); goog.require('ol.View'); goog.require('ol.events.Event'); +goog.require('ol.has'); goog.require('ol.interaction.Interaction'); + + describe('ol.interaction.MouseWheelZoom', function() { var map; diff --git a/test/spec/ol/interaction/select.test.js b/test/spec/ol/interaction/select.test.js index f5ee9f040d..272c5004d3 100644 --- a/test/spec/ol/interaction/select.test.js +++ b/test/spec/ol/interaction/select.test.js @@ -3,11 +3,12 @@ goog.provide('ol.test.interaction.Select'); goog.require('ol.Collection'); goog.require('ol.Feature'); goog.require('ol.Map'); +goog.require('ol.MapBrowserEvent'); goog.require('ol.MapBrowserPointerEvent'); goog.require('ol.View'); goog.require('ol.geom.Polygon'); -goog.require('ol.interaction.Select'); goog.require('ol.interaction.Interaction'); +goog.require('ol.interaction.Select'); goog.require('ol.layer.Vector'); goog.require('ol.pointer.PointerEvent'); goog.require('ol.source.Vector'); diff --git a/test/spec/ol/layer/group.test.js b/test/spec/ol/layer/group.test.js index 04ba125fb3..82dafb46df 100644 --- a/test/spec/ol/layer/group.test.js +++ b/test/spec/ol/layer/group.test.js @@ -1,5 +1,6 @@ goog.provide('ol.test.layer.Group'); +goog.require('ol'); goog.require('ol.array'); goog.require('ol.Collection'); goog.require('ol.extent'); diff --git a/test/spec/ol/layer/layer.test.js b/test/spec/ol/layer/layer.test.js index df9d419985..f2a2ebce38 100644 --- a/test/spec/ol/layer/layer.test.js +++ b/test/spec/ol/layer/layer.test.js @@ -1,5 +1,6 @@ goog.provide('ol.test.layer.Layer'); +goog.require('ol'); goog.require('ol.Map'); goog.require('ol.layer.Layer'); goog.require('ol.proj'); diff --git a/test/spec/ol/layer/vector.test.js b/test/spec/ol/layer/vector.test.js index 0474e7c0da..a4063f872e 100644 --- a/test/spec/ol/layer/vector.test.js +++ b/test/spec/ol/layer/vector.test.js @@ -76,10 +76,10 @@ describe('ol.layer.Vector', function() { }); it('updates the internal style function', function() { - expect(layer.getStyleFunction()).to.be(ol.style.defaultStyleFunction); + expect(layer.getStyleFunction()).to.be(ol.style.Style.defaultFunction); layer.setStyle(style); expect(layer.getStyleFunction()).not.to.be( - ol.style.defaultStyleFunction); + ol.style.Style.defaultFunction); }); it('allows setting an null style', function() { @@ -91,8 +91,8 @@ describe('ol.layer.Vector', function() { it('sets the default style when passing undefined', function() { layer.setStyle(style); layer.setStyle(undefined); - expect(layer.getStyle()).to.be(ol.style.defaultStyleFunction); - expect(layer.getStyleFunction()).to.be(ol.style.defaultStyleFunction); + expect(layer.getStyle()).to.be(ol.style.Style.defaultFunction); + expect(layer.getStyleFunction()).to.be(ol.style.Style.defaultFunction); }); }); @@ -107,7 +107,7 @@ describe('ol.layer.Vector', function() { source: source }); - expect(layer.getStyle()).to.be(ol.style.defaultStyleFunction); + expect(layer.getStyle()).to.be(ol.style.Style.defaultFunction); layer.setStyle(style); expect(layer.getStyle()).to.be(style); diff --git a/test/spec/ol/map.test.js b/test/spec/ol/map.test.js index a8647996d9..f92a44b6e2 100644 --- a/test/spec/ol/map.test.js +++ b/test/spec/ol/map.test.js @@ -4,9 +4,10 @@ goog.require('ol.Map'); goog.require('ol.MapEvent'); goog.require('ol.Overlay'); goog.require('ol.View'); +goog.require('ol.has'); goog.require('ol.interaction'); -goog.require('ol.interaction.Interaction'); goog.require('ol.interaction.DoubleClickZoom'); +goog.require('ol.interaction.Interaction'); goog.require('ol.interaction.MouseWheelZoom'); goog.require('ol.layer.Tile'); goog.require('ol.source.XYZ'); diff --git a/test/spec/ol/net.test.js b/test/spec/ol/net.test.js index ede3630aa5..f4b171ffe6 100644 --- a/test/spec/ol/net.test.js +++ b/test/spec/ol/net.test.js @@ -1,15 +1,17 @@ goog.provide('ol.test.net'); +goog.require('ol'); goog.require('ol.net'); - describe('ol.net', function() { + var global = ol.global; + describe('jsonp()', function() { - var head = ol.global.document.getElementsByTagName('head')[0]; + var head = global.document.getElementsByTagName('head')[0]; var origAppendChild = head.appendChild; var origCreateElement = document.createElement; - var origSetTimeout = ol.global.setTimeout; + var origSetTimeout = global.setTimeout; var key, removeChild; function createCallback(url, done) { @@ -29,7 +31,7 @@ describe('ol.net', function() { if (arg == 'script') { return element; } else { - return origCreateElement.apply(ol.global.document, arguments); + return origCreateElement.apply(global.document, arguments); } }; head.appendChild = function(el) { @@ -38,13 +40,13 @@ describe('ol.net', function() { removeChild: removeChild }; origSetTimeout(function() { - ol.global[key](element.src); + global[key](element.src); }, 0); } else { origAppendChild.apply(head, arguments); } }; - ol.global.setTimeout = function(fn, time) { + global.setTimeout = function(fn, time) { origSetTimeout(fn, 100); }; }); @@ -52,7 +54,7 @@ describe('ol.net', function() { afterEach(function() { document.createElement = origCreateElement; head.appendChild = origAppendChild; - ol.global.setTimeout = origSetTimeout; + global.setTimeout = origSetTimeout; }); it('appends callback param to url, cleans up after call', function(done) { @@ -72,7 +74,7 @@ describe('ol.net', function() { expect.fail(); } function errback() { - expect(ol.global[key]).to.be(undefined); + expect(global[key]).to.be(undefined); expect(removeChild.called).to.be(true); done(); } diff --git a/test/spec/ol/ol.test.js b/test/spec/ol/ol.test.js deleted file mode 100644 index 8ad3ba3dc6..0000000000 --- a/test/spec/ol/ol.test.js +++ /dev/null @@ -1,38 +0,0 @@ -goog.provide('ol.test'); - -goog.require('ol'); - - -describe('ol', function() { - - describe('ol.assert', function() { - it('throws an exception', function() { - expect(function() { - ol.assert(false, 42); - }).to.throwException(); - }); - }); - - describe('ol.AssertionError', function() { - it('generates a message', function() { - var error = new ol.AssertionError(42); - expect(error.message).to.be('Assertion failed. See /doc/errors/#42 for details.'); - }); - it('generates a message with a versioned url', function() { - var origVersion = ol.VERSION; - ol.VERSION = 'foo'; - var error = new ol.AssertionError(42); - expect(error.message).to.be('Assertion failed. See http://openlayers.org/en/foo/doc/errors/#42 for details.'); - ol.VERSION = origVersion; - }); - it('has an error code', function() { - var error = new ol.AssertionError(42); - expect(error.code).to.be(42); - }); - it('has a name', function() { - var error = new ol.AssertionError(42); - expect(error.name).to.be('AssertionError'); - }); - }); - -}); diff --git a/test/spec/ol/render.test.js b/test/spec/ol/render.test.js index eb25af919b..7d0855ae8f 100644 --- a/test/spec/ol/render.test.js +++ b/test/spec/ol/render.test.js @@ -1,8 +1,12 @@ goog.provide('ol.test.render'); -goog.require('ol.transform'); +goog.require('ol.array'); +goog.require('ol.has'); goog.require('ol.render'); goog.require('ol.render.canvas.Immediate'); +goog.require('ol.transform'); + + describe('ol.render', function() { describe('toContext', function() { diff --git a/test/spec/ol/renderer/canvas/map.test.js b/test/spec/ol/renderer/canvas/map.test.js index b90f56b5d4..42311d8e79 100644 --- a/test/spec/ol/renderer/canvas/map.test.js +++ b/test/spec/ol/renderer/canvas/map.test.js @@ -1,5 +1,6 @@ goog.provide('ol.test.renderer.canvas.Map'); +goog.require('ol'); goog.require('ol.Feature'); goog.require('ol.Map'); goog.require('ol.View'); diff --git a/test/spec/ol/renderer/canvas/vectorlayer.test.js b/test/spec/ol/renderer/canvas/vectorlayer.test.js index 34bf4f199c..a6bab3856d 100644 --- a/test/spec/ol/renderer/canvas/vectorlayer.test.js +++ b/test/spec/ol/renderer/canvas/vectorlayer.test.js @@ -1,5 +1,6 @@ goog.provide('ol.test.renderer.canvas.VectorLayer'); +goog.require('ol'); goog.require('ol.Feature'); goog.require('ol.Map'); goog.require('ol.View'); diff --git a/test/spec/ol/renderer/canvas/vectortilelayer.test.js b/test/spec/ol/renderer/canvas/vectortilelayer.test.js index 7c3de22187..4f54f8c8e3 100644 --- a/test/spec/ol/renderer/canvas/vectortilelayer.test.js +++ b/test/spec/ol/renderer/canvas/vectortilelayer.test.js @@ -1,5 +1,6 @@ goog.provide('ol.test.renderer.canvas.VectorTileLayer'); +goog.require('ol'); goog.require('ol.Feature'); goog.require('ol.Map'); goog.require('ol.VectorTile'); diff --git a/test/spec/ol/renderer/vector.test.js b/test/spec/ol/renderer/vector.test.js index 60f1244f66..71137d77b7 100644 --- a/test/spec/ol/renderer/vector.test.js +++ b/test/spec/ol/renderer/vector.test.js @@ -1,5 +1,6 @@ goog.provide('ol.test.renderer.vector'); +goog.require('ol'); goog.require('ol.events'); goog.require('ol.geom.LineString'); goog.require('ol.geom.Point'); diff --git a/test/spec/ol/source/tile.test.js b/test/spec/ol/source/tile.test.js index 1665302710..845b5a7268 100644 --- a/test/spec/ol/source/tile.test.js +++ b/test/spec/ol/source/tile.test.js @@ -1,5 +1,6 @@ goog.provide('ol.test.source.TileSource'); +goog.require('ol'); goog.require('ol.Tile'); goog.require('ol.TileRange'); goog.require('ol.proj'); @@ -247,7 +248,7 @@ describe('ol.source.Tile', function() { * * @constructor * @extends {ol.source.Tile} - * @param {Object.} tileStates Lookup of tile key to + * @param {Object.} tileStates Lookup of tile key to * tile state. */ ol.test.source.TileMock = function(tileStates) { diff --git a/test/spec/ol/style.test.js b/test/spec/ol/style.test.js index 094c1ac8ad..90986b8eab 100644 --- a/test/spec/ol/style.test.js +++ b/test/spec/ol/style.test.js @@ -67,16 +67,16 @@ describe('ol.style.Style', function() { }); -describe('ol.style.createStyleFunction()', function() { +describe('ol.style.Style.createFunction()', function() { var style = new ol.style.Style(); it('creates a style function from a single style', function() { - var styleFunction = ol.style.createStyleFunction(style); + var styleFunction = ol.style.Style.createFunction(style); expect(styleFunction()).to.eql([style]); }); it('creates a style function from an array of styles', function() { - var styleFunction = ol.style.createStyleFunction([style]); + var styleFunction = ol.style.Style.createFunction([style]); expect(styleFunction()).to.eql([style]); }); @@ -84,13 +84,13 @@ describe('ol.style.createStyleFunction()', function() { var original = function() { return [style]; }; - var styleFunction = ol.style.createStyleFunction(original); + var styleFunction = ol.style.Style.createFunction(original); expect(styleFunction).to.be(original); }); it('throws on (some) unexpected input', function() { expect(function() { - ol.style.createStyleFunction({bogus: 'input'}); + ol.style.Style.createFunction({bogus: 'input'}); }).to.throwException(); }); diff --git a/test/spec/ol/style/icon.test.js b/test/spec/ol/style/icon.test.js index d3e6c07c8a..5d3fa68cba 100644 --- a/test/spec/ol/style/icon.test.js +++ b/test/spec/ol/style/icon.test.js @@ -1,9 +1,9 @@ goog.provide('ol.test.style.Icon'); -goog.provide('ol.test.style.IconImageCache'); -goog.require('ol.events'); -goog.require('ol.style.iconImageCache'); +goog.require('ol'); +goog.require('ol.style'); goog.require('ol.style.Icon'); +goog.require('ol.style.IconImage'); describe('ol.style.Icon', function() { @@ -19,7 +19,7 @@ describe('ol.style.Icon', function() { img: canvas, imgSize: size }); - expect(ol.style.IconImage_.get( + expect(ol.style.IconImage.get( canvas, ol.getUid(canvas), size, '').getImage()).to.eql(canvas); }); @@ -147,7 +147,7 @@ describe('ol.style.Icon', function() { // this image will be used for the icon. var cache = ol.style.iconImageCache; var src = 'test.png'; - var iconImage = new ol.style.IconImage_(null, 'test.png', imgSize); + var iconImage = new ol.style.IconImage(null, 'test.png', imgSize); cache.set(src, null, null, iconImage); var iconStyle = new ol.style.Icon({ @@ -165,66 +165,3 @@ describe('ol.style.Icon', function() { }); }); }); - -describe('ol.style.IconImageCache', function() { - var originalMaxCacheSize; - - beforeEach(function() { - var cache = ol.style.iconImageCache; - cache.clear(); - originalMaxCacheSize = cache.maxCacheSize; - cache.maxCacheSize_ = 4; - }); - - afterEach(function() { - var cache = ol.style.iconImageCache; - cache.maxCacheSize_ = originalMaxCacheSize; - cache.clear(); - }); - - describe('#expire', function() { - it('expires images when expected', function() { - var cache = ol.style.iconImageCache; - - var i, src, iconImage; - - for (i = 0; i < 4; ++i) { - src = i + ''; - iconImage = new ol.style.IconImage_(src, null); - cache.set(src, null, null, iconImage); - } - - expect(cache.cacheSize_).to.eql(4); - - cache.expire(); - expect(cache.cacheSize_).to.eql(4); - - src = '4'; - iconImage = new ol.style.IconImage_(src, null); - cache.set(src, null, null, iconImage); - expect(cache.cacheSize_).to.eql(5); - - cache.expire(); // remove '0' and '4' - expect(cache.cacheSize_).to.eql(3); - - src = '0'; - iconImage = new ol.style.IconImage_(src, null); - ol.events.listen(iconImage, 'change', - ol.nullFunction, false); - cache.set(src, null, null, iconImage); - expect(cache.cacheSize_).to.eql(4); - - src = '4'; - iconImage = new ol.style.IconImage_(src, null); - ol.events.listen(iconImage, 'change', - ol.nullFunction, false); - cache.set(src, null, null, iconImage); - expect(cache.cacheSize_).to.eql(5); - - // check that '0' and '4' are not removed from the cache - cache.expire(); - expect(cache.get('0', null, null)).to.not.be(null); - expect(cache.get('4', null, null)).to.not.be(null); - }); - }); -}); diff --git a/test/spec/ol/style/iconimagecache.test.js b/test/spec/ol/style/iconimagecache.test.js new file mode 100644 index 0000000000..d1eb046142 --- /dev/null +++ b/test/spec/ol/style/iconimagecache.test.js @@ -0,0 +1,69 @@ +goog.provide('ol.test.style.IconImageCache'); + +goog.require('ol'); +goog.require('ol.events'); +goog.require('ol.style'); +goog.require('ol.style.IconImage'); + +describe('ol.style.IconImageCache', function() { + var originalMaxCacheSize; + + beforeEach(function() { + var cache = ol.style.iconImageCache; + cache.clear(); + originalMaxCacheSize = cache.maxCacheSize; + cache.maxCacheSize_ = 4; + }); + + afterEach(function() { + var cache = ol.style.iconImageCache; + cache.maxCacheSize_ = originalMaxCacheSize; + cache.clear(); + }); + + describe('#expire', function() { + it('expires images when expected', function() { + var cache = ol.style.iconImageCache; + + var i, src, iconImage; + + for (i = 0; i < 4; ++i) { + src = i + ''; + iconImage = new ol.style.IconImage(src, null); + cache.set(src, null, null, iconImage); + } + + expect(cache.cacheSize_).to.eql(4); + + cache.expire(); + expect(cache.cacheSize_).to.eql(4); + + src = '4'; + iconImage = new ol.style.IconImage(src, null); + cache.set(src, null, null, iconImage); + expect(cache.cacheSize_).to.eql(5); + + cache.expire(); // remove '0' and '4' + expect(cache.cacheSize_).to.eql(3); + + src = '0'; + iconImage = new ol.style.IconImage(src, null); + ol.events.listen(iconImage, 'change', + ol.nullFunction, false); + cache.set(src, null, null, iconImage); + expect(cache.cacheSize_).to.eql(4); + + src = '4'; + iconImage = new ol.style.IconImage(src, null); + ol.events.listen(iconImage, 'change', + ol.nullFunction, false); + cache.set(src, null, null, iconImage); + expect(cache.cacheSize_).to.eql(5); + + // check that '0' and '4' are not removed from the cache + cache.expire(); + expect(cache.get('0', null, null)).to.not.be(null); + expect(cache.get('4', null, null)).to.not.be(null); + }); + }); +}); diff --git a/test/spec/ol/tilegrid/tilegrid.test.js b/test/spec/ol/tilegrid/tilegrid.test.js index d0b811ef9e..ab89daf674 100644 --- a/test/spec/ol/tilegrid/tilegrid.test.js +++ b/test/spec/ol/tilegrid/tilegrid.test.js @@ -1,5 +1,6 @@ goog.provide('ol.test.TileGrid'); +goog.require('ol'); goog.require('ol.TileRange'); goog.require('ol.extent'); goog.require('ol.proj'); diff --git a/test/spec/ol/tileurlfunction.test.js b/test/spec/ol/tileurlfunction.test.js index d4f1019ff1..698ae0bcf4 100644 --- a/test/spec/ol/tileurlfunction.test.js +++ b/test/spec/ol/tileurlfunction.test.js @@ -74,6 +74,7 @@ describe('ol.TileUrlFunction', function() { templates, tileGrid); var tileCoord = [3, 2, -2]; + /* eslint-disable openlayers-internal/no-missing-requires */ sinon.stub(ol.tilecoord, 'hash', function() { return 3; }); @@ -91,6 +92,7 @@ describe('ol.TileUrlFunction', function() { }); expect(tileUrlFunction(tileCoord)).to.eql('http://tile-2/3/2/1'); ol.tilecoord.hash.restore(); + /* eslint-enable */ }); }); diff --git a/test/spec/ol/view.test.js b/test/spec/ol/view.test.js index ba006097fa..2d32a12adb 100644 --- a/test/spec/ol/view.test.js +++ b/test/spec/ol/view.test.js @@ -1,5 +1,6 @@ goog.provide('ol.test.View'); +goog.require('ol'); goog.require('ol.View'); goog.require('ol.extent'); goog.require('ol.geom.LineString'); diff --git a/test/test-extensions.js b/test/test-extensions.js index 0ce5e46a99..1c5c8c1c60 100644 --- a/test/test-extensions.js +++ b/test/test-extensions.js @@ -1,4 +1,5 @@ /* global resemble:false */ +/* eslint-disable openlayers-internal/no-missing-requires */ // FIXME remove afterLoadXml as it uses the wrong XML parser on IE9 diff --git a/test_rendering/.eslintrc b/test_rendering/.eslintrc new file mode 100644 index 0000000000..3bd7528f3c --- /dev/null +++ b/test_rendering/.eslintrc @@ -0,0 +1,5 @@ +{ + "rules": { + "openlayers-internal/valid-provide": 0 + } +} diff --git a/test_rendering/spec/ol/layer/tile.test.js b/test_rendering/spec/ol/layer/tile.test.js index 572c43700e..e6ba3d8b31 100644 --- a/test_rendering/spec/ol/layer/tile.test.js +++ b/test_rendering/spec/ol/layer/tile.test.js @@ -2,6 +2,7 @@ goog.provide('ol.test.rendering.layer.Tile'); goog.require('ol.Map'); goog.require('ol.View'); +goog.require('ol.extent'); goog.require('ol.geom.Point'); goog.require('ol.layer.Tile'); goog.require('ol.obj'); diff --git a/test_rendering/spec/ol/layer/vector.test.js b/test_rendering/spec/ol/layer/vector.test.js index e0acad7d7a..64d480bf5b 100644 --- a/test_rendering/spec/ol/layer/vector.test.js +++ b/test_rendering/spec/ol/layer/vector.test.js @@ -1,12 +1,15 @@ goog.provide('ol.test.rendering.layer.Vector'); +goog.require('ol.Feature'); goog.require('ol.Map'); goog.require('ol.View'); -goog.require('ol.Feature'); goog.require('ol.geom.Circle'); +goog.require('ol.geom.LineString'); goog.require('ol.geom.Polygon'); goog.require('ol.layer.Vector'); goog.require('ol.source.Vector'); +goog.require('ol.style.Stroke'); +goog.require('ol.style.Style'); describe('ol.rendering.layer.Vector', function() { diff --git a/test_rendering/spec/ol/reproj/tile.test.js b/test_rendering/spec/ol/reproj/tile.test.js index cce2b29035..cae2c4abd4 100644 --- a/test_rendering/spec/ol/reproj/tile.test.js +++ b/test_rendering/spec/ol/reproj/tile.test.js @@ -1,6 +1,6 @@ goog.provide('ol.test.rendering.reproj.Tile'); -goog.require('ol.TileState'); +goog.require('ol.Tile'); goog.require('ol.events'); goog.require('ol.proj'); goog.require('ol.reproj.Tile'); @@ -24,9 +24,9 @@ describe('ol.rendering.reproj.Tile', function() { tilesRequested++; return source.getTile(z, x, y, pixelRatio, sourceProjection); }); - if (tile.getState() == ol.TileState.IDLE) { + if (tile.getState() == ol.Tile.State.IDLE) { ol.events.listen(tile, 'change', function(e) { - if (tile.getState() == ol.TileState.LOADED) { + if (tile.getState() == ol.Tile.State.LOADED) { expect(tilesRequested).to.be(expectedRequests); resembleCanvas(tile.getImage(), expectedUrl, 7.5, done); }