[OpenLayers-Commits] r4734 - sandbox/context/lib/OpenLayers/Format
commits at openlayers.org
commits at openlayers.org
Mon Oct 1 09:57:01 EDT 2007
Author: ominiverdi
Date: 2007-10-01 09:56:59 -0400 (Mon, 01 Oct 2007)
New Revision: 4734
Modified:
sandbox/context/lib/OpenLayers/Format/WMC.js
Log:
WMC: lib updated. OWS Map Context accepted in read() function, fake OLContext object created. Fake OLContext accepted by write() funtion, basic WMC XML as output.
Modified: sandbox/context/lib/OpenLayers/Format/WMC.js
===================================================================
--- sandbox/context/lib/OpenLayers/Format/WMC.js 2007-10-01 13:53:59 UTC (rev 4733)
+++ sandbox/context/lib/OpenLayers/Format/WMC.js 2007-10-01 13:56:59 UTC (rev 4734)
@@ -16,14 +16,14 @@
* Inherits from:
* - <OpenLayers.Format>
*/
-OpenLayers.Format.WMC = OpenLayers.Class(OpenLayers.Format.WMC, {
+OpenLayers.Format.WMC = OpenLayers.Class(OpenLayers.Format.XML, {
/**
* Constant: WMC_NS
* {String} default Name Space for OGC WMC version 1.1
*/
- WMC_NS: '*',//http://www.opengeospatial.net/context
+ WMC_NS: 'http://www.opengeospatial.net/context',//http://www.opengeospatial.net/context
/**
* Constructor: OpenLayers.Format.GML
@@ -57,100 +57,141 @@
read: function(data) {
console.log('start read');
- var OLContext={};
-
+ var OLContext = {};
+
if(typeof data == "string") {
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
}
- alert (data);
- return data;
+
+ var context = this.findChildByName(data,'ViewContext');
+
+
//PARSE MAP
console.log('parse map');
- var context = data.getElementsByTagNameNS(data,
- this.WMC_NS,
- 'ViewContext');
- console.log('parse map+1');
- alert (context[0]);
-
- OLContext.id = context.getAttribute('id');
+
+ OLContext.id = context.getAttribute('id');
+ console.log('id: ' + OLContext.id);
+ OLContext.version = context.getAttribute('version');
+ console.log('version: ' + OLContext.version);
+
//PARSE GENERAL OBJECT
+ //choosen attributes:
+ //"BoundingBox":{"minX":-281.25,"minY":-166.9921875,"maxX":281.25,"maxY":166.9921875,"srs":"EPSG:4326"},
+ //"Window":{"width":800,"height":475},
+
console.log('parse general');
+ OLContext.general = {};
+ var general = this.findChildByName(context,'General');
+ OLContext.general.title = OpenLayers.Format.XML.prototype.concatChildValues.apply(this,[this.findChildByName(general,'Title')]);
+ //OLContext.general.title
+
//PARSE LAYERLIST
console.log('parse layer list');
//OUTPUT
console.log('out');
- return 'OLContext';//OLContext
+ return OLContext;
},
-
+
+
/**
- * Method: parseAttributes
- *
+ * APIMethod: write
+ * Generate a WMC document string given a OpenLayers Context obj.
+ *
* Parameters:
- * node - {<DOMElement>}
+ * OpenLayers Context - {<OpenLayers.OLContext>} the OpenLayers Context object
*
* Returns:
- * {Object} An attributes object.
+ * node - {<DOMElement>} A DOM obj representing a WMC document.
*/
- parseAttributes: function(node) {
- var attributes = {};
- // assume attributes are children of the first type 1 child
- var childNode = node.firstChild;
- var children, i, child, grandchildren, grandchild, name, value;
- while(childNode) {
- if(childNode.nodeType == 1) {
- // attributes are type 1 children with one type 3 child
- children = childNode.childNodes;
- for(i=0; i<children.length; ++i) {
- child = children[i];
- if(child.nodeType == 1) {
- grandchildren = child.childNodes;
- if(grandchildren.length == 1) {
- grandchild = grandchildren[0];
- if(grandchild.nodeType == 3 ||
- grandchild.nodeType == 4) {
- name = (child.prefix) ?
- child.nodeName.split(":")[1] :
- child.nodeName;
- value = grandchild.nodeValue.replace(
- this.regExes.trimSpace, "");
- attributes[name] = value;
- }
- }
- }
- }
- break;
- }
- childNode = childNode.nextSibling;
- }
- return attributes;
+ write: function(OLContext) {
+ /*if(!(OLContext instanceof Array)) {
+ OLContext = [OLContext];
+ }*/
+ var wmc = this.createElementNS(this.WMC_NS,
+ "ViewContext");
+ wmc.setAttribute('id', OLContext.id);
+ wmc.setAttribute('version', OLContext.version);
+ if(OLContext.general){
+ var general = this.createElementNS(this.WMC_NS,'General');
+ if(OLContext.general.title){
+ var title = this.createElementNS(this.WMC_NS,'Title');
+ title.appendChild(this.createTextNode(OLContext.general.title));
+ general.appendChild(title);
+ }
+
+ wmc.appendChild(general);
+ }
+
+ //createTextNode
+
+ /*for(var i=0; i<OLContext.length; i++) {
+ wmc.appendChild(this.createFeatureXML(OLContext[i]));
+ }*/
+ return OpenLayers.Format.XML.prototype.write.apply(this, [wmc]);
+
+ //return OpenLayers.Format.XML.prototype.concatChildValues.apply(features);
+ //OpenLayers.Ajax.getText(
+ //return features;
},
-
- /**
- * APIMethod: write
- * Generate a WMC document string given a OpenLayers Context obj.
+
+
+ /**
+ * @private
+ * APIMethod: findChildByName
+ * get first occurence of named tag from node children.
+ * no recursion
*
* Parameters:
- * OpenLayers Context - {<OpenLayers.OLContext>} the OpenLayers Context object
+ * Tag Nam - {String} the name of the tag to match
*
* Returns:
- * {XMLDOM} A DOM obj representing a WMC document.
+ * node - {<DOMElement>} the DOM Node correspondant to tag name
+ *
*/
- write: function(features) {
- if(!(features instanceof Array)) {
- features = [features];
- }
- var gml = this.createElementNS("http://www.opengis.net/wfs",
- "wfs:" + this.collectionName);
- for(var i=0; i<features.length; i++) {
- gml.appendChild(this.createFeatureXML(features[i]));
- }
- return OpenLayers.Format.XML.prototype.write.apply(this, [gml]);
- },
+ findChildByName: function(n,name) {
+ if(!n)return false;
+ var x = n.firstChild;
+ while (x)
+ {
+ if(x.nodeName==name) return x;
+ else if(x==n.lastChild)return null;
+ else x=x.nextSibling;
+ }
+ },
+
+ /**
+ * @private
+ * APIMethod: findChildrenByName
+ * returns an array of node matching the named tag
+ * no recursion
+ *
+ * Parameters:
+ * Tag Nam - {String} the name of the tag to match
+ *
+ * Returns:
+ * {Array (node - {<DOMElement>})} the array of DOM Nodes correspondant to tag name
+ *
+ */
+ findChildrenByName: function(n,name) {
+ if(!n)return false;
+ var nodes=n.childNodes;
+ var aNode = [];
+ for (i=0;i<nodes.length;i++) {
+ var x=n.childNodes[i];
+ if(x.nodeName==name) aNode.push(x) ;
+ }
+
+ return aNode;
+ },
+
CLASS_NAME: "OpenLayers.Format.WMC"
});
+
+
+
More information about the Commits
mailing list