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
+3 -5
View File
@@ -91,11 +91,9 @@ 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;
}
} }
} }
+4 -12
View File
@@ -258,9 +258,7 @@ 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(
@@ -278,9 +276,7 @@ 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(
@@ -564,9 +560,7 @@ 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,9 +573,7 @@ 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");
} }
}, },
+23 -31
View File
@@ -193,9 +193,7 @@ 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,27 +334,25 @@ 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); this.previousStack.unshift(state);
this.previousStack.unshift(state); if(this.previousStack.length > 1) {
if(this.previousStack.length > 1) { this.onPreviousChange(
this.onPreviousChange( this.previousStack[1], this.previousStack.length - 1
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);
}
} }
return true; if(this.previousStack.length > (this.limit + 1)) {
}, this); 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(); 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) {
@@ -411,11 +405,9 @@ 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();
+5 -4
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;
}
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); OpenLayers.Control.prototype.destroy.apply(this, arguments);
}, },
+4 -9
View File
@@ -168,16 +168,11 @@ 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) { delete this.layerCache[key];
if (this.layerCache.hasOwnProperty(key)) {
delete this.layerCache[key];
}
} }
for (key in this.wfsCache) { for (var 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);
}, },
+4 -6
View File
@@ -456,12 +456,10 @@ 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);
}
} }
} }
}, },
+6 -8
View File
@@ -564,14 +564,12 @@ 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( "feature:_attribute",
"feature:_attribute", {name: name, value: value}, node
{name: name, value: value}, node );
);
}
} }
} }
return node; return node;
+8 -10
View File
@@ -325,17 +325,15 @@ 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; if (attr.search(":") != -1) {
if (attr.search(":") != -1) { nodename = attr.split(":")[1];
nodename = attr.split(":")[1];
}
var attrContainer = this.createElementNS(this.featureNS, "feature:"+nodename);
attrContainer.appendChild(attrText);
featureNode.appendChild(attrContainer);
} }
var attrContainer = this.createElementNS(this.featureNS, "feature:"+nodename);
attrContainer.appendChild(attrText);
featureNode.appendChild(attrContainer);
} }
featureNode.appendChild(geometryNode); featureNode.appendChild(geometryNode);
return featureNode; return featureNode;
+30 -36
View File
@@ -140,35 +140,33 @@ 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;
if (this.checkTags) { if (this.checkTags) {
var result = this.getTags(node.node, true); var result = this.getTags(node.node, true);
if (node.used && !result[1]) { if (node.used && !result[1]) {
continue; continue;
}
tags = result[0];
} else {
tags = this.getTags(node.node);
} }
tags = result[0];
var feat = new OpenLayers.Feature.Vector( } else {
new OpenLayers.Geometry.Point(node['lon'], node['lat']), tags = this.getTags(node.node);
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; return feat_list;
}, },
@@ -275,11 +273,9 @@ 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;
}
} }
} }
} }
@@ -434,12 +430,10 @@ 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);
}
} }
}, },
+12 -20
View File
@@ -541,11 +541,9 @@ 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.defaultGraphicFormat; return format || this.defautlGraphicFormat;
}, },
/** /**
@@ -680,9 +676,7 @@ 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;
@@ -775,13 +769,11 @@ 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
@@ -128,12 +128,10 @@ 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;
+2 -6
View File
@@ -210,14 +210,10 @@ 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);
+15 -19
View File
@@ -104,16 +104,14 @@ 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) { nodename = attr.split(":")[1];
nodename = attr.split(":")[1];
}
var attrContainer = this.createElementNS(this.featureNS, "feature:" + nodename);
attrContainer.appendChild(attrText);
featureContainer.appendChild(attrContainer);
} }
var attrContainer = this.createElementNS(this.featureNS, "feature:" + nodename);
attrContainer.appendChild(attrText);
featureContainer.appendChild(attrContainer);
} }
return featureContainer; return featureContainer;
}, },
@@ -168,16 +166,14 @@ 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)); propertyNode.appendChild(nameNode);
propertyNode.appendChild(nameNode); valueNode = this.createElementNS(this.wfsns, 'wfs:Value');
valueNode = this.createElementNS(this.wfsns, 'wfs:Value'); valueNode.appendChild(this.createTextNode(feature.attributes[propName]));
valueNode.appendChild(this.createTextNode(feature.attributes[propName])); propertyNode.appendChild(valueNode);
propertyNode.appendChild(valueNode); updateNode.appendChild(propertyNode);
updateNode.appendChild(propertyNode);
}
} }
+9 -13
View File
@@ -332,14 +332,12 @@ 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))) { this.writeNode(
this.writeNode( "Property", {name: key, value: feature.attributes[key]}, node
"Property", {name: key, value: feature.attributes[key]}, node );
);
}
} }
} }
@@ -412,11 +410,9 @@ 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;
+25 -33
View File
@@ -48,10 +48,8 @@ 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;
}
} }
} }
} }
@@ -676,14 +674,12 @@ 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 this.setAttributeNS(node, null, name, value);
this.setAttributeNS(node, null, name, value); } else {
} else { node.setAttribute(name, value);
node.setAttribute(name, value);
}
} }
} }
}, },
@@ -1095,29 +1091,25 @@ 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 (typeof dimension[name] == "boolean") {
if (dimension.hasOwnProperty(name)) { attributes[name] = Number(dimension[name]);
if (typeof dimension[name] == "boolean") { } else {
attributes[name] = Number(dimension[name]); attributes[name] = dimension[name];
} else {
attributes[name] = dimension[name];
}
}
}
var values = "";
if (attributes.values) {
values = attributes.values.join(",");
delete attributes.values;
} }
}
var values = "";
if (attributes.values) {
values = attributes.values.join(",");
delete attributes.values;
}
node.appendChild(this.createElementDefaultNS( node.appendChild(this.createElementDefaultNS(
"Dimension", values, attributes "Dimension", values, attributes
)); ));
} }
}
return node; return node;
}, },
+1 -3
View File
@@ -122,9 +122,7 @@ 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));
}
} }
} }
+2 -4
View File
@@ -84,10 +84,8 @@ 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.");
}
} }
} }
+6 -10
View File
@@ -89,9 +89,7 @@ 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,13 +558,11 @@ 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") uri = this.namespaces[name.substring(0, name.indexOf(":"))] || null;
uri = this.namespaces[name.substring(0, name.indexOf(":"))] || null; this.setAttributeNS(node, uri, name, value);
this.setAttributeNS(node, uri, name, value);
}
} }
} }
}, },
+1 -3
View File
@@ -423,9 +423,7 @@ 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 -4
View File
@@ -218,10 +218,8 @@ 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);
+2 -4
View File
@@ -346,10 +346,8 @@ 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);
+2 -4
View File
@@ -142,10 +142,8 @@ 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);
+2 -4
View File
@@ -509,10 +509,8 @@ 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);
}
} }
} }
} }
+2 -4
View File
@@ -229,10 +229,8 @@ 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.");
}
} }
} }
+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);
} }
+1 -3
View File
@@ -311,9 +311,7 @@ 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]);
}
} }
} }
}, },
+1 -3
View File
@@ -181,9 +181,7 @@ 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;
+7 -11
View File
@@ -128,9 +128,7 @@ 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,14 +216,12 @@ 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") { options.symbolizer[key] = OpenLayers.Util.extend({}, value);
options.symbolizer[key] = OpenLayers.Util.extend({}, value); } else if(type === "string") {
} else if(type === "string") { options.symbolizer[key] = value;
options.symbolizer[key] = value;
}
} }
} }
} }
+13 -19
View File
@@ -273,9 +273,7 @@ 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,16 +301,14 @@ 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" this.addPropertyStyles(propertyStyles, value);
this.addPropertyStyles(propertyStyles, value); } else {
} else { // symbolizer is a hash of style properties
// symbolizer is a hash of style properties this.addPropertyStyles(propertyStyles, symbolizer);
this.addPropertyStyles(propertyStyles, symbolizer); break;
break;
}
} }
} }
} }
@@ -333,12 +329,10 @@ 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;
+23 -29
View File
@@ -63,21 +63,19 @@ 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]; } else if(typeof style[key] == "object") {
} else if(typeof style[key] == "object") { // user passsed a hash of style hashes
// user passsed a hash of style hashes this.styles[key] = new OpenLayers.Style(style[key]);
this.styles[key] = new OpenLayers.Style(style[key]); } else {
} else { // user passed a style hash (i.e. symbolizer)
// user passed a style hash (i.e. symbolizer) this.styles["default"] = new OpenLayers.Style(style);
this.styles["default"] = new OpenLayers.Style(style); this.styles["select"] = new OpenLayers.Style(style);
this.styles["select"] = new OpenLayers.Style(style); this.styles["temporary"] = new OpenLayers.Style(style);
this.styles["temporary"] = new OpenLayers.Style(style); this.styles["delete"] = new OpenLayers.Style(style);
this.styles["delete"] = new OpenLayers.Style(style); break;
break;
}
} }
} }
} }
@@ -89,9 +87,7 @@ 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,17 +144,15 @@ 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, filter: new OpenLayers.Filter.Comparison({
filter: new OpenLayers.Filter.Comparison({ type: OpenLayers.Filter.Comparison.EQUAL_TO,
type: OpenLayers.Filter.Comparison.EQUAL_TO, property: property,
property: property, value: value
value: value })
}) }));
}));
}
} }
this.styles[renderIntent].addRules(rules); this.styles[renderIntent].addRules(rules);
}, },
+5 -7
View File
@@ -163,13 +163,11 @@ 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;
+7 -9
View File
@@ -127,16 +127,14 @@ 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)) { throw new TypeError('invalid value for Tween');
throw new TypeError('invalid value for Tween');
}
var c = f - b;
value[i] = this.easing.apply(this, [this.time, b, c, this.duration]);
} }
var c = f - b;
value[i] = this.easing.apply(this, [this.time, b, c, this.duration]);
} }
this.time++; this.time++;
+32 -42
View File
@@ -441,9 +441,7 @@ 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,29 +509,27 @@ 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; if (typeof value == 'object' && value.constructor == Array) {
if (typeof value == 'object' && value.constructor == Array) { /* value is an array; encode items and separate with "," */
/* value is an array; encode items and separate with "," */ var encodedItemArray = [];
var encodedItemArray = []; var item;
var item; for (var itemIndex=0, len=value.length; itemIndex<len; itemIndex++) {
for (var itemIndex=0, len=value.length; itemIndex<len; itemIndex++) { item = value[itemIndex];
item = value[itemIndex]; encodedItemArray.push(encodeURIComponent(
encodedItemArray.push(encodeURIComponent( (item === null || item === undefined) ? "" : item)
(item === null || item === undefined) ? "" : item) );
); }
} encodedValue = encodedItemArray.join(",");
encodedValue = encodedItemArray.join(",");
}
else {
/* value is a string; simply encode */
encodedValue = encodeURIComponent(value);
}
paramsArray.push(encodeURIComponent(key) + "=" + encodedValue);
}
} }
else {
/* value is a string; simply encode */
encodedValue = encodeURIComponent(value);
}
paramsArray.push(encodeURIComponent(key) + "=" + encodedValue);
}
} }
return paramsArray.join("&"); return paramsArray.join("&");
@@ -1304,30 +1300,24 @@ OpenLayers.Util.isEquivalentUrl = function(url1, url2, options) {
var urlObj2 = OpenLayers.Util.createUrlObject(url2, options); var urlObj2 = OpenLayers.Util.createUrlObject(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;
}
delete urlObj2.args[key];
}
}
// urlObj2 shouldn't have any args left
for (var key in urlObj2.args) {
if (urlObj2.args.hasOwnProperty(key)) {
return false; return false;
} }
delete urlObj2.args[key];
}
// urlObj2 shouldn't have any args left
for(var key in urlObj2.args) {
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>