From 88c3891bef07a143d8e9e16da973306dd19aba0c Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Mon, 28 Sep 2015 16:57:24 +0200 Subject: [PATCH] Replace goog.array.contains with ol.array.includes --- src/ol/array.js | 11 +++++++++++ src/ol/format/gpxformat.js | 6 +++--- src/ol/format/kmlformat.js | 19 ++++++++++--------- src/ol/interaction/selectinteraction.js | 3 ++- src/ol/interaction/translateinteraction.js | 6 +++--- src/ol/source/wmtssource.js | 7 ++++--- src/ol/webgl/context.js | 4 ++-- 7 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/ol/array.js b/src/ol/array.js index d630a7ed6c..e2744ce3b7 100644 --- a/src/ol/array.js +++ b/src/ol/array.js @@ -37,6 +37,17 @@ ol.array.binaryFindNearest = function(arr, target) { }; +/** + * Whether the array contains the given object. + * @param {Array.<*>} arr The array to test for the presence of the element. + * @param {*} obj The object for which to test. + * @return {boolean} The object is in the array. + */ +ol.array.includes = function(arr, obj) { + return arr.indexOf(obj) >= 0; +}; + + /** * @param {Array.} arr Array. * @param {number} target Target. diff --git a/src/ol/format/gpxformat.js b/src/ol/format/gpxformat.js index 2da803bf43..25a7363357 100644 --- a/src/ol/format/gpxformat.js +++ b/src/ol/format/gpxformat.js @@ -1,9 +1,9 @@ goog.provide('ol.format.GPX'); -goog.require('goog.array'); goog.require('goog.asserts'); goog.require('goog.dom.NodeType'); goog.require('ol.Feature'); +goog.require('ol.array'); goog.require('ol.format.Feature'); goog.require('ol.format.XMLFeature'); goog.require('ol.format.XSD'); @@ -449,7 +449,7 @@ ol.format.GPX.prototype.readFeature; ol.format.GPX.prototype.readFeatureFromNode = function(node, opt_options) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT, 'node.nodeType should be ELEMENT'); - if (!goog.array.contains(ol.format.GPX.NAMESPACE_URIS_, node.namespaceURI)) { + if (!ol.array.includes(ol.format.GPX.NAMESPACE_URIS_, node.namespaceURI)) { return null; } var featureReader = ol.format.GPX.FEATURE_READER_[node.localName]; @@ -483,7 +483,7 @@ ol.format.GPX.prototype.readFeatures; ol.format.GPX.prototype.readFeaturesFromNode = function(node, opt_options) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT, 'node.nodeType should be ELEMENT'); - if (!goog.array.contains(ol.format.GPX.NAMESPACE_URIS_, node.namespaceURI)) { + if (!ol.array.includes(ol.format.GPX.NAMESPACE_URIS_, node.namespaceURI)) { return []; } if (node.localName == 'gpx') { diff --git a/src/ol/format/kmlformat.js b/src/ol/format/kmlformat.js index 51d3427b7a..dc401f94c6 100644 --- a/src/ol/format/kmlformat.js +++ b/src/ol/format/kmlformat.js @@ -16,6 +16,7 @@ goog.require('goog.string'); goog.require('ol'); goog.require('ol.Feature'); goog.require('ol.FeatureStyleFunction'); +goog.require('ol.array'); goog.require('ol.color'); goog.require('ol.format.Feature'); goog.require('ol.format.XMLFeature'); @@ -683,7 +684,7 @@ ol.format.KML.readFlatLinearRing_ = function(node, objectStack) { ol.format.KML.gxCoordParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT, 'node.nodeType should be ELEMENT'); - goog.asserts.assert(goog.array.contains( + goog.asserts.assert(ol.array.includes( ol.format.KML.GX_NAMESPACE_URIS_, node.namespaceURI), 'namespaceURI of the node should be known to the KML parser'); goog.asserts.assert(node.localName == 'coord', 'localName should be coord'); @@ -716,7 +717,7 @@ ol.format.KML.gxCoordParser_ = function(node, objectStack) { ol.format.KML.readGxMultiTrack_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT, 'node.nodeType should be ELEMENT'); - goog.asserts.assert(goog.array.contains( + goog.asserts.assert(ol.array.includes( ol.format.KML.GX_NAMESPACE_URIS_, node.namespaceURI), 'namespaceURI of the node should be known to the KML parser'); goog.asserts.assert(node.localName == 'MultiTrack', @@ -742,7 +743,7 @@ ol.format.KML.readGxMultiTrack_ = function(node, objectStack) { ol.format.KML.readGxTrack_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT, 'node.nodeType should be ELEMENT'); - goog.asserts.assert(goog.array.contains( + goog.asserts.assert(ol.array.includes( ol.format.KML.GX_NAMESPACE_URIS_, node.namespaceURI), 'namespaceURI of the node should be known to the KML parser'); goog.asserts.assert(node.localName == 'Track', 'localName should be Track'); @@ -1777,7 +1778,7 @@ ol.format.KML.prototype.readFeature; ol.format.KML.prototype.readFeatureFromNode = function(node, opt_options) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT, 'node.nodeType should be ELEMENT'); - if (!goog.array.contains(ol.format.KML.NAMESPACE_URIS_, node.namespaceURI)) { + if (!ol.array.includes(ol.format.KML.NAMESPACE_URIS_, node.namespaceURI)) { return null; } goog.asserts.assert(node.localName == 'Placemark', @@ -1810,7 +1811,7 @@ ol.format.KML.prototype.readFeatures; ol.format.KML.prototype.readFeaturesFromNode = function(node, opt_options) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT, 'node.nodeType should be ELEMENT'); - if (!goog.array.contains(ol.format.KML.NAMESPACE_URIS_, node.namespaceURI)) { + if (!ol.array.includes(ol.format.KML.NAMESPACE_URIS_, node.namespaceURI)) { return []; } var features; @@ -1895,14 +1896,14 @@ ol.format.KML.prototype.readNameFromDocument = function(doc) { ol.format.KML.prototype.readNameFromNode = function(node) { var n; for (n = node.firstElementChild; !goog.isNull(n); n = n.nextElementSibling) { - if (goog.array.contains(ol.format.KML.NAMESPACE_URIS_, n.namespaceURI) && + if (ol.array.includes(ol.format.KML.NAMESPACE_URIS_, n.namespaceURI) && n.localName == 'name') { return ol.format.XSD.readString(n); } } for (n = node.firstElementChild; !goog.isNull(n); n = n.nextElementSibling) { var localName = ol.xml.getLocalName(n); - if (goog.array.contains(ol.format.KML.NAMESPACE_URIS_, n.namespaceURI) && + if (ol.array.includes(ol.format.KML.NAMESPACE_URIS_, n.namespaceURI) && (localName == 'Document' || localName == 'Folder' || localName == 'Placemark' || @@ -1964,7 +1965,7 @@ ol.format.KML.prototype.readNetworkLinksFromDocument = function(doc) { ol.format.KML.prototype.readNetworkLinksFromNode = function(node) { var n, networkLinks = []; for (n = node.firstElementChild; !goog.isNull(n); n = n.nextElementSibling) { - if (goog.array.contains(ol.format.KML.NAMESPACE_URIS_, n.namespaceURI) && + if (ol.array.includes(ol.format.KML.NAMESPACE_URIS_, n.namespaceURI) && n.localName == 'NetworkLink') { var obj = ol.xml.pushParseAndPop({}, ol.format.KML.NETWORK_LINK_PARSERS_, n, []); @@ -1973,7 +1974,7 @@ ol.format.KML.prototype.readNetworkLinksFromNode = function(node) { } for (n = node.firstElementChild; !goog.isNull(n); n = n.nextElementSibling) { var localName = ol.xml.getLocalName(n); - if (goog.array.contains(ol.format.KML.NAMESPACE_URIS_, n.namespaceURI) && + if (ol.array.includes(ol.format.KML.NAMESPACE_URIS_, n.namespaceURI) && (localName == 'Document' || localName == 'Folder' || localName == 'kml')) { diff --git a/src/ol/interaction/selectinteraction.js b/src/ol/interaction/selectinteraction.js index 57a0d506ae..4d5653b863 100644 --- a/src/ol/interaction/selectinteraction.js +++ b/src/ol/interaction/selectinteraction.js @@ -10,6 +10,7 @@ goog.require('goog.events.Event'); goog.require('goog.functions'); goog.require('ol.CollectionEventType'); goog.require('ol.Feature'); +goog.require('ol.array'); goog.require('ol.events.condition'); goog.require('ol.geom.GeometryType'); goog.require('ol.interaction.Interaction'); @@ -160,7 +161,7 @@ ol.interaction.Select = function(opt_options) { * @return {boolean} Include. */ function(layer) { - return goog.array.contains(layers, layer); + return ol.array.includes(layers, layer); }; } } else { diff --git a/src/ol/interaction/translateinteraction.js b/src/ol/interaction/translateinteraction.js index 1f2ec0bd1e..50642851d8 100644 --- a/src/ol/interaction/translateinteraction.js +++ b/src/ol/interaction/translateinteraction.js @@ -1,6 +1,6 @@ goog.provide('ol.interaction.Translate'); -goog.require('goog.array'); +goog.require('ol.array'); goog.require('ol.interaction.Pointer'); @@ -131,7 +131,7 @@ ol.interaction.Translate.handleMoveEvent_ = function(event) var isSelected = false; if (!goog.isNull(this.features_) && - goog.array.contains(this.features_.getArray(), intersectingFeature)) { + ol.array.includes(this.features_.getArray(), intersectingFeature)) { isSelected = true; } @@ -172,7 +172,7 @@ ol.interaction.Translate.prototype.featuresAtPixel_ = function(pixel, map) { }); if (!goog.isNull(this.features_) && - goog.array.contains(this.features_.getArray(), intersectingFeature)) { + ol.array.includes(this.features_.getArray(), intersectingFeature)) { found = intersectingFeature; } diff --git a/src/ol/source/wmtssource.js b/src/ol/source/wmtssource.js index 4b6c126538..d4317d8fe6 100644 --- a/src/ol/source/wmtssource.js +++ b/src/ol/source/wmtssource.js @@ -8,6 +8,7 @@ goog.require('goog.string'); goog.require('goog.uri.utils'); goog.require('ol.TileUrlFunction'); goog.require('ol.TileUrlFunctionType'); +goog.require('ol.array'); goog.require('ol.extent'); goog.require('ol.proj'); goog.require('ol.source.TileImage'); @@ -405,7 +406,7 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) { var key = elt['Identifier']; var value = elt['default']; if (value !== undefined) { - goog.asserts.assert(goog.array.contains(elt['values'], value), + goog.asserts.assert(ol.array.includes(elt['values'], value), 'default value contained in values'); } else { value = elt['values'][0]; @@ -457,7 +458,7 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) { requestEncoding = requestEncoding !== undefined ? requestEncoding : ''; goog.asserts.assert( - goog.array.contains(['REST', 'RESTful', 'KVP', ''], requestEncoding), + ol.array.includes(['REST', 'RESTful', 'KVP', ''], requestEncoding), 'requestEncoding (%s) is one of "REST", "RESTful", "KVP" or ""', requestEncoding); @@ -481,7 +482,7 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) { return elt['name'] == 'GetEncoding'; }); var encodings = constraint['AllowedValues']['Value']; - if (encodings.length > 0 && goog.array.contains(encodings, 'KVP')) { + if (encodings.length > 0 && ol.array.includes(encodings, 'KVP')) { requestEncoding = ol.source.WMTSRequestEncoding.KVP; urls.push(/** @type {string} */ (gets[i]['href'])); } diff --git a/src/ol/webgl/context.js b/src/ol/webgl/context.js index f5cba1baa2..6b95937be5 100644 --- a/src/ol/webgl/context.js +++ b/src/ol/webgl/context.js @@ -1,11 +1,11 @@ goog.provide('ol.webgl.Context'); -goog.require('goog.array'); goog.require('goog.asserts'); goog.require('goog.events'); goog.require('goog.log'); goog.require('goog.object'); goog.require('ol'); +goog.require('ol.array'); goog.require('ol.webgl.Buffer'); goog.require('ol.webgl.WebGLContextEventType'); @@ -87,7 +87,7 @@ ol.webgl.Context = function(canvas, gl) { /** * @type {boolean} */ - this.hasOESElementIndexUint = goog.array.contains( + this.hasOESElementIndexUint = ol.array.includes( ol.WEBGL_EXTENSIONS, 'OES_element_index_uint'); // use the OES_element_index_uint extension if available