From d1b6a177735e778b3aa3c7d459767a959b3ce53c Mon Sep 17 00:00:00 2001 From: Nicholas L Date: Sun, 17 Jan 2016 15:45:57 +1300 Subject: [PATCH] Remove goog.array.extend --- src/ol/array.js | 16 ++++++++++++++++ src/ol/format/gml/gml3format.js | 4 ++-- src/ol/format/gml/gmlbaseformat.js | 4 ++-- src/ol/format/kmlformat.js | 17 ++++++++--------- src/ol/format/osmxmlformat.js | 4 ++-- src/ol/format/wmsgetfeatureinfoformat.js | 3 +-- src/ol/format/xmlfeatureformat.js | 4 ++-- src/ol/geom/linestring.js | 4 ++-- src/ol/geom/multilinestring.js | 8 ++++---- src/ol/geom/multipoint.js | 4 ++-- src/ol/geom/multipolygon.js | 6 +++--- src/ol/geom/polygon.js | 5 +++-- src/ol/interaction/selectinteraction.js | 5 ++--- src/ol/source/vectorsource.js | 4 ++-- src/ol/xml.js | 4 ++-- 15 files changed, 53 insertions(+), 39 deletions(-) diff --git a/src/ol/array.js b/src/ol/array.js index 10b2bb4bc2..21a468b43f 100644 --- a/src/ol/array.js +++ b/src/ol/array.js @@ -142,3 +142,19 @@ ol.array.flatten = function(arr) { }, []); return data; }; + + +// TODO: Optimisation by storing length or iterating backwards etc +/** + * @param {Array} arr The array to modify. + * @param {Array|VALUE} data The elements or arrays of elements + * to add to arr1. + * @template VALUE + */ +ol.array.extend = function(arr, data) { + var i; + var extension = goog.isArrayLike(data) ? data : [data]; + for (i = 0; i < extension.length; i++) { + arr[arr.length] = extension[i]; + } +} diff --git a/src/ol/format/gml/gml3format.js b/src/ol/format/gml/gml3format.js index 30242c0a60..7fa417d5fe 100644 --- a/src/ol/format/gml/gml3format.js +++ b/src/ol/format/gml/gml3format.js @@ -1,11 +1,11 @@ goog.provide('ol.format.GML'); goog.provide('ol.format.GML3'); -goog.require('goog.array'); goog.require('goog.asserts'); goog.require('goog.dom.NodeType'); goog.require('goog.object'); goog.require('ol'); +goog.require('ol.array'); goog.require('ol.Feature'); goog.require('ol.extent'); goog.require('ol.format.Feature'); @@ -305,7 +305,7 @@ ol.format.GML3.prototype.readSurface_ = function(node, objectStack) { var ends = [flatCoordinates.length]; var i, ii; for (i = 1, ii = flatLinearRings.length; i < ii; ++i) { - goog.array.extend(flatCoordinates, flatLinearRings[i]); + ol.array.extend(flatCoordinates, flatLinearRings[i]); ends.push(flatCoordinates.length); } polygon.setFlatCoordinates( diff --git a/src/ol/format/gml/gmlbaseformat.js b/src/ol/format/gml/gmlbaseformat.js index 6a50ba5ac2..54d3626aa8 100644 --- a/src/ol/format/gml/gmlbaseformat.js +++ b/src/ol/format/gml/gmlbaseformat.js @@ -3,11 +3,11 @@ // envelopes/extents, only geometries! goog.provide('ol.format.GMLBase'); -goog.require('goog.array'); goog.require('goog.asserts'); goog.require('goog.dom.NodeType'); goog.require('goog.object'); goog.require('goog.string'); +goog.require('ol.array'); goog.require('ol.Feature'); goog.require('ol.format.Feature'); goog.require('ol.format.XMLFeature'); @@ -451,7 +451,7 @@ ol.format.GMLBase.prototype.readPolygon = function(node, objectStack) { var ends = [flatCoordinates.length]; var i, ii; for (i = 1, ii = flatLinearRings.length; i < ii; ++i) { - goog.array.extend(flatCoordinates, flatLinearRings[i]); + ol.array.extend(flatCoordinates, flatLinearRings[i]); ends.push(flatCoordinates.length); } polygon.setFlatCoordinates( diff --git a/src/ol/format/kmlformat.js b/src/ol/format/kmlformat.js index d853520b85..3cec0193f0 100644 --- a/src/ol/format/kmlformat.js +++ b/src/ol/format/kmlformat.js @@ -7,7 +7,6 @@ goog.provide('ol.format.KML'); goog.require('goog.Uri'); -goog.require('goog.array'); goog.require('goog.asserts'); goog.require('goog.dom.NodeType'); goog.require('goog.object'); @@ -1021,7 +1020,7 @@ ol.format.KML.readMultiGeometry_ = function(node, objectStack) { 'geometry should be an ol.geom.Point'); goog.asserts.assert(geometry.getLayout() == layout, 'geometry layout should be consistent'); - goog.array.extend(flatCoordinates, geometry.getFlatCoordinates()); + ol.array.extend(flatCoordinates, geometry.getFlatCoordinates()); } var multiPoint = new ol.geom.MultiPoint(null); multiPoint.setFlatCoordinates(layout, flatCoordinates); @@ -1100,7 +1099,7 @@ ol.format.KML.readPolygon_ = function(node, objectStack) { var ends = [flatCoordinates.length]; var i, ii; for (i = 1, ii = flatLinearRings.length; i < ii; ++i) { - goog.array.extend(flatCoordinates, flatLinearRings[i]); + ol.array.extend(flatCoordinates, flatLinearRings[i]); ends.push(flatCoordinates.length); } polygon.setFlatCoordinates( @@ -1955,7 +1954,7 @@ ol.format.KML.prototype.readFeaturesFromNode = function(node, opt_options) { for (n = node.firstElementChild; n; n = n.nextElementSibling) { var fs = this.readFeaturesFromNode(n, opt_options); if (fs) { - goog.array.extend(features, fs); + ol.array.extend(features, fs); } } return features; @@ -2044,14 +2043,14 @@ ol.format.KML.prototype.readNameFromNode = function(node) { ol.format.KML.prototype.readNetworkLinks = function(source) { var networkLinks = []; if (ol.xml.isDocument(source)) { - goog.array.extend(networkLinks, this.readNetworkLinksFromDocument( + ol.array.extend(networkLinks, this.readNetworkLinksFromDocument( /** @type {Document} */ (source))); } else if (ol.xml.isNode(source)) { - goog.array.extend(networkLinks, this.readNetworkLinksFromNode( + ol.array.extend(networkLinks, this.readNetworkLinksFromNode( /** @type {Node} */ (source))); } else if (goog.isString(source)) { var doc = ol.xml.parse(source); - goog.array.extend(networkLinks, this.readNetworkLinksFromDocument(doc)); + ol.array.extend(networkLinks, this.readNetworkLinksFromDocument(doc)); } else { goog.asserts.fail('unknown type for source'); } @@ -2067,7 +2066,7 @@ ol.format.KML.prototype.readNetworkLinksFromDocument = function(doc) { var n, networkLinks = []; for (n = doc.firstChild; n; n = n.nextSibling) { if (n.nodeType == goog.dom.NodeType.ELEMENT) { - goog.array.extend(networkLinks, this.readNetworkLinksFromNode(n)); + ol.array.extend(networkLinks, this.readNetworkLinksFromNode(n)); } } return networkLinks; @@ -2094,7 +2093,7 @@ ol.format.KML.prototype.readNetworkLinksFromNode = function(node) { (localName == 'Document' || localName == 'Folder' || localName == 'kml')) { - goog.array.extend(networkLinks, this.readNetworkLinksFromNode(n)); + ol.array.extend(networkLinks, this.readNetworkLinksFromNode(n)); } } return networkLinks; diff --git a/src/ol/format/osmxmlformat.js b/src/ol/format/osmxmlformat.js index 398ece9a71..54630e5526 100644 --- a/src/ol/format/osmxmlformat.js +++ b/src/ol/format/osmxmlformat.js @@ -1,10 +1,10 @@ // FIXME add typedef for stack state objects goog.provide('ol.format.OSMXML'); -goog.require('goog.array'); goog.require('goog.asserts'); goog.require('goog.dom.NodeType'); goog.require('goog.object'); +goog.require('ol.array'); goog.require('ol.Feature'); goog.require('ol.format.Feature'); goog.require('ol.format.XMLFeature'); @@ -103,7 +103,7 @@ ol.format.OSMXML.readWay_ = function(node, objectStack) { var flatCoordinates = /** @type {Array.} */ ([]); for (var i = 0, ii = values.ndrefs.length; i < ii; i++) { var point = state.nodes[values.ndrefs[i]]; - goog.array.extend(flatCoordinates, point); + ol.array.extend(flatCoordinates, point); } var geometry; if (values.ndrefs[0] == values.ndrefs[values.ndrefs.length - 1]) { diff --git a/src/ol/format/wmsgetfeatureinfoformat.js b/src/ol/format/wmsgetfeatureinfoformat.js index 0157b197fe..a9af65ae14 100644 --- a/src/ol/format/wmsgetfeatureinfoformat.js +++ b/src/ol/format/wmsgetfeatureinfoformat.js @@ -1,6 +1,5 @@ goog.provide('ol.format.WMSGetFeatureInfo'); -goog.require('goog.array'); goog.require('goog.asserts'); goog.require('goog.dom.NodeType'); goog.require('goog.object'); @@ -118,7 +117,7 @@ ol.format.WMSGetFeatureInfo.prototype.readFeatures_ = function(node, objectStack var layerFeatures = ol.xml.pushParseAndPop( [], parsersNS, layer, objectStack, this.gmlFormat_); if (layerFeatures) { - goog.array.extend(features, layerFeatures); + ol.array.extend(features, layerFeatures); } } } diff --git a/src/ol/format/xmlfeatureformat.js b/src/ol/format/xmlfeatureformat.js index 76b86baf6b..49e3288258 100644 --- a/src/ol/format/xmlfeatureformat.js +++ b/src/ol/format/xmlfeatureformat.js @@ -1,9 +1,9 @@ goog.provide('ol.format.XMLFeature'); -goog.require('goog.array'); goog.require('goog.asserts'); goog.require('goog.dom.NodeType'); goog.require('goog.dom.xml'); +goog.require('ol.array'); goog.require('ol.format.Feature'); goog.require('ol.format.FormatType'); goog.require('ol.proj'); @@ -108,7 +108,7 @@ ol.format.XMLFeature.prototype.readFeaturesFromDocument = function( var n; for (n = doc.firstChild; n; n = n.nextSibling) { if (n.nodeType == goog.dom.NodeType.ELEMENT) { - goog.array.extend(features, this.readFeaturesFromNode(n, opt_options)); + ol.array.extend(features, this.readFeaturesFromNode(n, opt_options)); } } return features; diff --git a/src/ol/geom/linestring.js b/src/ol/geom/linestring.js index 2be2b21b10..4d8722584c 100644 --- a/src/ol/geom/linestring.js +++ b/src/ol/geom/linestring.js @@ -1,8 +1,8 @@ goog.provide('ol.geom.LineString'); -goog.require('goog.array'); goog.require('goog.asserts'); goog.require('ol'); +goog.require('ol.array'); goog.require('ol.extent'); goog.require('ol.geom.GeometryLayout'); goog.require('ol.geom.GeometryType'); @@ -72,7 +72,7 @@ ol.geom.LineString.prototype.appendCoordinate = function(coordinate) { if (!this.flatCoordinates) { this.flatCoordinates = coordinate.slice(); } else { - goog.array.extend(this.flatCoordinates, coordinate); + ol.array.extend(this.flatCoordinates, coordinate); } this.changed(); }; diff --git a/src/ol/geom/multilinestring.js b/src/ol/geom/multilinestring.js index fce9293baf..81b91f22b6 100644 --- a/src/ol/geom/multilinestring.js +++ b/src/ol/geom/multilinestring.js @@ -1,8 +1,8 @@ goog.provide('ol.geom.MultiLineString'); -goog.require('goog.array'); goog.require('goog.asserts'); goog.require('ol'); +goog.require('ol.array'); goog.require('ol.extent'); goog.require('ol.geom.GeometryLayout'); goog.require('ol.geom.GeometryType'); @@ -65,7 +65,7 @@ ol.geom.MultiLineString.prototype.appendLineString = function(lineString) { if (!this.flatCoordinates) { this.flatCoordinates = lineString.getFlatCoordinates().slice(); } else { - goog.array.extend( + ol.array.extend( this.flatCoordinates, lineString.getFlatCoordinates().slice()); } this.ends_.push(this.flatCoordinates.length); @@ -216,7 +216,7 @@ ol.geom.MultiLineString.prototype.getFlatMidpoints = function() { var end = ends[i]; var midpoint = ol.geom.flat.interpolate.lineString( flatCoordinates, offset, end, stride, 0.5); - goog.array.extend(midpoints, midpoint); + ol.array.extend(midpoints, midpoint); offset = end; } return midpoints; @@ -319,7 +319,7 @@ ol.geom.MultiLineString.prototype.setLineStrings = function(lineStrings) { goog.asserts.assert(lineString.getLayout() == layout, 'layout of lineString should match layout'); } - goog.array.extend(flatCoordinates, lineString.getFlatCoordinates()); + ol.array.extend(flatCoordinates, lineString.getFlatCoordinates()); ends.push(flatCoordinates.length); } this.setFlatCoordinates(layout, flatCoordinates, ends); diff --git a/src/ol/geom/multipoint.js b/src/ol/geom/multipoint.js index 5a8d9d1201..b9eaae92a5 100644 --- a/src/ol/geom/multipoint.js +++ b/src/ol/geom/multipoint.js @@ -1,7 +1,7 @@ goog.provide('ol.geom.MultiPoint'); -goog.require('goog.array'); goog.require('goog.asserts'); +goog.require('ol.array'); goog.require('ol.extent'); goog.require('ol.geom.GeometryLayout'); goog.require('ol.geom.GeometryType'); @@ -40,7 +40,7 @@ ol.geom.MultiPoint.prototype.appendPoint = function(point) { if (!this.flatCoordinates) { this.flatCoordinates = point.getFlatCoordinates().slice(); } else { - goog.array.extend(this.flatCoordinates, point.getFlatCoordinates()); + ol.array.extend(this.flatCoordinates, point.getFlatCoordinates()); } this.changed(); }; diff --git a/src/ol/geom/multipolygon.js b/src/ol/geom/multipolygon.js index 0570ebca48..5e943c03f9 100644 --- a/src/ol/geom/multipolygon.js +++ b/src/ol/geom/multipolygon.js @@ -1,9 +1,9 @@ goog.provide('ol.geom.MultiPolygon'); -goog.require('goog.array'); goog.require('goog.asserts'); goog.require('goog.object'); goog.require('ol'); +goog.require('ol.array'); goog.require('ol.extent'); goog.require('ol.geom.GeometryLayout'); goog.require('ol.geom.GeometryType'); @@ -100,7 +100,7 @@ ol.geom.MultiPolygon.prototype.appendPolygon = function(polygon) { this.endss_.push(); } else { var offset = this.flatCoordinates.length; - goog.array.extend(this.flatCoordinates, polygon.getFlatCoordinates()); + ol.array.extend(this.flatCoordinates, polygon.getFlatCoordinates()); ends = polygon.getEnds().slice(); var i, ii; for (i = 0, ii = ends.length; i < ii; ++i) { @@ -424,7 +424,7 @@ ol.geom.MultiPolygon.prototype.setPolygons = function(polygons) { for (j = 0, jj = ends.length; j < jj; ++j) { ends[j] += offset; } - goog.array.extend(flatCoordinates, polygon.getFlatCoordinates()); + ol.array.extend(flatCoordinates, polygon.getFlatCoordinates()); endss.push(ends); } this.setFlatCoordinates(layout, flatCoordinates, endss); diff --git a/src/ol/geom/polygon.js b/src/ol/geom/polygon.js index 24fa72c6e9..a6e0b86bc6 100644 --- a/src/ol/geom/polygon.js +++ b/src/ol/geom/polygon.js @@ -4,6 +4,7 @@ goog.require('goog.array'); goog.require('goog.asserts'); goog.require('goog.math'); goog.require('ol'); +goog.require('ol.array'); goog.require('ol.extent'); goog.require('ol.geom.GeometryLayout'); goog.require('ol.geom.GeometryType'); @@ -94,7 +95,7 @@ ol.geom.Polygon.prototype.appendLinearRing = function(linearRing) { if (!this.flatCoordinates) { this.flatCoordinates = linearRing.getFlatCoordinates().slice(); } else { - goog.array.extend(this.flatCoordinates, linearRing.getFlatCoordinates()); + ol.array.extend(this.flatCoordinates, linearRing.getFlatCoordinates()); } this.ends_.push(this.flatCoordinates.length); this.changed(); @@ -390,7 +391,7 @@ ol.geom.Polygon.circular = function(sphere, center, radius, opt_n) { var flatCoordinates = []; var i; for (i = 0; i < n; ++i) { - goog.array.extend( + ol.array.extend( flatCoordinates, sphere.offset(center, radius, 2 * Math.PI * i / n)); } flatCoordinates.push(flatCoordinates[0], flatCoordinates[1]); diff --git a/src/ol/interaction/selectinteraction.js b/src/ol/interaction/selectinteraction.js index 81fa25838f..a11231a5bc 100644 --- a/src/ol/interaction/selectinteraction.js +++ b/src/ol/interaction/selectinteraction.js @@ -3,7 +3,6 @@ goog.provide('ol.interaction.SelectEvent'); goog.provide('ol.interaction.SelectEventType'); goog.provide('ol.interaction.SelectFilterFunction'); -goog.require('goog.array'); goog.require('goog.asserts'); goog.require('goog.events'); goog.require('goog.events.Event'); @@ -384,9 +383,9 @@ ol.interaction.Select.prototype.setMap = function(map) { */ ol.interaction.Select.getDefaultStyleFunction = function() { var styles = ol.style.createDefaultEditingStyles(); - goog.array.extend(styles[ol.geom.GeometryType.POLYGON], + ol.array.extend(styles[ol.geom.GeometryType.POLYGON], styles[ol.geom.GeometryType.LINE_STRING]); - goog.array.extend(styles[ol.geom.GeometryType.GEOMETRY_COLLECTION], + ol.array.extend(styles[ol.geom.GeometryType.GEOMETRY_COLLECTION], styles[ol.geom.GeometryType.LINE_STRING]); return function(feature, resolution) { diff --git a/src/ol/source/vectorsource.js b/src/ol/source/vectorsource.js index 8a40546170..38867af174 100644 --- a/src/ol/source/vectorsource.js +++ b/src/ol/source/vectorsource.js @@ -5,7 +5,6 @@ goog.provide('ol.source.Vector'); goog.provide('ol.source.VectorEvent'); goog.provide('ol.source.VectorEventType'); -goog.require('goog.array'); goog.require('goog.asserts'); goog.require('goog.events'); goog.require('goog.events.Event'); @@ -19,6 +18,7 @@ goog.require('ol.Feature'); goog.require('ol.FeatureLoader'); goog.require('ol.LoadingStrategy'); goog.require('ol.ObjectEventType'); +goog.require('ol.array'); goog.require('ol.extent'); goog.require('ol.featureloader'); goog.require('ol.loadingstrategy'); @@ -552,7 +552,7 @@ ol.source.Vector.prototype.getFeatures = function() { } else if (this.featuresRtree_) { features = this.featuresRtree_.getAll(); if (!goog.object.isEmpty(this.nullGeometryFeatures_)) { - goog.array.extend( + ol.array.extend( features, goog.object.getValues(this.nullGeometryFeatures_)); } } diff --git a/src/ol/xml.js b/src/ol/xml.js index 3a681947e3..780a9be248 100644 --- a/src/ol/xml.js +++ b/src/ol/xml.js @@ -1,11 +1,11 @@ goog.provide('ol.xml'); -goog.require('goog.array'); goog.require('goog.asserts'); goog.require('goog.dom.NodeType'); goog.require('goog.dom.xml'); goog.require('goog.object'); goog.require('goog.userAgent'); +goog.require('ol.array'); /** @@ -370,7 +370,7 @@ ol.xml.makeArrayExtender = function(valueReader, opt_this) { (objectStack[objectStack.length - 1]); goog.asserts.assert(goog.isArray(array), 'objectStack is supposed to be an array of arrays'); - goog.array.extend(array, value); + ol.array.extend(array, value); } }); };