From eae04c92bcd785ea81693b3c6ae8f2cda589f209 Mon Sep 17 00:00:00 2001 From: Xavier Mamano Date: Wed, 16 Nov 2011 19:51:28 +0100 Subject: [PATCH 01/10] cancelDelay before measureImmediate + changes in tests. --- lib/OpenLayers/Control/Measure.js | 4 ++-- tests/Control/Measure.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/OpenLayers/Control/Measure.js b/lib/OpenLayers/Control/Measure.js index f57f6c4465..a8f66dd89a 100644 --- a/lib/OpenLayers/Control/Measure.js +++ b/lib/OpenLayers/Control/Measure.js @@ -230,8 +230,8 @@ OpenLayers.Control.Measure = OpenLayers.Class(OpenLayers.Control, { * mouseposition. feature - {} The sketch feature. */ measureImmediate : function(point, feature, drawing) { - if (drawing && this.delayedTrigger === null && - !this.handler.freehandMode(this.handler.evt)) { + if (drawing && !this.handler.freehandMode(this.handler.evt)) { + this.cancelDelay(); this.measure(feature.geometry, "measurepartial"); } }, diff --git a/tests/Control/Measure.html b/tests/Control/Measure.html index 045f807d36..fb55fc9364 100644 --- a/tests/Control/Measure.html +++ b/tests/Control/Measure.html @@ -289,7 +289,7 @@ // move 10 pixels trigger("mousemove", 0, 10); - t.eq(log.length, 0, "a) no event fired yet"); + t.eq(log.length, 1, "a) no event fired yet"); t.delay_call( delay, function() { @@ -298,7 +298,7 @@ t.ok(log[0] && log[0].type == "measurepartial", "a) correct type"); // mousemove within the partialDelay fires no event, so the // measure below is the one of the initial point - t.ok(log[0] && log[0].measure == 0, "a) correct measure"); + t.eq(log[0]?log[0].measure:-1 , 10, "a) correct measure"); // b) move 10 pixels trigger("mousemove", 0, 20); From 7c76b90a2de0f27f5b4c6d7e5c6ba7b451f24d33 Mon Sep 17 00:00:00 2001 From: Xavier Mamano Date: Tue, 17 Jan 2012 22:45:25 +0100 Subject: [PATCH 02/10] Test Measure: Correct the text of expected result. --- tests/Control/Measure.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Control/Measure.html b/tests/Control/Measure.html index fb55fc9364..58df363f6e 100644 --- a/tests/Control/Measure.html +++ b/tests/Control/Measure.html @@ -289,12 +289,12 @@ // move 10 pixels trigger("mousemove", 0, 10); - t.eq(log.length, 1, "a) no event fired yet"); + t.eq(log.length, 1, "a) has fired an event"); t.delay_call( delay, function() { // confirm measurepartial is fired - t.eq(log.length, 1, "a) event logged"); + t.eq(log.length, 1, "a) one event logged"); t.ok(log[0] && log[0].type == "measurepartial", "a) correct type"); // mousemove within the partialDelay fires no event, so the // measure below is the one of the initial point From bcba6bb0fd828cbe1c2a46bd47d3472c6954475b Mon Sep 17 00:00:00 2001 From: Peter Robins Date: Sat, 3 Mar 2012 17:06:14 +0000 Subject: [PATCH 03/10] Map: make options.center compatible with permalink --- lib/OpenLayers/Map.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index 96744b4dd2..016c4110b8 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -628,9 +628,9 @@ OpenLayers.Map = OpenLayers.Class({ * be properly set below. */ delete this.center; - this.addLayers(options.layers); + this.addLayers(options.layers); // set center (and optionally zoom) - if (options.center) { + if (options.center && !this.getCenter()) { // zoom can be undefined here this.setCenter(options.center, options.zoom); } From 935d621113b287496df8b0432b3cecf826a63de4 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sat, 3 Mar 2012 14:30:03 -0700 Subject: [PATCH 04/10] Testing that the permalink works with map options. The permalink/argparser combo doesn't properly handle map configurations where layers and a map location are provided (see #270). --- tests/Control/Permalink.html | 57 +++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/tests/Control/Permalink.html b/tests/Control/Permalink.html index 843cdbf181..3260eaf24f 100644 --- a/tests/Control/Permalink.html +++ b/tests/Control/Permalink.html @@ -322,8 +322,12 @@ t.ok(OpenLayers.Util.isEquivalentUrl(OpenLayers.Util.getElement('permalink').href, location+"#zoom=2&lat=0&lon=1.75781&layers=BF"), 'setVisibility sets permalink'); } - function test_arrayCenter(t) { - t.plan(1); + function test_center_from_map(t) { + t.plan(7); + + var previous = window.location.hash; + window.location.hash = ""; + var err; try { var map = new OpenLayers.Map({ @@ -331,8 +335,8 @@ controls: [ new OpenLayers.Control.Permalink({anchor: true}) ], - center: [0, 0], - zoom: 1 + center: [1, 2], + zoom: 3 }); } catch (e) { err = e; @@ -342,6 +346,51 @@ } else { t.ok(true, "Map construction works"); } + + // confirm that map center is correctly set + var center = map.getCenter(); + t.eq(center.lon, 1, "map x"); + t.eq(center.lat, 2, "map y") + t.eq(map.getZoom(), 3, "map z"); + + // confirm that location from map options has been added to url + var params = OpenLayers.Util.getParameters(window.location.hash.replace("#", "?")); + t.eq(params.lon, "1", "url x"); + t.eq(params.lat, "2", "url y"); + t.eq(params.zoom, "3", "url z"); + + // map.destroy(); + window.location.hash = previous; + } + + function test_center_from_url(t) { + t.plan(6); + + // In cases where the location is specified in the URL and given in + // the map options, we respect the location in the URL. + var previous = window.location.hash; + window.location.hash = "#zoom=6&lat=5&lon=4&layers=B" + + var map = new OpenLayers.Map({ + layers: [new OpenLayers.Layer(null, {isBaseLayer: true})], + controls: [new OpenLayers.Control.Permalink({anchor: true})], + center: [0, 0], + zoom: 0 + }); + + // confirm that map center is correctly set + var center = map.getCenter(); + t.eq(center.lon, 4, "map x"); + t.eq(center.lat, 5, "map y") + t.eq(map.getZoom(), 6, "map z"); + + var params = OpenLayers.Util.getParameters(window.location.hash.replace("#", "?")); + t.eq(params.lon, "4", "x set"); + t.eq(params.lat, "5", "y set"); + t.eq(params.zoom, "6", "z set"); + + // map.destroy(); + window.location.hash = previous; } From 6712dd9680c6567109b2e6aef952815670057164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Sat, 3 Mar 2012 22:35:17 +0100 Subject: [PATCH 05/10] Revert "Collecting tests together." This reverts commit fb748bae818d2cfa066bc75c0b5a6eff078df3bc. --- tests/Util.html | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/Util.html b/tests/Util.html index 2357b54e2c..e137d0f7ce 100644 --- a/tests/Util.html +++ b/tests/Util.html @@ -1120,7 +1120,11 @@ t.eq(OpenLayers.Util.getFormattedLonLat(-181, "lon"), "179°00'00\"E", "crossing dateline from the west results in correct east coordinate"); t.eq(OpenLayers.Util.getFormattedLonLat(181, "lon"), "179°00'00\"W", "crossing dateline from the east results in correct west coordinate"); } - + + + +
+ - - -
+ From 161b54b6f168fc0aedb2d4c2bcaa5e1279f06b27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Sat, 3 Mar 2012 22:35:31 +0100 Subject: [PATCH 06/10] Revert "Fixing the extend method to work on IE." This reverts commit 71276b5323a5181bf9cdf90bb02ad07f2cebb1a0. --- lib/OpenLayers/BaseTypes/Class.js | 2 +- tests/Util.html | 26 +------------------------- 2 files changed, 2 insertions(+), 26 deletions(-) diff --git a/lib/OpenLayers/BaseTypes/Class.js b/lib/OpenLayers/BaseTypes/Class.js index 6f64d3f961..1e242f55bb 100644 --- a/lib/OpenLayers/BaseTypes/Class.js +++ b/lib/OpenLayers/BaseTypes/Class.js @@ -91,7 +91,7 @@ OpenLayers.Util.extend = function(destination, source) { destination = destination || {}; if (source) { for (var property in source) { - if (Object.prototype.hasOwnProperty.call(source, property)) { + if (source.hasOwnProperty(property)) { var value = source[property]; if (value !== undefined) { destination[property] = value; diff --git a/tests/Util.html b/tests/Util.html index e137d0f7ce..43db83c06d 100644 --- a/tests/Util.html +++ b/tests/Util.html @@ -1120,34 +1120,10 @@ t.eq(OpenLayers.Util.getFormattedLonLat(-181, "lon"), "179°00'00\"E", "crossing dateline from the west results in correct east coordinate"); t.eq(OpenLayers.Util.getFormattedLonLat(181, "lon"), "179°00'00\"W", "crossing dateline from the east results in correct west coordinate"); } +
- From 9a116b21b9317dd7210072c603e180caeed036c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Sat, 3 Mar 2012 22:35:39 +0100 Subject: [PATCH 07/10] Revert "protect for in loops with hasOwnProperty" This reverts commit e3cc96dbfb58ee873db457e74de7c7774a25bf45. --- lib/OpenLayers/BaseTypes/Class.js | 8 +- lib/OpenLayers/Control/GetFeature.js | 16 +--- lib/OpenLayers/Control/NavigationHistory.js | 54 ++++++-------- lib/OpenLayers/Control/SLDSelect.js | 13 +--- lib/OpenLayers/Control/WMSGetFeatureInfo.js | 10 +-- lib/OpenLayers/Format/GML/Base.js | 14 ++-- lib/OpenLayers/Format/GeoRSS.js | 20 +++-- lib/OpenLayers/Format/OSM.js | 70 ++++++++---------- lib/OpenLayers/Format/SLD/v1.js | 32 +++----- lib/OpenLayers/Format/SLD/v1_0_0_GeoServer.js | 10 +-- lib/OpenLayers/Format/SOSGetObservation.js | 8 +- lib/OpenLayers/Format/WFS.js | 38 +++++----- lib/OpenLayers/Format/WFST/v1.js | 22 +++--- lib/OpenLayers/Format/WMC/v1.js | 58 +++++++-------- lib/OpenLayers/Format/WMC/v1_1_0.js | 4 +- lib/OpenLayers/Format/WMTSCapabilities.js | 6 +- lib/OpenLayers/Format/XML.js | 16 ++-- lib/OpenLayers/Layer.js | 4 +- lib/OpenLayers/Layer/HTTPRequest.js | 6 +- lib/OpenLayers/Layer/MapGuide.js | 6 +- lib/OpenLayers/Layer/MapServer.js | 6 +- lib/OpenLayers/Layer/Vector.js | 8 +- lib/OpenLayers/Layer/WMTS.js | 6 +- lib/OpenLayers/Protocol/Script.js | 6 +- lib/OpenLayers/Request.js | 4 +- lib/OpenLayers/Rule.js | 20 ++--- lib/OpenLayers/Style.js | 32 ++++---- lib/OpenLayers/StyleMap.js | 52 ++++++------- lib/OpenLayers/Tile/Image/IFrame.js | 14 ++-- lib/OpenLayers/Tween.js | 16 ++-- lib/OpenLayers/Util.js | 74 ++++++++----------- 31 files changed, 267 insertions(+), 386 deletions(-) diff --git a/lib/OpenLayers/BaseTypes/Class.js b/lib/OpenLayers/BaseTypes/Class.js index 1e242f55bb..4a900b4198 100644 --- a/lib/OpenLayers/BaseTypes/Class.js +++ b/lib/OpenLayers/BaseTypes/Class.js @@ -91,11 +91,9 @@ OpenLayers.Util.extend = function(destination, source) { destination = destination || {}; if (source) { for (var property in source) { - if (source.hasOwnProperty(property)) { - var value = source[property]; - if (value !== undefined) { - destination[property] = value; - } + var value = source[property]; + if (value !== undefined) { + destination[property] = value; } } diff --git a/lib/OpenLayers/Control/GetFeature.js b/lib/OpenLayers/Control/GetFeature.js index 49760b03d3..c037f87d15 100644 --- a/lib/OpenLayers/Control/GetFeature.js +++ b/lib/OpenLayers/Control/GetFeature.js @@ -258,9 +258,7 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, { activate: function () { if (!this.active) { for(var i in this.handlers) { - if (this.handlers.hasOwnProperty(i)) { - this.handlers[i].activate(); - } + this.handlers[i].activate(); } } return OpenLayers.Control.prototype.activate.apply( @@ -278,9 +276,7 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, { deactivate: function () { if (this.active) { for(var i in this.handlers) { - if (this.handlers.hasOwnProperty(i)) { - this.handlers[i].deactivate(); - } + this.handlers[i].deactivate(); } } return OpenLayers.Control.prototype.deactivate.apply( @@ -564,9 +560,7 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, { unselectAll: function() { // we'll want an option to supress notification here for(var fid in this.features) { - if (this.features.hasOwnProperty(fid)) { - this.unselect(this.features[fid]); - } + this.unselect(this.features[fid]); } }, @@ -579,9 +573,7 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, { */ setMap: function(map) { for(var i in this.handlers) { - if (this.handlers.hasOwnProperty(i)) { - this.handlers[i].setMap(map); - } + this.handlers[i].setMap(map); } OpenLayers.Control.prototype.setMap.apply(this, arguments); }, diff --git a/lib/OpenLayers/Control/NavigationHistory.js b/lib/OpenLayers/Control/NavigationHistory.js index 4fe47a629e..eb46946e73 100644 --- a/lib/OpenLayers/Control/NavigationHistory.js +++ b/lib/OpenLayers/Control/NavigationHistory.js @@ -193,9 +193,7 @@ OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, { this.next.destroy(); this.deactivate(); for(var prop in this) { - if (this.hasOwnProperty(prop)) { - this[prop] = null; - } + this[prop] = null; } }, @@ -336,27 +334,25 @@ OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, { setListeners: function() { this.listeners = {}; for(var type in this.registry) { - if (this.registry.hasOwnProperty(type)) { - this.listeners[type] = OpenLayers.Function.bind(function() { - if(!this.restoring) { - var state = this.registry[type].apply(this, arguments); - this.previousStack.unshift(state); - if(this.previousStack.length > 1) { - this.onPreviousChange( - this.previousStack[1], this.previousStack.length - 1 - ); - } - if(this.previousStack.length > (this.limit + 1)) { - this.previousStack.pop(); - } - if(this.nextStack.length > 0) { - this.nextStack = []; - this.onNextChange(null, 0); - } + this.listeners[type] = OpenLayers.Function.bind(function() { + if(!this.restoring) { + var state = this.registry[type].apply(this, arguments); + this.previousStack.unshift(state); + if(this.previousStack.length > 1) { + this.onPreviousChange( + this.previousStack[1], this.previousStack.length - 1 + ); } - return true; - }, this); - } + if(this.previousStack.length > (this.limit + 1)) { + this.previousStack.pop(); + } + if(this.nextStack.length > 0) { + this.nextStack = []; + this.onNextChange(null, 0); + } + } + return true; + }, this); } }, @@ -375,9 +371,7 @@ OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, { this.setListeners(); } for(var type in this.listeners) { - if (this.listeners.hasOwnProperty(type)) { - this.map.events.register(type, this, this.listeners[type]); - } + this.map.events.register(type, this, this.listeners[type]); } activated = true; if(this.previousStack.length == 0) { @@ -411,11 +405,9 @@ OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, { if(this.map) { if(OpenLayers.Control.prototype.deactivate.apply(this)) { for(var type in this.listeners) { - if (this.listeners.hasOwnProperty(type)) { - this.map.events.unregister( - type, this, this.listeners[type] - ); - } + this.map.events.unregister( + type, this, this.listeners[type] + ); } if(this.clearOnDeactivate) { this.clear(); diff --git a/lib/OpenLayers/Control/SLDSelect.js b/lib/OpenLayers/Control/SLDSelect.js index 50ac906afd..52f0798ae9 100644 --- a/lib/OpenLayers/Control/SLDSelect.js +++ b/lib/OpenLayers/Control/SLDSelect.js @@ -168,16 +168,11 @@ OpenLayers.Control.SLDSelect = OpenLayers.Class(OpenLayers.Control, { * Take care of things that are not handled in superclass. */ destroy: function() { - var key; - for (key in this.layerCache) { - if (this.layerCache.hasOwnProperty(key)) { - delete this.layerCache[key]; - } + for (var key in this.layerCache) { + delete this.layerCache[key]; } - for (key in this.wfsCache) { - if (this.wfsCache.hasOwnProperty(key)) { - delete this.wfsCache[key]; - } + for (var key in this.wfsCache) { + delete this.wfsCache[key]; } OpenLayers.Control.prototype.destroy.apply(this, arguments); }, diff --git a/lib/OpenLayers/Control/WMSGetFeatureInfo.js b/lib/OpenLayers/Control/WMSGetFeatureInfo.js index 67555f1038..9348a9d542 100644 --- a/lib/OpenLayers/Control/WMSGetFeatureInfo.js +++ b/lib/OpenLayers/Control/WMSGetFeatureInfo.js @@ -456,12 +456,10 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, { } var layers; for (var url in services) { - if (services.hasOwnProperty(url)) { - layers = services[url]; - var wmsOptions = this.buildWMSOptions(url, layers, - clickPosition, layers[0].params.FORMAT); - OpenLayers.Request.GET(wmsOptions); - } + layers = services[url]; + var wmsOptions = this.buildWMSOptions(url, layers, + clickPosition, layers[0].params.FORMAT); + OpenLayers.Request.GET(wmsOptions); } } }, diff --git a/lib/OpenLayers/Format/GML/Base.js b/lib/OpenLayers/Format/GML/Base.js index 9abbf5aa7a..0eceadaed6 100644 --- a/lib/OpenLayers/Format/GML/Base.js +++ b/lib/OpenLayers/Format/GML/Base.js @@ -564,14 +564,12 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, { this.writeNode("feature:_geometry", feature.geometry, node); } for(var name in feature.attributes) { - if (feature.attributes.hasOwnProperty(name)) { - var value = feature.attributes[name]; - if(value != null) { - this.writeNode( - "feature:_attribute", - {name: name, value: value}, node - ); - } + var value = feature.attributes[name]; + if(value != null) { + this.writeNode( + "feature:_attribute", + {name: name, value: value}, node + ); } } return node; diff --git a/lib/OpenLayers/Format/GeoRSS.js b/lib/OpenLayers/Format/GeoRSS.js index 0fc1790f6d..a9e117b2ec 100644 --- a/lib/OpenLayers/Format/GeoRSS.js +++ b/lib/OpenLayers/Format/GeoRSS.js @@ -325,17 +325,15 @@ OpenLayers.Format.GeoRSS = OpenLayers.Class(OpenLayers.Format.XML, { featureNode.appendChild(linkNode); } for(var attr in feature.attributes) { - if (feature.attributes.hasOwnProperty(attr)) { - if (attr == "link" || attr == "title" || attr == "description") { continue; } - var attrText = this.createTextNode(feature.attributes[attr]); - var nodename = attr; - if (attr.search(":") != -1) { - nodename = attr.split(":")[1]; - } - var attrContainer = this.createElementNS(this.featureNS, "feature:"+nodename); - attrContainer.appendChild(attrText); - featureNode.appendChild(attrContainer); - } + if (attr == "link" || attr == "title" || attr == "description") { continue; } + var attrText = this.createTextNode(feature.attributes[attr]); + var nodename = attr; + if (attr.search(":") != -1) { + nodename = attr.split(":")[1]; + } + var attrContainer = this.createElementNS(this.featureNS, "feature:"+nodename); + attrContainer.appendChild(attrText); + featureNode.appendChild(attrContainer); } featureNode.appendChild(geometryNode); return featureNode; diff --git a/lib/OpenLayers/Format/OSM.js b/lib/OpenLayers/Format/OSM.js index a5de50fc35..48ef45ac91 100644 --- a/lib/OpenLayers/Format/OSM.js +++ b/lib/OpenLayers/Format/OSM.js @@ -140,35 +140,33 @@ OpenLayers.Format.OSM = OpenLayers.Class(OpenLayers.Format.XML, { feat_list[i] = feat; } for (var node_id in nodes) { - if (nodes.hasOwnProperty(node_id)) { - var node = nodes[node_id]; - if (!node.used || this.checkTags) { - var tags = null; + var node = nodes[node_id]; + if (!node.used || this.checkTags) { + var tags = null; - if (this.checkTags) { - var result = this.getTags(node.node, true); - if (node.used && !result[1]) { - continue; - } - tags = result[0]; - } else { - tags = this.getTags(node.node); - } + if (this.checkTags) { + var result = this.getTags(node.node, true); + if (node.used && !result[1]) { + continue; + } + tags = result[0]; + } else { + tags = this.getTags(node.node); + } - var feat = new OpenLayers.Feature.Vector( - new OpenLayers.Geometry.Point(node['lon'], node['lat']), - tags); - if (this.internalProjection && this.externalProjection) { - feat.geometry.transform(this.externalProjection, - this.internalProjection); - } - feat.osm_id = parseInt(node_id); - feat.fid = "node." + feat.osm_id; - feat_list.push(feat); - } - // Memory cleanup - node.node = null; - } + var feat = new OpenLayers.Feature.Vector( + new OpenLayers.Geometry.Point(node['lon'], node['lat']), + tags); + if (this.internalProjection && this.externalProjection) { + feat.geometry.transform(this.externalProjection, + this.internalProjection); + } + feat.osm_id = parseInt(node_id); + feat.fid = "node." + feat.osm_id; + feat_list.push(feat); + } + // Memory cleanup + node.node = null; } return feat_list; }, @@ -275,11 +273,9 @@ OpenLayers.Format.OSM = OpenLayers.Class(OpenLayers.Format.XML, { } if (this.checkTags) { for(var key in way.tags) { - if (way.tags.hasOwnProperty(key)) { - if (this.areaTags[key]) { - poly_tags = true; - break; - } + if (this.areaTags[key]) { + poly_tags = true; + break; } } } @@ -434,12 +430,10 @@ OpenLayers.Format.OSM = OpenLayers.Class(OpenLayers.Format.XML, { */ serializeTags: function(feature, node) { for (var key in feature.attributes) { - if (feature.attributes.hasOwnProperty(key)) { - var tag = this.createElementNS(null, "tag"); - tag.setAttribute("k", key); - tag.setAttribute("v", feature.attributes[key]); - node.appendChild(tag); - } + var tag = this.createElementNS(null, "tag"); + tag.setAttribute("k", key); + tag.setAttribute("v", feature.attributes[key]); + node.appendChild(tag); } }, diff --git a/lib/OpenLayers/Format/SLD/v1.js b/lib/OpenLayers/Format/SLD/v1.js index 2a1c2e33af..cd32810be9 100644 --- a/lib/OpenLayers/Format/SLD/v1.js +++ b/lib/OpenLayers/Format/SLD/v1.js @@ -541,11 +541,9 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, { getCssProperty: function(sym) { var css = null; for(var prop in this.cssMap) { - if (this.cssMap.hasOwnProperty(prop)) { - if(this.cssMap[prop] == sym) { - css = prop; - break; - } + if(this.cssMap[prop] == sym) { + css = prop; + break; } } return css; @@ -567,14 +565,12 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, { getGraphicFormat: function(href) { var format, regex; for(var key in this.graphicFormats) { - if (this.graphicFormats.hasOwnProperty(key)) { - if(this.graphicFormats[key].test(href)) { - format = key; - break; - } + if(this.graphicFormats[key].test(href)) { + format = key; + break; } } - return format || this.defaultGraphicFormat; + return format || this.defautlGraphicFormat; }, /** @@ -680,9 +676,7 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, { } } else { for(var name in sld.namedLayers) { - if (sld.namedLayers.hasOwnProperty(name)) { - this.writeNode("NamedLayer", sld.namedLayers[name], root); - } + this.writeNode("NamedLayer", sld.namedLayers[name], root); } } return root; @@ -775,13 +769,11 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, { ruleMap[zIndex].symbolizers.push(symbolizer.clone()); } for (zIndex in ruleMap) { - if (ruleMap.hasOwnProperty(zIndex)) { - if (!(zIndex in rulesByZ)) { - zValues.push(zIndex); - rulesByZ[zIndex] = []; - } - rulesByZ[zIndex].push(ruleMap[zIndex]); + if (!(zIndex in rulesByZ)) { + zValues.push(zIndex); + rulesByZ[zIndex] = []; } + rulesByZ[zIndex].push(ruleMap[zIndex]); } } else { // no symbolizers in rule diff --git a/lib/OpenLayers/Format/SLD/v1_0_0_GeoServer.js b/lib/OpenLayers/Format/SLD/v1_0_0_GeoServer.js index 784e42b592..bee661311b 100644 --- a/lib/OpenLayers/Format/SLD/v1_0_0_GeoServer.js +++ b/lib/OpenLayers/Format/SLD/v1_0_0_GeoServer.js @@ -128,12 +128,10 @@ OpenLayers.Format.SLD.v1_0_0_GeoServer = OpenLayers.Class( var options = symbolizer.vendorOptions; if (options) { for (var key in symbolizer.vendorOptions) { - if (symbolizer.vendorOptions.hasOwnProperty(key)) { - this.writeNode("VendorOption", { - name: key, - value: symbolizer.vendorOptions[key] - }, node); - } + this.writeNode("VendorOption", { + name: key, + value: symbolizer.vendorOptions[key] + }, node); } } return node; diff --git a/lib/OpenLayers/Format/SOSGetObservation.js b/lib/OpenLayers/Format/SOSGetObservation.js index feb1e35a49..a7f2c1725f 100644 --- a/lib/OpenLayers/Format/SOSGetObservation.js +++ b/lib/OpenLayers/Format/SOSGetObservation.js @@ -210,14 +210,10 @@ OpenLayers.Format.SOSGetObservation = OpenLayers.Class(OpenLayers.Format.XML, { this.writeNode("eventTime", options, node); } for (var procedure in options.procedures) { - if (options.procedures.hasOwnProperty(procedure)) { - this.writeNode("procedure", options.procedures[procedure], node); - } + this.writeNode("procedure", options.procedures[procedure], node); } for (var observedProperty in options.observedProperties) { - if (options.observedProperties.hasOwnProperty(observedProperty)) { - this.writeNode("observedProperty", options.observedProperties[observedProperty], node); - } + this.writeNode("observedProperty", options.observedProperties[observedProperty], node); } if (options.foi) { this.writeNode("featureOfInterest", options.foi, node); diff --git a/lib/OpenLayers/Format/WFS.js b/lib/OpenLayers/Format/WFS.js index 0d69566ad6..860df0aa5f 100644 --- a/lib/OpenLayers/Format/WFS.js +++ b/lib/OpenLayers/Format/WFS.js @@ -104,17 +104,15 @@ OpenLayers.Format.WFS = OpenLayers.Class(OpenLayers.Format.GML, { var featureContainer = this.createElementNS(this.featureNS, "feature:" + this.featureName); featureContainer.appendChild(geomContainer); for(var attr in feature.attributes) { - if (feature.attributes.hasOwnProperty(attr)) { - var attrText = this.createTextNode(feature.attributes[attr]); - var nodename = attr; - if (attr.search(":") != -1) { - nodename = attr.split(":")[1]; - } - var attrContainer = this.createElementNS(this.featureNS, "feature:" + nodename); - attrContainer.appendChild(attrText); - featureContainer.appendChild(attrContainer); - } - } + var attrText = this.createTextNode(feature.attributes[attr]); + var nodename = attr; + if (attr.search(":") != -1) { + nodename = attr.split(":")[1]; + } + var attrContainer = this.createElementNS(this.featureNS, "feature:" + nodename); + attrContainer.appendChild(attrText); + featureContainer.appendChild(attrContainer); + } return featureContainer; }, @@ -168,16 +166,14 @@ OpenLayers.Format.WFS = OpenLayers.Class(OpenLayers.Format.GML, { // add in attributes for(var propName in feature.attributes) { - if (feature.attributes.hasOwnProperty(propName)) { - propertyNode = this.createElementNS(this.wfsns, 'wfs:Property'); - nameNode = this.createElementNS(this.wfsns, 'wfs:Name'); - nameNode.appendChild(this.createTextNode(propName)); - propertyNode.appendChild(nameNode); - valueNode = this.createElementNS(this.wfsns, 'wfs:Value'); - valueNode.appendChild(this.createTextNode(feature.attributes[propName])); - propertyNode.appendChild(valueNode); - updateNode.appendChild(propertyNode); - } + propertyNode = this.createElementNS(this.wfsns, 'wfs:Property'); + nameNode = this.createElementNS(this.wfsns, 'wfs:Name'); + nameNode.appendChild(this.createTextNode(propName)); + propertyNode.appendChild(nameNode); + valueNode = this.createElementNS(this.wfsns, 'wfs:Value'); + valueNode.appendChild(this.createTextNode(feature.attributes[propName])); + propertyNode.appendChild(valueNode); + updateNode.appendChild(propertyNode); } diff --git a/lib/OpenLayers/Format/WFST/v1.js b/lib/OpenLayers/Format/WFST/v1.js index 5341fd17a7..e3bf963afc 100644 --- a/lib/OpenLayers/Format/WFST/v1.js +++ b/lib/OpenLayers/Format/WFST/v1.js @@ -332,14 +332,12 @@ OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, { // add in attributes for(var key in feature.attributes) { - if (feature.attributes.hasOwnProperty(key)) { - if(feature.attributes[key] !== undefined && - (!modified || !modified.attributes || - (modified.attributes && modified.attributes[key] !== undefined))) { - this.writeNode( - "Property", {name: key, value: feature.attributes[key]}, node - ); - } + if(feature.attributes[key] !== undefined && + (!modified || !modified.attributes || + (modified.attributes && modified.attributes[key] !== undefined))) { + this.writeNode( + "Property", {name: key, value: feature.attributes[key]}, node + ); } } @@ -412,11 +410,9 @@ OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, { var parts = []; var uri; for(var key in schemaLocations) { - if (schemaLocations.hasOwnProperty(key)) { - uri = this.namespaces[key]; - if(uri) { - parts.push(uri + " " + schemaLocations[key]); - } + uri = this.namespaces[key]; + if(uri) { + parts.push(uri + " " + schemaLocations[key]); } } var value = parts.join(" ") || undefined; diff --git a/lib/OpenLayers/Format/WMC/v1.js b/lib/OpenLayers/Format/WMC/v1.js index 46e1947cbc..e6eed09b44 100644 --- a/lib/OpenLayers/Format/WMC/v1.js +++ b/lib/OpenLayers/Format/WMC/v1.js @@ -48,10 +48,8 @@ OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, { prefix = this.namespaces[this.defaultPrefix]; } else { for(prefix in this.namespaces) { - if (this.namespaces.hasOwnProperty(prefix)) { - if(this.namespaces[prefix] == uri) { - break; - } + if(this.namespaces[prefix] == uri) { + break; } } } @@ -676,14 +674,12 @@ OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, { setAttributes: function(node, obj) { var value; for(var name in obj) { - if (obj.hasOwnProperty(name)) { - value = obj[name].toString(); - if(value.match(/[A-Z]/)) { - // safari lowercases attributes with setAttribute - this.setAttributeNS(node, null, name, value); - } else { - node.setAttribute(name, value); - } + value = obj[name].toString(); + if(value.match(/[A-Z]/)) { + // safari lowercases attributes with setAttribute + this.setAttributeNS(node, null, name, value); + } else { + node.setAttribute(name, value); } } }, @@ -1095,29 +1091,25 @@ OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, { userValue: true }; for (var dim in context.dimensions) { - if (context.dimensions.hasOwnProperty(dim)) { - var attributes = {}; - var dimension = context.dimensions[dim]; - for (var name in dimension) { - if (dimension.hasOwnProperty(name)) { - if (typeof dimension[name] == "boolean") { - attributes[name] = Number(dimension[name]); - } else { - attributes[name] = dimension[name]; - } - } - } - var values = ""; - if (attributes.values) { - values = attributes.values.join(","); - delete attributes.values; + var attributes = {}; + var dimension = context.dimensions[dim]; + for (var name in dimension) { + if (typeof dimension[name] == "boolean") { + attributes[name] = Number(dimension[name]); + } else { + attributes[name] = dimension[name]; } + } + var values = ""; + if (attributes.values) { + values = attributes.values.join(","); + delete attributes.values; + } - node.appendChild(this.createElementDefaultNS( - "Dimension", values, attributes - )); - } - } + node.appendChild(this.createElementDefaultNS( + "Dimension", values, attributes + )); + } return node; }, diff --git a/lib/OpenLayers/Format/WMC/v1_1_0.js b/lib/OpenLayers/Format/WMC/v1_1_0.js index ceed7f5fd2..16caf0ece4 100644 --- a/lib/OpenLayers/Format/WMC/v1_1_0.js +++ b/lib/OpenLayers/Format/WMC/v1_1_0.js @@ -122,9 +122,7 @@ OpenLayers.Format.WMC.v1_1_0 = OpenLayers.Class( // optional SRS element(s) if (context.srs) { for(var name in context.srs) { - if (context.srs.hasOwnProperty(name)) { - node.appendChild(this.createElementDefaultNS("SRS", name)); - } + node.appendChild(this.createElementDefaultNS("SRS", name)); } } diff --git a/lib/OpenLayers/Format/WMTSCapabilities.js b/lib/OpenLayers/Format/WMTSCapabilities.js index b142072092..d69e944c5f 100644 --- a/lib/OpenLayers/Format/WMTSCapabilities.js +++ b/lib/OpenLayers/Format/WMTSCapabilities.js @@ -84,10 +84,8 @@ OpenLayers.Format.WMTSCapabilities = OpenLayers.Class(OpenLayers.Format.XML.Vers matrixSet: true }; for (var prop in required) { - if (required.hasOwnProperty(prop)) { - if (!(prop in config)) { - throw new Error("Missing property '" + prop + "' in layer configuration."); - } + if (!(prop in config)) { + throw new Error("Missing property '" + prop + "' in layer configuration."); } } diff --git a/lib/OpenLayers/Format/XML.js b/lib/OpenLayers/Format/XML.js index 3d8be16ed5..e5cc118891 100644 --- a/lib/OpenLayers/Format/XML.js +++ b/lib/OpenLayers/Format/XML.js @@ -89,9 +89,7 @@ OpenLayers.Format.XML = OpenLayers.Class(OpenLayers.Format, { this.namespaces = OpenLayers.Util.extend({}, this.namespaces); this.namespaceAlias = {}; for(var alias in this.namespaces) { - if (this.namespaces.hasOwnProperty(alias)) { - this.namespaceAlias[this.namespaces[alias]] = alias; - } + this.namespaceAlias[this.namespaces[alias]] = alias; } }, @@ -560,13 +558,11 @@ OpenLayers.Format.XML = OpenLayers.Class(OpenLayers.Format, { setAttributes: function(node, obj) { var value, uri; for(var name in obj) { - if (obj.hasOwnProperty(name)) { - if(obj[name] != null && obj[name].toString) { - value = obj[name].toString(); - // check for qualified attribute name ("prefix:local") - uri = this.namespaces[name.substring(0, name.indexOf(":"))] || null; - this.setAttributeNS(node, uri, name, value); - } + if(obj[name] != null && obj[name].toString) { + value = obj[name].toString(); + // check for qualified attribute name ("prefix:local") + uri = this.namespaces[name.substring(0, name.indexOf(":"))] || null; + this.setAttributeNS(node, uri, name, value); } } }, diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index 76f6b5d6b7..788b6e7633 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -423,9 +423,7 @@ OpenLayers.Layer = OpenLayers.Class({ getOptions: function() { var options = {}; for(var o in this.options) { - if (this.options.hasOwnProperty(o)) { - options[o] = this[o]; - } + options[o] = this[o]; } return options; }, diff --git a/lib/OpenLayers/Layer/HTTPRequest.js b/lib/OpenLayers/Layer/HTTPRequest.js index 6cbc83dc3d..d1e9bf2219 100644 --- a/lib/OpenLayers/Layer/HTTPRequest.js +++ b/lib/OpenLayers/Layer/HTTPRequest.js @@ -218,10 +218,8 @@ OpenLayers.Layer.HTTPRequest = OpenLayers.Class(OpenLayers.Layer, { var urlParams = OpenLayers.Util.upperCaseObject(OpenLayers.Util.getParameters(url)); for(var key in allParams) { - if (allParams.hasOwnProperty(key)) { - if(key.toUpperCase() in urlParams) { - delete allParams[key]; - } + if(key.toUpperCase() in urlParams) { + delete allParams[key]; } } paramsString = OpenLayers.Util.getParameterString(allParams); diff --git a/lib/OpenLayers/Layer/MapGuide.js b/lib/OpenLayers/Layer/MapGuide.js index 4285fd6094..680b8472c2 100644 --- a/lib/OpenLayers/Layer/MapGuide.js +++ b/lib/OpenLayers/Layer/MapGuide.js @@ -346,10 +346,8 @@ OpenLayers.Layer.MapGuide = OpenLayers.Class(OpenLayers.Layer.Grid, { var urlParams = OpenLayers.Util.upperCaseObject( OpenLayers.Util.getParameters(url)); for(var key in allParams) { - if (allParams.hasOwnProperty(key)) { - if(key.toUpperCase() in urlParams) { - delete allParams[key]; - } + if(key.toUpperCase() in urlParams) { + delete allParams[key]; } } var paramsString = OpenLayers.Util.getParameterString(allParams); diff --git a/lib/OpenLayers/Layer/MapServer.js b/lib/OpenLayers/Layer/MapServer.js index 2151961713..61e9930ab9 100644 --- a/lib/OpenLayers/Layer/MapServer.js +++ b/lib/OpenLayers/Layer/MapServer.js @@ -142,10 +142,8 @@ OpenLayers.Layer.MapServer = OpenLayers.Class(OpenLayers.Layer.Grid, { var urlParams = OpenLayers.Util.upperCaseObject( OpenLayers.Util.getParameters(url)); for(var key in allParams) { - if (allParams.hasOwnProperty(key)) { - if(key.toUpperCase() in urlParams) { - delete allParams[key]; - } + if(key.toUpperCase() in urlParams) { + delete allParams[key]; } } paramsString = OpenLayers.Util.getParameterString(allParams); diff --git a/lib/OpenLayers/Layer/Vector.js b/lib/OpenLayers/Layer/Vector.js index 0e771b0017..2857a82d7b 100644 --- a/lib/OpenLayers/Layer/Vector.js +++ b/lib/OpenLayers/Layer/Vector.js @@ -509,10 +509,8 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, { if(!zoomChanged && coordSysUnchanged) { for(var i in this.unrenderedFeatures) { - if (this.unrenderedFeatures.hasOwnProperty(i)) { - var feature = this.unrenderedFeatures[i]; - this.drawFeature(feature); - } + var feature = this.unrenderedFeatures[i]; + this.drawFeature(feature); } } } @@ -1025,4 +1023,4 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, { }, CLASS_NAME: "OpenLayers.Layer.Vector" -}); +}); \ No newline at end of file diff --git a/lib/OpenLayers/Layer/WMTS.js b/lib/OpenLayers/Layer/WMTS.js index 8673502f6f..c82beb4d18 100644 --- a/lib/OpenLayers/Layer/WMTS.js +++ b/lib/OpenLayers/Layer/WMTS.js @@ -229,10 +229,8 @@ OpenLayers.Layer.WMTS = OpenLayers.Class(OpenLayers.Layer.Grid, { matrixSet: true }; for (var prop in required) { - if (required.hasOwnProperty(prop)) { - if (!(prop in config)) { - throw new Error("Missing property '" + prop + "' in layer configuration."); - } + if (!(prop in config)) { + throw new Error("Missing property '" + prop + "' in layer configuration."); } } diff --git a/lib/OpenLayers/Protocol/Script.js b/lib/OpenLayers/Protocol/Script.js index a92a0c9360..49e332b7f0 100644 --- a/lib/OpenLayers/Protocol/Script.js +++ b/lib/OpenLayers/Protocol/Script.js @@ -135,7 +135,7 @@ OpenLayers.Protocol.Script = OpenLayers.Class(OpenLayers.Protocol, { }); this.filterToParams = function(filter, params) { return format.write(filter, params); - }; + } } }, @@ -311,9 +311,7 @@ OpenLayers.Protocol.Script = OpenLayers.Class(OpenLayers.Protocol, { this.destroyRequest(response.priv); } else { for (var key in this.pendingRequests) { - if (this.pendingRequests.hasOwnProperty(key)) { - this.destroyRequest(this.pendingRequests[key]); - } + this.destroyRequest(this.pendingRequests[key]); } } }, diff --git a/lib/OpenLayers/Request.js b/lib/OpenLayers/Request.js index f1f51467a2..a5de46fdee 100644 --- a/lib/OpenLayers/Request.js +++ b/lib/OpenLayers/Request.js @@ -181,9 +181,7 @@ OpenLayers.Request = { config.method, url, config.async, config.user, config.password ); for(var header in config.headers) { - if (config.headers.hasOwnProperty(header)) { - request.setRequestHeader(header, config.headers[header]); - } + request.setRequestHeader(header, config.headers[header]); } var events = this.events; diff --git a/lib/OpenLayers/Rule.js b/lib/OpenLayers/Rule.js index 0f7db50ae2..452b3de25f 100644 --- a/lib/OpenLayers/Rule.js +++ b/lib/OpenLayers/Rule.js @@ -128,9 +128,7 @@ OpenLayers.Rule = OpenLayers.Class({ */ destroy: function() { for (var i in this.symbolizer) { - if (this.symbolizer.hasOwnProperty(i)) { - this.symbolizer[i] = null; - } + this.symbolizer[i] = null; } this.symbolizer = null; delete this.symbolizers; @@ -218,14 +216,12 @@ OpenLayers.Rule = OpenLayers.Class({ options.symbolizer = {}; var value, type; for(var key in this.symbolizer) { - if (this.symbolizer.hasOwnProperty(key)) { - value = this.symbolizer[key]; - type = typeof value; - if(type === "object") { - options.symbolizer[key] = OpenLayers.Util.extend({}, value); - } else if(type === "string") { - options.symbolizer[key] = value; - } + value = this.symbolizer[key]; + type = typeof value; + if(type === "object") { + options.symbolizer[key] = OpenLayers.Util.extend({}, value); + } else if(type === "string") { + options.symbolizer[key] = value; } } } @@ -237,4 +233,4 @@ OpenLayers.Rule = OpenLayers.Class({ }, CLASS_NAME: "OpenLayers.Rule" -}); +}); \ No newline at end of file diff --git a/lib/OpenLayers/Style.js b/lib/OpenLayers/Style.js index 891af83181..1af88dfba2 100644 --- a/lib/OpenLayers/Style.js +++ b/lib/OpenLayers/Style.js @@ -273,9 +273,7 @@ OpenLayers.Style = OpenLayers.Class({ OpenLayers.Util.extend(context, this.context); for (var i in this.propertyStyles) { - if (this.propertyStyles.hasOwnProperty(i)) { - style[i] = OpenLayers.Style.createLiteral(style[i], context, feature, i); - } + style[i] = OpenLayers.Style.createLiteral(style[i], context, feature, i); } return style; }, @@ -303,16 +301,14 @@ OpenLayers.Style = OpenLayers.Class({ for (var i=0, len=rules.length; i Date: Sat, 3 Mar 2012 14:42:43 -0700 Subject: [PATCH 08/10] Making it safe to destroy a permalink. Previously, a map could not be destroyed if it included a permalink control without an "element". In addition, a permalink control could not be destroyed if it didn't have a reference to a map. --- lib/OpenLayers/Control/Permalink.js | 9 +++++---- tests/Control/Permalink.html | 23 +++++++++++++++++++++-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/lib/OpenLayers/Control/Permalink.js b/lib/OpenLayers/Control/Permalink.js index 5686f1f8b6..4a2112c552 100644 --- a/lib/OpenLayers/Control/Permalink.js +++ b/lib/OpenLayers/Control/Permalink.js @@ -94,12 +94,13 @@ OpenLayers.Control.Permalink = OpenLayers.Class(OpenLayers.Control, { * APIMethod: destroy */ destroy: function() { - if (this.element.parentNode == this.div) { + if (this.element && this.element.parentNode == this.div) { this.div.removeChild(this.element); + this.element = null; + } + if (this.map) { + this.map.events.unregister('moveend', this, this.updateLink); } - this.element = null; - - this.map.events.unregister('moveend', this, this.updateLink); OpenLayers.Control.prototype.destroy.apply(this, arguments); }, diff --git a/tests/Control/Permalink.html b/tests/Control/Permalink.html index 3260eaf24f..b398adf148 100644 --- a/tests/Control/Permalink.html +++ b/tests/Control/Permalink.html @@ -11,6 +11,7 @@ t.eq(control.displayClass, "olControlPermalink", "displayClass is correct"); t.eq(control.base, document.location.href, "base is correct"); t.ok(!control.anchor, "anchor is correct"); + control.destroy(); control = new OpenLayers.Control.Permalink('permalink', 'test.html'); t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object"); @@ -18,6 +19,7 @@ t.eq(control.base, 'test.html', "base is correct"); t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object"); t.ok(!control.anchor, "anchor is correct"); + control.destroy(); control = new OpenLayers.Control.Permalink('permalink'); t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object"); @@ -25,6 +27,7 @@ t.eq(control.base, document.location.href, "base is correct"); t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object"); t.ok(!control.anchor, "anchor is correct"); + control.destroy(); control = new OpenLayers.Control.Permalink(OpenLayers.Util.getElement('permalink')); t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object"); @@ -32,6 +35,7 @@ t.eq(control.base, document.location.href, "base is correct"); t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object"); t.ok(!control.anchor, "anchor is correct"); + control.destroy(); control = new OpenLayers.Control.Permalink({anchor: true}); t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object"); @@ -39,18 +43,21 @@ t.eq(control.base, document.location.href, "base is correct"); t.ok(control.element == null, "element is null"); t.ok(control.anchor, "anchor is correct"); + control.destroy(); control = new OpenLayers.Control.Permalink({anchor: false}); t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object"); t.eq(control.displayClass, "olControlPermalink", "displayClass is correct"); t.eq(control.base, document.location.href, "base is correct"); t.ok(!control.anchor, "anchor is correct"); + control.destroy(); control = new OpenLayers.Control.Permalink({}); t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object"); t.eq(control.displayClass, "olControlPermalink", "displayClass is correct"); t.eq(control.base, document.location.href, "base is correct"); t.ok(!control.anchor, "anchor is correct"); + control.destroy(); control = new OpenLayers.Control.Permalink({element: 'permalink', base: 'test.html'}); t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object"); @@ -58,6 +65,7 @@ t.eq(control.base, 'test.html', "base is correct"); t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object"); t.ok(!control.anchor, "anchor is correct"); + control.destroy(); control = new OpenLayers.Control.Permalink({element: 'permalink', base: 'test.html', anchor: true}); t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object"); @@ -65,6 +73,7 @@ t.eq(control.base, 'test.html', "base is correct"); t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object"); t.ok(control.anchor, "anchor is correct"); + control.destroy(); } function test_Control_Permalink_uncentered (t) { t.plan( 1 ); @@ -74,12 +83,14 @@ map.addControl(control); map.events.triggerEvent("changelayer", {}); t.ok(true, "permalink didn't bomb out."); + map.destroy(); } function test_Control_Permalink_initwithelem (t) { t.plan( 1 ); control = new OpenLayers.Control.Permalink(OpenLayers.Util.getElement('permalink')); t.ok(true, "If the above line doesn't throw an error, we're safe."); + control.destroy(); } function test_Control_Permalink_updateLinks (t) { t.plan( 3 ); @@ -100,6 +111,7 @@ map.layers[1].setVisibility(false); t.ok(OpenLayers.Util.isEquivalentUrl(OpenLayers.Util.getElement('permalink').href, location+"?zoom=2&lat=0&lon=1.75781&layers=BF"), 'setVisibility sets permalink'); + map.destroy(); } function test_Control_Permalink_updateLinksBase (t) { t.plan( 2 ); @@ -114,6 +126,7 @@ map.pan(5, 0, {animate:false}); OpenLayers.Util.getElement('edit_permalink').href = './edit.html?zoom=2&lat=0&lon=1.75781&layers=B'; t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base"); + map.destroy(); } function test_Control_Permalink_noElement (t) { t.plan( 2 ); @@ -122,6 +135,7 @@ map = new OpenLayers.Map('map'); map.addControl(control); t.eq(map.controls[4].div.firstChild.nodeName, "A", "Permalink control creates div with 'a' inside." ); + map.destroy(); } function test_Control_Permalink_base_with_query (t) { t.plan( 3 ); @@ -147,6 +161,7 @@ map.pan(5, 0, {animate:false}); map.pan(-5, 0, {animate:false}); t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and querystring ending with '?'"); + map.destroy(); } @@ -163,6 +178,7 @@ map.pan(5, 0, {animate:false}); OpenLayers.Util.getElement('edit_permalink').href = './edit.html?zoom=2&lat=0&lon=1.75781&layers=B'; t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with existing zoom in base"); + map.destroy(); } function test_Control_Permalink_customized(t) { @@ -189,6 +205,7 @@ t.eq(this.map.controls[this.map.controls.length-1].CLASS_NAME, "CustomArgParser", "Custom ArgParser added correctly."); t.eq(control.div.firstChild.getAttribute("href"), "./edit.html?zoom=2&lat=0&lon=1.75781&layers=B&customParam=foo", "Custom parameter encoded correctly."); + map.destroy(); } function test_Control_Permalink_createParams(t) { @@ -300,6 +317,7 @@ map.layers[1].setVisibility(false); t.ok(OpenLayers.Util.isEquivalentUrl(OpenLayers.Util.getParameterString(control.createParams()), "zoom=2&lat=0&lon=1.75781&layers=BF"), 'setVisibility sets permalink'); + map.destroy(); } function test_Control_Permalink_AnchorBaseElement (t) { @@ -320,6 +338,7 @@ map.layers[1].setVisibility(false); t.ok(OpenLayers.Util.isEquivalentUrl(OpenLayers.Util.getElement('permalink').href, location+"#zoom=2&lat=0&lon=1.75781&layers=BF"), 'setVisibility sets permalink'); + map.destroy(); } function test_center_from_map(t) { @@ -359,7 +378,7 @@ t.eq(params.lat, "2", "url y"); t.eq(params.zoom, "3", "url z"); - // map.destroy(); + map.destroy(); window.location.hash = previous; } @@ -389,7 +408,7 @@ t.eq(params.lat, "5", "y set"); t.eq(params.zoom, "6", "z set"); - // map.destroy(); + map.destroy(); window.location.hash = previous; } From d6f80955355d529a1727dd6e4d5bacef0978234d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Sat, 3 Mar 2012 23:42:09 +0100 Subject: [PATCH 09/10] add @tschaub's test_extend_event back --- tests/Util.html | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/Util.html b/tests/Util.html index 43db83c06d..2357b54e2c 100644 --- a/tests/Util.html +++ b/tests/Util.html @@ -1120,7 +1120,31 @@ t.eq(OpenLayers.Util.getFormattedLonLat(-181, "lon"), "179°00'00\"E", "crossing dateline from the west results in correct east coordinate"); t.eq(OpenLayers.Util.getFormattedLonLat(181, "lon"), "179°00'00\"W", "crossing dateline from the east results in correct west coordinate"); } - + + /** + * To test that we can safely call OpenLayers.Util.extend with an Event + * instance, we need to capture a real event. + */ + var loadEvent; + window.onload = function(evt) { + loadEvent = evt || window.event; + } + function test_extend_event(t) { + t.plan(2); + t.ok(loadEvent, "loadEvent recorded"); + var extended, err; + try { + extended = OpenLayers.Util.extend({foo: "bar"}, loadEvent); + } catch (e) { + err = e; + } + if (err) { + t.fail("Failed to extend with an event: " + err.message); + } else { + t.eq(extended && extended.foo, "bar", "extended with event"); + } + } + From e576eba862b6b3a90bd2685d2f34302db7ea040b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Sat, 3 Mar 2012 23:57:02 +0100 Subject: [PATCH 10/10] add missing statement-ending semi-colon, refs #272 --- lib/OpenLayers/Protocol/Script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OpenLayers/Protocol/Script.js b/lib/OpenLayers/Protocol/Script.js index 49e332b7f0..b298845586 100644 --- a/lib/OpenLayers/Protocol/Script.js +++ b/lib/OpenLayers/Protocol/Script.js @@ -135,7 +135,7 @@ OpenLayers.Protocol.Script = OpenLayers.Class(OpenLayers.Protocol, { }); this.filterToParams = function(filter, params) { return format.write(filter, params); - } + }; } },