Merge branch 'master' of github.com:openlayers/openlayers

This commit is contained in:
ahocevar
2012-03-04 11:25:10 +01:00
36 changed files with 350 additions and 400 deletions
-2
View File
@@ -91,13 +91,11 @@ OpenLayers.Util.extend = function(destination, source) {
destination = destination || {}; destination = destination || {};
if (source) { if (source) {
for (var property in source) { for (var property in source) {
if (Object.prototype.hasOwnProperty.call(source, property)) {
var value = source[property]; var value = source[property];
if (value !== undefined) { if (value !== undefined) {
destination[property] = value; destination[property] = value;
} }
} }
}
/** /**
* IE doesn't include the toString property when iterating over an object's * IE doesn't include the toString property when iterating over an object's
-8
View File
@@ -258,11 +258,9 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, {
activate: function () { activate: function () {
if (!this.active) { if (!this.active) {
for(var i in this.handlers) { 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( return OpenLayers.Control.prototype.activate.apply(
this, arguments this, arguments
); );
@@ -278,11 +276,9 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, {
deactivate: function () { deactivate: function () {
if (this.active) { if (this.active) {
for(var i in this.handlers) { 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( return OpenLayers.Control.prototype.deactivate.apply(
this, arguments this, arguments
); );
@@ -564,10 +560,8 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, {
unselectAll: function() { unselectAll: function() {
// we'll want an option to supress notification here // we'll want an option to supress notification here
for(var fid in this.features) { for(var fid in this.features) {
if (this.features.hasOwnProperty(fid)) {
this.unselect(this.features[fid]); this.unselect(this.features[fid]);
} }
}
}, },
/** /**
@@ -579,10 +573,8 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, {
*/ */
setMap: function(map) { setMap: function(map) {
for(var i in this.handlers) { 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); OpenLayers.Control.prototype.setMap.apply(this, arguments);
}, },
+2 -2
View File
@@ -231,8 +231,8 @@ OpenLayers.Control.Measure = OpenLayers.Class(OpenLayers.Control, {
* mouseposition. feature - {<OpenLayers.Feature.Vector>} The sketch feature. * mouseposition. feature - {<OpenLayers.Feature.Vector>} The sketch feature.
*/ */
measureImmediate : function(point, feature, drawing) { measureImmediate : function(point, feature, drawing) {
if (drawing && this.delayedTrigger === null && if (drawing && !this.handler.freehandMode(this.handler.evt)) {
!this.handler.freehandMode(this.handler.evt)) { this.cancelDelay();
this.measure(feature.geometry, "measurepartial"); this.measure(feature.geometry, "measurepartial");
} }
}, },
@@ -193,10 +193,8 @@ OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, {
this.next.destroy(); this.next.destroy();
this.deactivate(); this.deactivate();
for(var prop in this) { for(var prop in this) {
if (this.hasOwnProperty(prop)) {
this[prop] = null; this[prop] = null;
} }
}
}, },
/** /**
@@ -336,7 +334,6 @@ OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, {
setListeners: function() { setListeners: function() {
this.listeners = {}; this.listeners = {};
for(var type in this.registry) { for(var type in this.registry) {
if (this.registry.hasOwnProperty(type)) {
this.listeners[type] = OpenLayers.Function.bind(function() { this.listeners[type] = OpenLayers.Function.bind(function() {
if(!this.restoring) { if(!this.restoring) {
var state = this.registry[type].apply(this, arguments); var state = this.registry[type].apply(this, arguments);
@@ -357,7 +354,6 @@ OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, {
return true; return true;
}, this); }, this);
} }
}
}, },
/** /**
@@ -375,10 +371,8 @@ OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, {
this.setListeners(); this.setListeners();
} }
for(var type in this.listeners) { 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; activated = true;
if(this.previousStack.length == 0) { if(this.previousStack.length == 0) {
this.initStack(); this.initStack();
@@ -411,12 +405,10 @@ OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, {
if(this.map) { if(this.map) {
if(OpenLayers.Control.prototype.deactivate.apply(this)) { if(OpenLayers.Control.prototype.deactivate.apply(this)) {
for(var type in this.listeners) { for(var type in this.listeners) {
if (this.listeners.hasOwnProperty(type)) {
this.map.events.unregister( this.map.events.unregister(
type, this, this.listeners[type] type, this, this.listeners[type]
); );
} }
}
if(this.clearOnDeactivate) { if(this.clearOnDeactivate) {
this.clear(); this.clear();
} }
+4 -3
View File
@@ -94,12 +94,13 @@ OpenLayers.Control.Permalink = OpenLayers.Class(OpenLayers.Control, {
* APIMethod: destroy * APIMethod: destroy
*/ */
destroy: function() { destroy: function() {
if (this.element.parentNode == this.div) { if (this.element && this.element.parentNode == this.div) {
this.div.removeChild(this.element); this.div.removeChild(this.element);
}
this.element = null; this.element = null;
}
if (this.map) {
this.map.events.unregister('moveend', this, this.updateLink); this.map.events.unregister('moveend', this, this.updateLink);
}
OpenLayers.Control.prototype.destroy.apply(this, arguments); OpenLayers.Control.prototype.destroy.apply(this, arguments);
}, },
+2 -7
View File
@@ -168,17 +168,12 @@ OpenLayers.Control.SLDSelect = OpenLayers.Class(OpenLayers.Control, {
* Take care of things that are not handled in superclass. * Take care of things that are not handled in superclass.
*/ */
destroy: function() { destroy: function() {
var key; for (var key in this.layerCache) {
for (key in this.layerCache) {
if (this.layerCache.hasOwnProperty(key)) {
delete this.layerCache[key]; delete this.layerCache[key];
} }
} for (var key in this.wfsCache) {
for (key in this.wfsCache) {
if (this.wfsCache.hasOwnProperty(key)) {
delete this.wfsCache[key]; delete this.wfsCache[key];
} }
}
OpenLayers.Control.prototype.destroy.apply(this, arguments); OpenLayers.Control.prototype.destroy.apply(this, arguments);
}, },
@@ -456,14 +456,12 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
} }
var layers; var layers;
for (var url in services) { for (var url in services) {
if (services.hasOwnProperty(url)) {
layers = services[url]; layers = services[url];
var wmsOptions = this.buildWMSOptions(url, layers, var wmsOptions = this.buildWMSOptions(url, layers,
clickPosition, layers[0].params.FORMAT); clickPosition, layers[0].params.FORMAT);
OpenLayers.Request.GET(wmsOptions); OpenLayers.Request.GET(wmsOptions);
} }
} }
}
}, },
/** /**
-2
View File
@@ -564,7 +564,6 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
this.writeNode("feature:_geometry", feature.geometry, node); this.writeNode("feature:_geometry", feature.geometry, node);
} }
for(var name in feature.attributes) { for(var name in feature.attributes) {
if (feature.attributes.hasOwnProperty(name)) {
var value = feature.attributes[name]; var value = feature.attributes[name];
if(value != null) { if(value != null) {
this.writeNode( this.writeNode(
@@ -573,7 +572,6 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
); );
} }
} }
}
return node; return node;
}, },
"_geometry": function(geometry) { "_geometry": function(geometry) {
-2
View File
@@ -325,7 +325,6 @@ OpenLayers.Format.GeoRSS = OpenLayers.Class(OpenLayers.Format.XML, {
featureNode.appendChild(linkNode); featureNode.appendChild(linkNode);
} }
for(var attr in feature.attributes) { for(var attr in feature.attributes) {
if (feature.attributes.hasOwnProperty(attr)) {
if (attr == "link" || attr == "title" || attr == "description") { continue; } if (attr == "link" || attr == "title" || attr == "description") { continue; }
var attrText = this.createTextNode(feature.attributes[attr]); var attrText = this.createTextNode(feature.attributes[attr]);
var nodename = attr; var nodename = attr;
@@ -336,7 +335,6 @@ OpenLayers.Format.GeoRSS = OpenLayers.Class(OpenLayers.Format.XML, {
attrContainer.appendChild(attrText); attrContainer.appendChild(attrText);
featureNode.appendChild(attrContainer); featureNode.appendChild(attrContainer);
} }
}
featureNode.appendChild(geometryNode); featureNode.appendChild(geometryNode);
return featureNode; return featureNode;
}, },
-6
View File
@@ -140,7 +140,6 @@ OpenLayers.Format.OSM = OpenLayers.Class(OpenLayers.Format.XML, {
feat_list[i] = feat; feat_list[i] = feat;
} }
for (var node_id in nodes) { for (var node_id in nodes) {
if (nodes.hasOwnProperty(node_id)) {
var node = nodes[node_id]; var node = nodes[node_id];
if (!node.used || this.checkTags) { if (!node.used || this.checkTags) {
var tags = null; var tags = null;
@@ -169,7 +168,6 @@ OpenLayers.Format.OSM = OpenLayers.Class(OpenLayers.Format.XML, {
// Memory cleanup // Memory cleanup
node.node = null; node.node = null;
} }
}
return feat_list; return feat_list;
}, },
@@ -275,14 +273,12 @@ OpenLayers.Format.OSM = OpenLayers.Class(OpenLayers.Format.XML, {
} }
if (this.checkTags) { if (this.checkTags) {
for(var key in way.tags) { for(var key in way.tags) {
if (way.tags.hasOwnProperty(key)) {
if (this.areaTags[key]) { if (this.areaTags[key]) {
poly_tags = true; poly_tags = true;
break; break;
} }
} }
} }
}
return poly_shaped && (this.checkTags ? poly_tags : true); return poly_shaped && (this.checkTags ? poly_tags : true);
}, },
@@ -434,13 +430,11 @@ OpenLayers.Format.OSM = OpenLayers.Class(OpenLayers.Format.XML, {
*/ */
serializeTags: function(feature, node) { serializeTags: function(feature, node) {
for (var key in feature.attributes) { for (var key in feature.attributes) {
if (feature.attributes.hasOwnProperty(key)) {
var tag = this.createElementNS(null, "tag"); var tag = this.createElementNS(null, "tag");
tag.setAttribute("k", key); tag.setAttribute("k", key);
tag.setAttribute("v", feature.attributes[key]); tag.setAttribute("v", feature.attributes[key]);
node.appendChild(tag); node.appendChild(tag);
} }
}
}, },
/** /**
+1 -9
View File
@@ -541,13 +541,11 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
getCssProperty: function(sym) { getCssProperty: function(sym) {
var css = null; var css = null;
for(var prop in this.cssMap) { for(var prop in this.cssMap) {
if (this.cssMap.hasOwnProperty(prop)) {
if(this.cssMap[prop] == sym) { if(this.cssMap[prop] == sym) {
css = prop; css = prop;
break; break;
} }
} }
}
return css; return css;
}, },
@@ -567,14 +565,12 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
getGraphicFormat: function(href) { getGraphicFormat: function(href) {
var format, regex; var format, regex;
for(var key in this.graphicFormats) { for(var key in this.graphicFormats) {
if (this.graphicFormats.hasOwnProperty(key)) {
if(this.graphicFormats[key].test(href)) { if(this.graphicFormats[key].test(href)) {
format = key; format = key;
break; break;
} }
} }
} return format || this.defautlGraphicFormat;
return format || this.defaultGraphicFormat;
}, },
/** /**
@@ -680,11 +676,9 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
} }
} else { } else {
for(var name in sld.namedLayers) { 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; return root;
}, },
"Name": function(name) { "Name": function(name) {
@@ -775,14 +769,12 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
ruleMap[zIndex].symbolizers.push(symbolizer.clone()); ruleMap[zIndex].symbolizers.push(symbolizer.clone());
} }
for (zIndex in ruleMap) { for (zIndex in ruleMap) {
if (ruleMap.hasOwnProperty(zIndex)) {
if (!(zIndex in rulesByZ)) { if (!(zIndex in rulesByZ)) {
zValues.push(zIndex); zValues.push(zIndex);
rulesByZ[zIndex] = []; rulesByZ[zIndex] = [];
} }
rulesByZ[zIndex].push(ruleMap[zIndex]); rulesByZ[zIndex].push(ruleMap[zIndex]);
} }
}
} else { } else {
// no symbolizers in rule // no symbolizers in rule
rulesByZ[0].push(rule.clone()); rulesByZ[0].push(rule.clone());
@@ -128,14 +128,12 @@ OpenLayers.Format.SLD.v1_0_0_GeoServer = OpenLayers.Class(
var options = symbolizer.vendorOptions; var options = symbolizer.vendorOptions;
if (options) { if (options) {
for (var key in symbolizer.vendorOptions) { for (var key in symbolizer.vendorOptions) {
if (symbolizer.vendorOptions.hasOwnProperty(key)) {
this.writeNode("VendorOption", { this.writeNode("VendorOption", {
name: key, name: key,
value: symbolizer.vendorOptions[key] value: symbolizer.vendorOptions[key]
}, node); }, node);
} }
} }
}
return node; return node;
}, },
@@ -210,15 +210,11 @@ OpenLayers.Format.SOSGetObservation = OpenLayers.Class(OpenLayers.Format.XML, {
this.writeNode("eventTime", options, node); this.writeNode("eventTime", options, node);
} }
for (var procedure in options.procedures) { 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) { 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) { if (options.foi) {
this.writeNode("featureOfInterest", options.foi, node); this.writeNode("featureOfInterest", options.foi, node);
} }
-4
View File
@@ -104,7 +104,6 @@ OpenLayers.Format.WFS = OpenLayers.Class(OpenLayers.Format.GML, {
var featureContainer = this.createElementNS(this.featureNS, "feature:" + this.featureName); var featureContainer = this.createElementNS(this.featureNS, "feature:" + this.featureName);
featureContainer.appendChild(geomContainer); featureContainer.appendChild(geomContainer);
for(var attr in feature.attributes) { for(var attr in feature.attributes) {
if (feature.attributes.hasOwnProperty(attr)) {
var attrText = this.createTextNode(feature.attributes[attr]); var attrText = this.createTextNode(feature.attributes[attr]);
var nodename = attr; var nodename = attr;
if (attr.search(":") != -1) { if (attr.search(":") != -1) {
@@ -114,7 +113,6 @@ OpenLayers.Format.WFS = OpenLayers.Class(OpenLayers.Format.GML, {
attrContainer.appendChild(attrText); attrContainer.appendChild(attrText);
featureContainer.appendChild(attrContainer); featureContainer.appendChild(attrContainer);
} }
}
return featureContainer; return featureContainer;
}, },
@@ -168,7 +166,6 @@ OpenLayers.Format.WFS = OpenLayers.Class(OpenLayers.Format.GML, {
// add in attributes // add in attributes
for(var propName in feature.attributes) { for(var propName in feature.attributes) {
if (feature.attributes.hasOwnProperty(propName)) {
propertyNode = this.createElementNS(this.wfsns, 'wfs:Property'); propertyNode = this.createElementNS(this.wfsns, 'wfs:Property');
nameNode = this.createElementNS(this.wfsns, 'wfs:Name'); nameNode = this.createElementNS(this.wfsns, 'wfs:Name');
nameNode.appendChild(this.createTextNode(propName)); nameNode.appendChild(this.createTextNode(propName));
@@ -178,7 +175,6 @@ OpenLayers.Format.WFS = OpenLayers.Class(OpenLayers.Format.GML, {
propertyNode.appendChild(valueNode); propertyNode.appendChild(valueNode);
updateNode.appendChild(propertyNode); updateNode.appendChild(propertyNode);
} }
}
var filterNode = this.createElementNS(this.ogcns, 'ogc:Filter'); var filterNode = this.createElementNS(this.ogcns, 'ogc:Filter');
-4
View File
@@ -332,7 +332,6 @@ OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
// add in attributes // add in attributes
for(var key in feature.attributes) { for(var key in feature.attributes) {
if (feature.attributes.hasOwnProperty(key)) {
if(feature.attributes[key] !== undefined && if(feature.attributes[key] !== undefined &&
(!modified || !modified.attributes || (!modified || !modified.attributes ||
(modified.attributes && modified.attributes[key] !== undefined))) { (modified.attributes && modified.attributes[key] !== undefined))) {
@@ -341,7 +340,6 @@ OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
); );
} }
} }
}
// add feature id filter // add feature id filter
this.writeNode("ogc:Filter", new OpenLayers.Filter.FeatureId({ this.writeNode("ogc:Filter", new OpenLayers.Filter.FeatureId({
@@ -412,13 +410,11 @@ OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
var parts = []; var parts = [];
var uri; var uri;
for(var key in schemaLocations) { for(var key in schemaLocations) {
if (schemaLocations.hasOwnProperty(key)) {
uri = this.namespaces[key]; uri = this.namespaces[key];
if(uri) { if(uri) {
parts.push(uri + " " + schemaLocations[key]); parts.push(uri + " " + schemaLocations[key]);
} }
} }
}
var value = parts.join(" ") || undefined; var value = parts.join(" ") || undefined;
return value; return value;
}, },
-8
View File
@@ -48,13 +48,11 @@ OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
prefix = this.namespaces[this.defaultPrefix]; prefix = this.namespaces[this.defaultPrefix];
} else { } else {
for(prefix in this.namespaces) { for(prefix in this.namespaces) {
if (this.namespaces.hasOwnProperty(prefix)) {
if(this.namespaces[prefix] == uri) { if(this.namespaces[prefix] == uri) {
break; break;
} }
} }
} }
}
return prefix; return prefix;
}, },
@@ -676,7 +674,6 @@ OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
setAttributes: function(node, obj) { setAttributes: function(node, obj) {
var value; var value;
for(var name in obj) { for(var name in obj) {
if (obj.hasOwnProperty(name)) {
value = obj[name].toString(); value = obj[name].toString();
if(value.match(/[A-Z]/)) { if(value.match(/[A-Z]/)) {
// safari lowercases attributes with setAttribute // safari lowercases attributes with setAttribute
@@ -685,7 +682,6 @@ OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
node.setAttribute(name, value); node.setAttribute(name, value);
} }
} }
}
}, },
/** /**
@@ -1095,18 +1091,15 @@ OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
userValue: true userValue: true
}; };
for (var dim in context.dimensions) { for (var dim in context.dimensions) {
if (context.dimensions.hasOwnProperty(dim)) {
var attributes = {}; var attributes = {};
var dimension = context.dimensions[dim]; var dimension = context.dimensions[dim];
for (var name in dimension) { for (var name in dimension) {
if (dimension.hasOwnProperty(name)) {
if (typeof dimension[name] == "boolean") { if (typeof dimension[name] == "boolean") {
attributes[name] = Number(dimension[name]); attributes[name] = Number(dimension[name]);
} else { } else {
attributes[name] = dimension[name]; attributes[name] = dimension[name];
} }
} }
}
var values = ""; var values = "";
if (attributes.values) { if (attributes.values) {
values = attributes.values.join(","); values = attributes.values.join(",");
@@ -1117,7 +1110,6 @@ OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
"Dimension", values, attributes "Dimension", values, attributes
)); ));
} }
}
return node; return node;
}, },
-2
View File
@@ -122,11 +122,9 @@ OpenLayers.Format.WMC.v1_1_0 = OpenLayers.Class(
// optional SRS element(s) // optional SRS element(s)
if (context.srs) { if (context.srs) {
for(var name in 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));
} }
} }
}
// optional FormatList element // optional FormatList element
node.appendChild(this.write_wmc_FormatList(context)); node.appendChild(this.write_wmc_FormatList(context));
@@ -84,12 +84,10 @@ OpenLayers.Format.WMTSCapabilities = OpenLayers.Class(OpenLayers.Format.XML.Vers
matrixSet: true matrixSet: true
}; };
for (var prop in required) { for (var prop in required) {
if (required.hasOwnProperty(prop)) {
if (!(prop in config)) { if (!(prop in config)) {
throw new Error("Missing property '" + prop + "' in layer configuration."); throw new Error("Missing property '" + prop + "' in layer configuration.");
} }
} }
}
var contents = capabilities.contents; var contents = capabilities.contents;
var matrixSet = contents.tileMatrixSets[config.matrixSet]; var matrixSet = contents.tileMatrixSets[config.matrixSet];
-4
View File
@@ -89,10 +89,8 @@ OpenLayers.Format.XML = OpenLayers.Class(OpenLayers.Format, {
this.namespaces = OpenLayers.Util.extend({}, this.namespaces); this.namespaces = OpenLayers.Util.extend({}, this.namespaces);
this.namespaceAlias = {}; this.namespaceAlias = {};
for(var alias in this.namespaces) { for(var alias in this.namespaces) {
if (this.namespaces.hasOwnProperty(alias)) {
this.namespaceAlias[this.namespaces[alias]] = alias; this.namespaceAlias[this.namespaces[alias]] = alias;
} }
}
}, },
/** /**
@@ -560,7 +558,6 @@ OpenLayers.Format.XML = OpenLayers.Class(OpenLayers.Format, {
setAttributes: function(node, obj) { setAttributes: function(node, obj) {
var value, uri; var value, uri;
for(var name in obj) { for(var name in obj) {
if (obj.hasOwnProperty(name)) {
if(obj[name] != null && obj[name].toString) { if(obj[name] != null && obj[name].toString) {
value = obj[name].toString(); value = obj[name].toString();
// check for qualified attribute name ("prefix:local") // check for qualified attribute name ("prefix:local")
@@ -568,7 +565,6 @@ OpenLayers.Format.XML = OpenLayers.Class(OpenLayers.Format, {
this.setAttributeNS(node, uri, name, value); this.setAttributeNS(node, uri, name, value);
} }
} }
}
}, },
/** /**
-2
View File
@@ -423,10 +423,8 @@ OpenLayers.Layer = OpenLayers.Class({
getOptions: function() { getOptions: function() {
var options = {}; var options = {};
for(var o in this.options) { for(var o in this.options) {
if (this.options.hasOwnProperty(o)) {
options[o] = this[o]; options[o] = this[o];
} }
}
return options; return options;
}, },
-2
View File
@@ -218,12 +218,10 @@ OpenLayers.Layer.HTTPRequest = OpenLayers.Class(OpenLayers.Layer, {
var urlParams = var urlParams =
OpenLayers.Util.upperCaseObject(OpenLayers.Util.getParameters(url)); OpenLayers.Util.upperCaseObject(OpenLayers.Util.getParameters(url));
for(var key in allParams) { for(var key in allParams) {
if (allParams.hasOwnProperty(key)) {
if(key.toUpperCase() in urlParams) { if(key.toUpperCase() in urlParams) {
delete allParams[key]; delete allParams[key];
} }
} }
}
paramsString = OpenLayers.Util.getParameterString(allParams); paramsString = OpenLayers.Util.getParameterString(allParams);
return OpenLayers.Util.urlAppend(url, paramsString); return OpenLayers.Util.urlAppend(url, paramsString);
-2
View File
@@ -346,12 +346,10 @@ OpenLayers.Layer.MapGuide = OpenLayers.Class(OpenLayers.Layer.Grid, {
var urlParams = OpenLayers.Util.upperCaseObject( var urlParams = OpenLayers.Util.upperCaseObject(
OpenLayers.Util.getParameters(url)); OpenLayers.Util.getParameters(url));
for(var key in allParams) { for(var key in allParams) {
if (allParams.hasOwnProperty(key)) {
if(key.toUpperCase() in urlParams) { if(key.toUpperCase() in urlParams) {
delete allParams[key]; delete allParams[key];
} }
} }
}
var paramsString = OpenLayers.Util.getParameterString(allParams); var paramsString = OpenLayers.Util.getParameterString(allParams);
/* MapGuide needs '+' seperating things like bounds/height/width. /* MapGuide needs '+' seperating things like bounds/height/width.
-2
View File
@@ -142,12 +142,10 @@ OpenLayers.Layer.MapServer = OpenLayers.Class(OpenLayers.Layer.Grid, {
var urlParams = OpenLayers.Util.upperCaseObject( var urlParams = OpenLayers.Util.upperCaseObject(
OpenLayers.Util.getParameters(url)); OpenLayers.Util.getParameters(url));
for(var key in allParams) { for(var key in allParams) {
if (allParams.hasOwnProperty(key)) {
if(key.toUpperCase() in urlParams) { if(key.toUpperCase() in urlParams) {
delete allParams[key]; delete allParams[key];
} }
} }
}
paramsString = OpenLayers.Util.getParameterString(allParams); paramsString = OpenLayers.Util.getParameterString(allParams);
// requestString always starts with url // requestString always starts with url
-2
View File
@@ -509,14 +509,12 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
if(!zoomChanged && coordSysUnchanged) { if(!zoomChanged && coordSysUnchanged) {
for(var i in this.unrenderedFeatures) { for(var i in this.unrenderedFeatures) {
if (this.unrenderedFeatures.hasOwnProperty(i)) {
var feature = this.unrenderedFeatures[i]; var feature = this.unrenderedFeatures[i];
this.drawFeature(feature); this.drawFeature(feature);
} }
} }
} }
} }
}
if (!this.drawn || (!ng && (zoomChanged || !coordSysUnchanged))) { if (!this.drawn || (!ng && (zoomChanged || !coordSysUnchanged))) {
this.drawn = true; this.drawn = true;
var feature; var feature;
-2
View File
@@ -229,12 +229,10 @@ OpenLayers.Layer.WMTS = OpenLayers.Class(OpenLayers.Layer.Grid, {
matrixSet: true matrixSet: true
}; };
for (var prop in required) { for (var prop in required) {
if (required.hasOwnProperty(prop)) {
if (!(prop in config)) { if (!(prop in config)) {
throw new Error("Missing property '" + prop + "' in layer configuration."); throw new Error("Missing property '" + prop + "' in layer configuration.");
} }
} }
}
config.params = OpenLayers.Util.upperCaseObject(config.params); config.params = OpenLayers.Util.upperCaseObject(config.params);
var args = [config.name, config.url, config.params, config]; var args = [config.name, config.url, config.params, config];
+1 -1
View File
@@ -630,7 +630,7 @@ OpenLayers.Map = OpenLayers.Class({
delete this.center; delete this.center;
this.addLayers(options.layers); this.addLayers(options.layers);
// set center (and optionally zoom) // set center (and optionally zoom)
if (options.center) { if (options.center && !this.getCenter()) {
// zoom can be undefined here // zoom can be undefined here
this.setCenter(options.center, options.zoom); this.setCenter(options.center, options.zoom);
} }
-2
View File
@@ -311,11 +311,9 @@ OpenLayers.Protocol.Script = OpenLayers.Class(OpenLayers.Protocol, {
this.destroyRequest(response.priv); this.destroyRequest(response.priv);
} else { } else {
for (var key in this.pendingRequests) { for (var key in this.pendingRequests) {
if (this.pendingRequests.hasOwnProperty(key)) {
this.destroyRequest(this.pendingRequests[key]); this.destroyRequest(this.pendingRequests[key]);
} }
} }
}
}, },
/** /**
-2
View File
@@ -181,10 +181,8 @@ OpenLayers.Request = {
config.method, url, config.async, config.user, config.password config.method, url, config.async, config.user, config.password
); );
for(var header in config.headers) { 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; var events = this.events;
-4
View File
@@ -128,10 +128,8 @@ OpenLayers.Rule = OpenLayers.Class({
*/ */
destroy: function() { destroy: function() {
for (var i in this.symbolizer) { for (var i in this.symbolizer) {
if (this.symbolizer.hasOwnProperty(i)) {
this.symbolizer[i] = null; this.symbolizer[i] = null;
} }
}
this.symbolizer = null; this.symbolizer = null;
delete this.symbolizers; delete this.symbolizers;
}, },
@@ -218,7 +216,6 @@ OpenLayers.Rule = OpenLayers.Class({
options.symbolizer = {}; options.symbolizer = {};
var value, type; var value, type;
for(var key in this.symbolizer) { for(var key in this.symbolizer) {
if (this.symbolizer.hasOwnProperty(key)) {
value = this.symbolizer[key]; value = this.symbolizer[key];
type = typeof value; type = typeof value;
if(type === "object") { if(type === "object") {
@@ -228,7 +225,6 @@ OpenLayers.Rule = OpenLayers.Class({
} }
} }
} }
}
// clone filter // clone filter
options.filter = this.filter && this.filter.clone(); options.filter = this.filter && this.filter.clone();
// clone context // clone context
-6
View File
@@ -273,10 +273,8 @@ OpenLayers.Style = OpenLayers.Class({
OpenLayers.Util.extend(context, this.context); OpenLayers.Util.extend(context, this.context);
for (var i in this.propertyStyles) { 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; return style;
}, },
@@ -303,7 +301,6 @@ OpenLayers.Style = OpenLayers.Class({
for (var i=0, len=rules.length; i<len; i++) { for (var i=0, len=rules.length; i<len; i++) {
symbolizer = rules[i].symbolizer; symbolizer = rules[i].symbolizer;
for (var key in symbolizer) { for (var key in symbolizer) {
if (symbolizer.hasOwnProperty(key)) {
value = symbolizer[key]; value = symbolizer[key];
if (typeof value == "object") { if (typeof value == "object") {
// symbolizer key is "Point", "Line" or "Polygon" // symbolizer key is "Point", "Line" or "Polygon"
@@ -315,7 +312,6 @@ OpenLayers.Style = OpenLayers.Class({
} }
} }
} }
}
return propertyStyles; return propertyStyles;
}, },
@@ -333,14 +329,12 @@ OpenLayers.Style = OpenLayers.Class({
addPropertyStyles: function(propertyStyles, symbolizer) { addPropertyStyles: function(propertyStyles, symbolizer) {
var property; var property;
for (var key in symbolizer) { for (var key in symbolizer) {
if (symbolizer.hasOwnProperty(key)) {
property = symbolizer[key]; property = symbolizer[key];
if (typeof property == "string" && if (typeof property == "string" &&
property.match(/\$\{\w+\}/)) { property.match(/\$\{\w+\}/)) {
propertyStyles[key] = true; propertyStyles[key] = true;
} }
} }
}
return propertyStyles; return propertyStyles;
}, },
-6
View File
@@ -63,7 +63,6 @@ OpenLayers.StyleMap = OpenLayers.Class({
this.styles["delete"] = style; this.styles["delete"] = style;
} else if(typeof style == "object") { } else if(typeof style == "object") {
for(var key in style) { for(var key in style) {
if (style.hasOwnProperty(key)) {
if(style[key] instanceof OpenLayers.Style) { if(style[key] instanceof OpenLayers.Style) {
// user passed a hash of style objects // user passed a hash of style objects
this.styles[key] = style[key]; this.styles[key] = style[key];
@@ -80,7 +79,6 @@ OpenLayers.StyleMap = OpenLayers.Class({
} }
} }
} }
}
OpenLayers.Util.extend(this, options); OpenLayers.Util.extend(this, options);
}, },
@@ -89,10 +87,8 @@ OpenLayers.StyleMap = OpenLayers.Class({
*/ */
destroy: function() { destroy: function() {
for(var key in this.styles) { for(var key in this.styles) {
if (this.styles.hasOwnProperty(key)) {
this.styles[key].destroy(); this.styles[key].destroy();
} }
}
this.styles = null; this.styles = null;
}, },
@@ -148,7 +144,6 @@ OpenLayers.StyleMap = OpenLayers.Class({
addUniqueValueRules: function(renderIntent, property, symbolizers, context) { addUniqueValueRules: function(renderIntent, property, symbolizers, context) {
var rules = []; var rules = [];
for (var value in symbolizers) { for (var value in symbolizers) {
if (symbolizers.hasOwnProperty(value)) {
rules.push(new OpenLayers.Rule({ rules.push(new OpenLayers.Rule({
symbolizer: symbolizers[value], symbolizer: symbolizers[value],
context: context, context: context,
@@ -159,7 +154,6 @@ OpenLayers.StyleMap = OpenLayers.Class({
}) })
})); }));
} }
}
this.styles[renderIntent].addRules(rules); this.styles[renderIntent].addRules(rules);
}, },
-2
View File
@@ -163,14 +163,12 @@ OpenLayers.Tile.Image.IFrame = {
field; field;
for(var par in params) { for(var par in params) {
if (params.hasOwnProperty(par)) {
field = document.createElement('input'); field = document.createElement('input');
field.type = 'hidden'; field.type = 'hidden';
field.name = par; field.name = par;
field.value = params[par]; field.value = params[par];
form.appendChild(field); form.appendChild(field);
} }
}
return form; return form;
}, },
-2
View File
@@ -127,7 +127,6 @@ OpenLayers.Tween = OpenLayers.Class({
play: function() { play: function() {
var value = {}; var value = {};
for (var i in this.begin) { for (var i in this.begin) {
if (this.begin.hasOwnProperty(i)) {
var b = this.begin[i]; var b = this.begin[i];
var f = this.finish[i]; var f = this.finish[i];
if (b == null || f == null || isNaN(b) || isNaN(f)) { if (b == null || f == null || isNaN(b) || isNaN(f)) {
@@ -137,7 +136,6 @@ OpenLayers.Tween = OpenLayers.Class({
var c = f - b; var c = f - b;
value[i] = this.easing.apply(this, [this.time, b, c, this.duration]); value[i] = this.easing.apply(this, [this.time, b, c, this.duration]);
} }
}
this.time++; this.time++;
if (this.callbacks && this.callbacks.eachStep) { if (this.callbacks && this.callbacks.eachStep) {
-10
View File
@@ -441,10 +441,8 @@ OpenLayers.Util.createAlphaImageDiv = function(id, px, sz, imgURL,
OpenLayers.Util.upperCaseObject = function (object) { OpenLayers.Util.upperCaseObject = function (object) {
var uObject = {}; var uObject = {};
for (var key in object) { for (var key in object) {
if (object.hasOwnProperty(key)) {
uObject[key.toUpperCase()] = object[key]; uObject[key.toUpperCase()] = object[key];
} }
}
return uObject; return uObject;
}; };
@@ -511,7 +509,6 @@ OpenLayers.Util.getParameterString = function(params) {
var paramsArray = []; var paramsArray = [];
for (var key in params) { for (var key in params) {
if (params.hasOwnProperty(key)) {
var value = params[key]; var value = params[key];
if ((value != null) && (typeof value != 'function')) { if ((value != null) && (typeof value != 'function')) {
var encodedValue; var encodedValue;
@@ -534,7 +531,6 @@ OpenLayers.Util.getParameterString = function(params) {
paramsArray.push(encodeURIComponent(key) + "=" + encodedValue); paramsArray.push(encodeURIComponent(key) + "=" + encodedValue);
} }
} }
}
return paramsArray.join("&"); return paramsArray.join("&");
}; };
@@ -1305,30 +1301,24 @@ OpenLayers.Util.isEquivalentUrl = function(url1, url2, options) {
//compare all keys except for "args" (treated below) //compare all keys except for "args" (treated below)
for(var key in urlObj1) { for(var key in urlObj1) {
if (urlObj1.hasOwnProperty(key)) {
if(key !== "args") { if(key !== "args") {
if(urlObj1[key] != urlObj2[key]) { if(urlObj1[key] != urlObj2[key]) {
return false; return false;
} }
} }
} }
}
// compare search args - irrespective of order // compare search args - irrespective of order
for(var key in urlObj1.args) { for(var key in urlObj1.args) {
if (urlObj1.args.hasOwnProperty(key)) {
if(urlObj1.args[key] != urlObj2.args[key]) { if(urlObj1.args[key] != urlObj2.args[key]) {
return false; return false;
} }
delete urlObj2.args[key]; delete urlObj2.args[key];
} }
}
// urlObj2 shouldn't have any args left // urlObj2 shouldn't have any args left
for(var key in urlObj2.args) { for(var key in urlObj2.args) {
if (urlObj2.args.hasOwnProperty(key)) {
return false; return false;
} }
}
return true; return true;
}; };
+3 -3
View File
@@ -289,16 +289,16 @@
// move 10 pixels // move 10 pixels
trigger("mousemove", 0, 10); trigger("mousemove", 0, 10);
t.eq(log.length, 0, "a) no event fired yet"); t.eq(log.length, 1, "a) has fired an event");
t.delay_call( t.delay_call(
delay, function() { delay, function() {
// confirm measurepartial is fired // 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"); t.ok(log[0] && log[0].type == "measurepartial", "a) correct type");
// mousemove within the partialDelay fires no event, so the // mousemove within the partialDelay fires no event, so the
// measure below is the one of the initial point // 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 // b) move 10 pixels
trigger("mousemove", 0, 20); trigger("mousemove", 0, 20);
+72 -4
View File
@@ -11,6 +11,7 @@
t.eq(control.displayClass, "olControlPermalink", "displayClass is correct"); t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
t.eq(control.base, document.location.href, "base is correct"); t.eq(control.base, document.location.href, "base is correct");
t.ok(!control.anchor, "anchor is correct"); t.ok(!control.anchor, "anchor is correct");
control.destroy();
control = new OpenLayers.Control.Permalink('permalink', 'test.html'); control = new OpenLayers.Control.Permalink('permalink', 'test.html');
t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object"); 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.eq(control.base, 'test.html', "base is correct");
t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object"); t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object");
t.ok(!control.anchor, "anchor is correct"); t.ok(!control.anchor, "anchor is correct");
control.destroy();
control = new OpenLayers.Control.Permalink('permalink'); control = new OpenLayers.Control.Permalink('permalink');
t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object"); 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.eq(control.base, document.location.href, "base is correct");
t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object"); t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object");
t.ok(!control.anchor, "anchor is correct"); t.ok(!control.anchor, "anchor is correct");
control.destroy();
control = new OpenLayers.Control.Permalink(OpenLayers.Util.getElement('permalink')); control = new OpenLayers.Control.Permalink(OpenLayers.Util.getElement('permalink'));
t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object"); 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.eq(control.base, document.location.href, "base is correct");
t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object"); t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object");
t.ok(!control.anchor, "anchor is correct"); t.ok(!control.anchor, "anchor is correct");
control.destroy();
control = new OpenLayers.Control.Permalink({anchor: true}); control = new OpenLayers.Control.Permalink({anchor: true});
t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object"); 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.eq(control.base, document.location.href, "base is correct");
t.ok(control.element == null, "element is null"); t.ok(control.element == null, "element is null");
t.ok(control.anchor, "anchor is correct"); t.ok(control.anchor, "anchor is correct");
control.destroy();
control = new OpenLayers.Control.Permalink({anchor: false}); control = new OpenLayers.Control.Permalink({anchor: false});
t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object"); t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
t.eq(control.displayClass, "olControlPermalink", "displayClass is correct"); t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
t.eq(control.base, document.location.href, "base is correct"); t.eq(control.base, document.location.href, "base is correct");
t.ok(!control.anchor, "anchor is correct"); t.ok(!control.anchor, "anchor is correct");
control.destroy();
control = new OpenLayers.Control.Permalink({}); control = new OpenLayers.Control.Permalink({});
t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object"); t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
t.eq(control.displayClass, "olControlPermalink", "displayClass is correct"); t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
t.eq(control.base, document.location.href, "base is correct"); t.eq(control.base, document.location.href, "base is correct");
t.ok(!control.anchor, "anchor is correct"); t.ok(!control.anchor, "anchor is correct");
control.destroy();
control = new OpenLayers.Control.Permalink({element: 'permalink', base: 'test.html'}); control = new OpenLayers.Control.Permalink({element: 'permalink', base: 'test.html'});
t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object"); 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.eq(control.base, 'test.html', "base is correct");
t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object"); t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object");
t.ok(!control.anchor, "anchor is correct"); t.ok(!control.anchor, "anchor is correct");
control.destroy();
control = new OpenLayers.Control.Permalink({element: 'permalink', base: 'test.html', anchor: true}); control = new OpenLayers.Control.Permalink({element: 'permalink', base: 'test.html', anchor: true});
t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object"); 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.eq(control.base, 'test.html', "base is correct");
t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object"); t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object");
t.ok(control.anchor, "anchor is correct"); t.ok(control.anchor, "anchor is correct");
control.destroy();
} }
function test_Control_Permalink_uncentered (t) { function test_Control_Permalink_uncentered (t) {
t.plan( 1 ); t.plan( 1 );
@@ -74,12 +83,14 @@
map.addControl(control); map.addControl(control);
map.events.triggerEvent("changelayer", {}); map.events.triggerEvent("changelayer", {});
t.ok(true, "permalink didn't bomb out."); t.ok(true, "permalink didn't bomb out.");
map.destroy();
} }
function test_Control_Permalink_initwithelem (t) { function test_Control_Permalink_initwithelem (t) {
t.plan( 1 ); t.plan( 1 );
control = new OpenLayers.Control.Permalink(OpenLayers.Util.getElement('permalink')); control = new OpenLayers.Control.Permalink(OpenLayers.Util.getElement('permalink'));
t.ok(true, "If the above line doesn't throw an error, we're safe."); t.ok(true, "If the above line doesn't throw an error, we're safe.");
control.destroy();
} }
function test_Control_Permalink_updateLinks (t) { function test_Control_Permalink_updateLinks (t) {
t.plan( 3 ); t.plan( 3 );
@@ -100,6 +111,7 @@
map.layers[1].setVisibility(false); 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'); 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) { function test_Control_Permalink_updateLinksBase (t) {
t.plan( 2 ); t.plan( 2 );
@@ -114,6 +126,7 @@
map.pan(5, 0, {animate:false}); map.pan(5, 0, {animate:false});
OpenLayers.Util.getElement('edit_permalink').href = './edit.html?zoom=2&lat=0&lon=1.75781&layers=B'; 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"); 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) { function test_Control_Permalink_noElement (t) {
t.plan( 2 ); t.plan( 2 );
@@ -122,6 +135,7 @@
map = new OpenLayers.Map('map'); map = new OpenLayers.Map('map');
map.addControl(control); map.addControl(control);
t.eq(map.controls[4].div.firstChild.nodeName, "A", "Permalink control creates div with 'a' inside." ); 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) { function test_Control_Permalink_base_with_query (t) {
t.plan( 3 ); t.plan( 3 );
@@ -147,6 +161,7 @@
map.pan(5, 0, {animate:false}); map.pan(5, 0, {animate:false});
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 '?'"); 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}); map.pan(5, 0, {animate:false});
OpenLayers.Util.getElement('edit_permalink').href = './edit.html?zoom=2&lat=0&lon=1.75781&layers=B'; 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"); 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) { 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(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."); 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) { function test_Control_Permalink_createParams(t) {
@@ -300,6 +317,7 @@
map.layers[1].setVisibility(false); 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'); 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) { function test_Control_Permalink_AnchorBaseElement (t) {
@@ -320,10 +338,15 @@
map.layers[1].setVisibility(false); 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'); 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_arrayCenter(t) { function test_center_from_map(t) {
t.plan(1); t.plan(7);
var previous = window.location.hash;
window.location.hash = "";
var err; var err;
try { try {
var map = new OpenLayers.Map({ var map = new OpenLayers.Map({
@@ -331,8 +354,8 @@
controls: [ controls: [
new OpenLayers.Control.Permalink({anchor: true}) new OpenLayers.Control.Permalink({anchor: true})
], ],
center: [0, 0], center: [1, 2],
zoom: 1 zoom: 3
}); });
} catch (e) { } catch (e) {
err = e; err = e;
@@ -342,6 +365,51 @@
} else { } else {
t.ok(true, "Map construction works"); 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;
} }
</script> </script>