[OpenLayers-Commits] r4803 - in sandbox/context: examples lib/OpenLayers/BaseTypes lib/OpenLayers/Control
commits at openlayers.org
commits at openlayers.org
Wed Oct 3 19:26:15 EDT 2007
Author: tschaub
Date: 2007-10-03 19:26:15 -0400 (Wed, 03 Oct 2007)
New Revision: 4803
Modified:
sandbox/context/examples/context.html
sandbox/context/lib/OpenLayers/BaseTypes/Class.js
sandbox/context/lib/OpenLayers/Control/MouseToolbar.js
Log:
instances are not serializable by default
Modified: sandbox/context/examples/context.html
===================================================================
--- sandbox/context/examples/context.html 2007-10-03 22:34:08 UTC (rev 4802)
+++ sandbox/context/examples/context.html 2007-10-03 23:26:15 UTC (rev 4803)
@@ -115,6 +115,14 @@
var str = element.value;
var obj = olon.read(str);
map.addLayers(obj.layers);
+ var zoom;
+ if(obj.resolution) {
+ zoom = map.getZoomForResolution(obj.resolution, true);
+ }
+ if(obj.center) {
+ map.setCenter(obj.center, zoom);
+ }
+
}
</script>
</head>
Modified: sandbox/context/lib/OpenLayers/BaseTypes/Class.js
===================================================================
--- sandbox/context/lib/OpenLayers/BaseTypes/Class.js 2007-10-03 22:34:08 UTC (rev 4802)
+++ sandbox/context/lib/OpenLayers/BaseTypes/Class.js 2007-10-03 23:26:15 UTC (rev 4803)
@@ -53,12 +53,18 @@
// serialize the args and props
var index;
var args = obj.args;
- for(index=0; index<args.length; ++index) {
- data[args[index]] = OpenLayers.Class.serialize(this[args[index]]);
+ if(args) {
+ for(index=0; index<args.length; ++index) {
+ data[args[index]] = OpenLayers.Class.serialize(
+ this[args[index]]
+ );
+ }
}
var props = obj.props;
for(index=0; index<props.length; ++index) {
- data[props[index]] = OpenLayers.Class.serialize(this[props[index]]);
+ data[props[index]] = OpenLayers.Class.serialize(
+ this[props[index]]
+ );
}
// add in the class name
data.CLASS_NAME = this.CLASS_NAME;
@@ -68,32 +74,40 @@
// get the serializable object on the prototype
var proto = arguments[arguments.length - 1];
- /**
- * Property: Class.prototype.serializable
- * {Object} Object that maps serializalble properties of an instance
- * of this class.
- *
- * The serializable object has three properties:
- * args - {Array} Property names to be applied to the constructor.
- * All required argument names must be supplied here. There is
- * no inheritance of the args array from any parent classes.
- * props - {Array} All additional properties to set on the new
- * instance. These will be set by direct assignment. The props
- * array inherits from its parent by merging arrays. Any new
- * properties specified in a child props array will be added
- * to the properties inherited from a parent class.
- * except - {Array} List of properties from a parent class' props
- * array that will not be merged with the props array of a child
- * class.
- */
- var serializable = {
- "args": (proto.serializable && proto.serializable.args) ?
- proto.serializable.args : [],
- "props": (proto.serializable && proto.serializable.props) ?
- proto.serializable.props : [],
- "except": (proto.serializable && proto.serializable.except) ?
- proto.serializable.except : []
- };
+ var serializable;
+ if(proto.serializable) {
+ /**
+ * Property: Class.prototype.serializable
+ * {Object} Object that maps serializalble properties of an instance
+ * of this class. By default, instances will not be serialized.
+ * To allow an instance to be serialized, add a serializable
+ * property to the prototype. Subclasses will inherit this
+ * property in the manor described below. The simplest way to make
+ * an instance serializable is to set the serializable property
+ * to an empty object ({}).
+ *
+ * The serializable object has three properties:
+ * args - {Array} Property names to be applied to the constructor.
+ * All required argument names must be supplied here. If args
+ * is undefined, args will be inherited from the parent.
+ * props - {Array} All additional properties to set on the new
+ * instance. These will be set by direct assignment. The props
+ * array inherits from its parent by merging arrays. Any new
+ * properties specified in a child props array will be added
+ * to the properties inherited from a parent class.
+ * except - {Array} List of properties from a parent class' props
+ * array that will not be merged with the props array of a child
+ * class. There is no inheritance of the except array.
+ */
+ serializable = {
+ "args": (proto.serializable.args) ?
+ proto.serializable.args : undefined,
+ "props": (proto.serializable.props) ?
+ proto.serializable.props : [],
+ "except": (proto.serializable.except) ?
+ proto.serializable.except : []
+ };
+ }
// inherit from all arguments
var parent = {};
@@ -104,6 +118,9 @@
// All OpenLayers classes are serializable.
// Inheriting from others still works.
if(parent.serializable) {
+ // prototype may not have serializable property
+ serializable = (serializable) ?
+ serializable : {"props": [], "except": []};
// props are merged with the parent
var prop;
var indexOf = OpenLayers.Util.indexOf;
@@ -116,7 +133,7 @@
}
}
// args are inherited only if not specified in the prototype
- if(!serializable.args || serializable.args.length == 0) {
+ if(!serializable.args) {
serializable.args = parent.serializable.args;
}
}
@@ -169,7 +186,9 @@
for(var key in obj) {
value = OpenLayers.Class.serialize(obj[key], depth);
if(value !== undefined) {
- data[key] = OpenLayers.Class.serialize(obj[key], depth);
+ data[key] = OpenLayers.Class.serialize(
+ obj[key], depth
+ );
}
}
} else {
@@ -230,7 +249,7 @@
// deal with instances of OpenLayers classes
var olClass = eval(struct.CLASS_NAME);
if(!olClass.prototype.serializable) {
- var msg = "Unable to deserialize. Bad CLASS_NAME: " +
+ var msg = "Unable to deserialize. CLASS_NAME: " +
struct.CLASS_NAME;
throw Error(msg);
}
Modified: sandbox/context/lib/OpenLayers/Control/MouseToolbar.js
===================================================================
--- sandbox/context/lib/OpenLayers/Control/MouseToolbar.js 2007-10-03 22:34:08 UTC (rev 4802)
+++ sandbox/context/lib/OpenLayers/Control/MouseToolbar.js 2007-10-03 23:26:15 UTC (rev 4803)
@@ -378,7 +378,9 @@
this.performedDrag = false;
return false;
}
- }
+ },
+
+ CLASS_NAME: "OpenLayers.Control.MouseToolbar"
});
OpenLayers.Control.MouseToolbar.X = 6;
More information about the Commits
mailing list