Replace goog.array.contains with ol.array.includes

This commit is contained in:
Frederic Junod
2015-09-28 16:57:24 +02:00
parent 504e67303f
commit 88c3891bef
7 changed files with 35 additions and 21 deletions

View File

@@ -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.<number>} arr Array.
* @param {number} target Target.

View File

@@ -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') {

View File

@@ -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')) {

View File

@@ -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 {

View File

@@ -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;
}

View File

@@ -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']));
}

View File

@@ -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