From 9b492f49c7626f666be49c133a1bede0d3069d29 Mon Sep 17 00:00:00 2001 From: Nicholas L Date: Sun, 17 Jan 2016 18:37:43 +1300 Subject: [PATCH] Remove goog.array.findIndex --- src/ol/array.js | 25 +++++++++++++++++++++++++ src/ol/source/wmtssource.js | 7 +++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/ol/array.js b/src/ol/array.js index 5a59474fda..682b78cf98 100644 --- a/src/ol/array.js +++ b/src/ol/array.js @@ -239,3 +239,28 @@ ol.array.stableSort = function(arr, compareFnc) { arr[i] = tmp[i].value; } } + + +/** +* @param {goog.array.ArrayLike} arr The first array to compare.. +* @param {Function} func Optional comparison function. +* @param {THISVAL=} opt_thisArg Optional this argument for the function. +* @template THISVAL +* @return {number} Whether the two arrays are equal. + */ +ol.array.findIndex = function(arr, func, opt_thisArg) { + if (typeof func !== 'function') { + throw new TypeError('func must be a function'); + } + var list = Object(arr); + var length = list.length >>> 0; + var value; + + for (var i = 0; i < length; i++) { + value = list[i]; + if (func.call(opt_thisArg, value, i, list)) { + return i; + } + } + return -1; +} diff --git a/src/ol/source/wmtssource.js b/src/ol/source/wmtssource.js index 22b591aa40..8284404296 100644 --- a/src/ol/source/wmtssource.js +++ b/src/ol/source/wmtssource.js @@ -1,7 +1,6 @@ goog.provide('ol.source.WMTS'); goog.provide('ol.source.WMTSRequestEncoding'); -goog.require('goog.array'); goog.require('goog.asserts'); goog.require('goog.object'); goog.require('goog.uri.utils'); @@ -338,7 +337,7 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) { var idx, matrixSet; if (l['TileMatrixSetLink'].length > 1) { if ('projection' in config) { - idx = goog.array.findIndex(l['TileMatrixSetLink'], + idx = ol.array.findIndex(l['TileMatrixSetLink'], function(elt, index, array) { var tileMatrixSet = ol.array.find(tileMatrixSets, function(el) { return el['Identifier'] == elt['TileMatrixSet']; @@ -348,7 +347,7 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) { ) == config['projection']; }); } else { - idx = goog.array.findIndex(l['TileMatrixSetLink'], + idx = ol.array.findIndex(l['TileMatrixSetLink'], function(elt, index, array) { return elt['TileMatrixSet'] == config['matrixSet']; }); @@ -368,7 +367,7 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) { if ('format' in config) { format = config['format']; } - idx = goog.array.findIndex(l['Style'], function(elt, index, array) { + idx = ol.array.findIndex(l['Style'], function(elt, index, array) { if ('style' in config) { return elt['Title'] == config['style']; } else {