[OpenLayers-Commits] r11871 - in trunk/openlayers:
lib/OpenLayers/Format lib/OpenLayers/Format/WMC tests/Format
tests/Format/WMC
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Mon Apr 4 13:15:17 EDT 2011
Author: tschaub
Date: 2011-04-04 10:15:14 -0700 (Mon, 04 Apr 2011)
New Revision: 11871
Modified:
trunk/openlayers/lib/OpenLayers/Format/Context.js
trunk/openlayers/lib/OpenLayers/Format/WMC.js
trunk/openlayers/lib/OpenLayers/Format/WMC/v1.js
trunk/openlayers/lib/OpenLayers/Format/WMC/v1_0_0.js
trunk/openlayers/lib/OpenLayers/Format/WMC/v1_1_0.js
trunk/openlayers/tests/Format/WMC.html
trunk/openlayers/tests/Format/WMC/v1.html
Log:
Enhancements to the WMC parser for better contact information, SRS, and style support. p=trondmm, r=me (closes #3236)
Modified: trunk/openlayers/lib/OpenLayers/Format/Context.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/Context.js 2011-04-04 17:11:14 UTC (rev 11870)
+++ trunk/openlayers/lib/OpenLayers/Format/Context.js 2011-04-04 17:15:14 UTC (rev 11871)
@@ -122,7 +122,11 @@
visibility: layerContext.visibility,
maxExtent: layerContext.maxExtent,
metadata: OpenLayers.Util.applyDefaults(layerContext.metadata,
- {styles: layerContext.styles}),
+ {styles: layerContext.styles,
+ formats: layerContext.formats,
+ "abstract": layerContext["abstract"],
+ dataURL: layerContext.dataURL
+ }),
numZoomLevels: layerContext.numZoomLevels,
units: layerContext.units,
isBaseLayer: layerContext.isBaseLayer,
@@ -135,7 +139,10 @@
layerContext.tileSize.height
) : undefined,
minScale: layerContext.minScale || layerContext.maxScaleDenominator,
- maxScale: layerContext.maxScale || layerContext.minScaleDenominator
+ maxScale: layerContext.maxScale || layerContext.minScaleDenominator,
+ srs: layerContext.srs,
+ dimensions: layerContext.dimensions,
+ metadataURL: layerContext.metadataURL
};
if (this.layerOptions) {
OpenLayers.Util.applyDefaults(options, this.layerOptions);
@@ -273,10 +280,22 @@
projection: context.projection,
units: context.units
}, options);
+
if (options.maxExtent) {
options.maxResolution =
options.maxExtent.getWidth() / OpenLayers.Map.TILE_WIDTH;
}
+
+ var metadata = {
+ contactInformation: context.contactInformation,
+ "abstract": context["abstract"],
+ keywords: context.keywords,
+ logo: context.logo,
+ descriptionURL: context.descriptionURL
+ }
+
+ options.metadata = metadata;
+
var map = new OpenLayers.Map(options);
map.addLayers(this.getLayersFromContext(context.layersContext));
map.setCenter(
Modified: trunk/openlayers/lib/OpenLayers/Format/WMC/v1.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/WMC/v1.js 2011-04-04 17:11:14 UTC (rev 11870)
+++ trunk/openlayers/lib/OpenLayers/Format/WMC/v1.js 2011-04-04 17:15:14 UTC (rev 11871)
@@ -171,7 +171,8 @@
visibility: (node.getAttribute("hidden") != "1"),
queryable: (node.getAttribute("queryable") == "1"),
formats: [],
- styles: []
+ styles: [],
+ metadata: {}
};
this.runChildNodes(layerContext, node);
@@ -259,12 +260,8 @@
*/
read_wmc_Server: function(layerContext, node) {
layerContext.version = node.getAttribute("version");
- var server = {};
- var links = node.getElementsByTagName("OnlineResource");
- if(links.length > 0) {
- this.read_wmc_OnlineResource(server, links[0]);
- }
- layerContext.url = server.href;
+ layerContext.url = this.getOnlineResource_href(node);
+ layerContext.metadata.servertitle = node.getAttribute("title");
},
/**
@@ -323,6 +320,14 @@
},
/**
+ * Method: read_sld_FeatureTypeStyle
+ */
+ read_sld_FeatureTypeStyle: function(sld, node) {
+ var xml = OpenLayers.Format.XML.prototype.write.apply(this, [node]);
+ sld.body = xml;
+ },
+
+ /**
* Method: read_wmc_OnlineResource
*/
read_wmc_OnlineResource: function(obj, node) {
@@ -355,16 +360,25 @@
* Method: read_wmc_MetadataURL
*/
read_wmc_MetadataURL: function(layerContext, node) {
- var metadataURL = {};
- var links = node.getElementsByTagName("OnlineResource");
- if(links.length > 0) {
- this.read_wmc_OnlineResource(metadataURL, links[0]);
- }
- layerContext.metadataURL = metadataURL.href;
+ layerContext.metadataURL = this.getOnlineResource_href(node);
+ },
+ /**
+ * Method: read_wmc_KeywordList
+ */
+ read_wmc_KeywordList: function(context, node) {
+ context.keywords = [];
+ this.runChildNodes(context.keywords, node);
},
/**
+ * Method: read_wmc_Keyword
+ */
+ read_wmc_Keyword: function(keywords, node) {
+ keywords.push(this.getChildValue(node));
+ },
+
+ /**
* Method: read_wmc_Abstract
*/
read_wmc_Abstract: function(obj, node) {
@@ -375,21 +389,221 @@
},
/**
+ * Method: read_wmc_LogoURL
+ */
+ read_wmc_LogoURL: function(context, node) {
+ context.logo = {
+ width: node.getAttribute("width"),
+ height: node.getAttribute("height"),
+ format: node.getAttribute("format"),
+ href: this.getOnlineResource_href(node)
+ };
+ },
+
+ /**
+ * Method: read_wmc_DescriptionURL
+ */
+ read_wmc_DescriptionURL: function(context, node) {
+ context.descriptionURL = this.getOnlineResource_href(node);
+ },
+
+ /**
+ * Method: read_wmc_ContactInformation
+ */
+ read_wmc_ContactInformation: function(obj, node) {
+ var contact = {};
+ this.runChildNodes(contact, node);
+ obj.contactInformation = contact;
+ },
+
+ /**
+ * Method: read_wmc_ContactPersonPrimary
+ */
+ read_wmc_ContactPersonPrimary: function(contact, node) {
+ var personPrimary = {};
+ this.runChildNodes(personPrimary, node);
+ contact.personPrimary = personPrimary;
+ },
+
+ /**
+ * Method: read_wmc_ContactPerson
+ */
+ read_wmc_ContactPerson: function(primaryPerson, node) {
+ var person = this.getChildValue(node);
+ if (person) {
+ primaryPerson.person = person;
+ }
+ },
+
+ /**
+ * Method: read_wmc_ContactOrganization
+ */
+ read_wmc_ContactOrganization: function(primaryPerson, node) {
+ var organization = this.getChildValue(node);
+ if (organization) {
+ primaryPerson.organization = organization;
+ }
+ },
+
+ /**
+ * Method: read_wmc_ContactPosition
+ */
+ read_wmc_ContactPosition: function(contact, node) {
+ var position = this.getChildValue(node);
+ if (position) {
+ contact.position = position;
+ }
+ },
+
+ /**
+ * Method: read_wmc_ContactAddress
+ */
+ read_wmc_ContactAddress: function(contact, node) {
+ var contactAddress = {};
+ this.runChildNodes(contactAddress, node);
+ contact.contactAddress = contactAddress;
+ },
+
+ /**
+ * Method: read_wmc_AddressType
+ */
+ read_wmc_AddressType: function(contactAddress, node) {
+ var type = this.getChildValue(node);
+ if (type) {
+ contactAddress.type = type;
+ }
+ },
+
+ /**
+ * Method: read_wmc_Address
+ */
+ read_wmc_Address: function(contactAddress, node) {
+ var address = this.getChildValue(node);
+ if (address) {
+ contactAddress.address = address;
+ }
+ },
+
+ /**
+ * Method: read_wmc_City
+ */
+ read_wmc_City: function(contactAddress, node) {
+ var city = this.getChildValue(node);
+ if (city) {
+ contactAddress.city = city;
+ }
+ },
+
+ /**
+ * Method: read_wmc_StateOrProvince
+ */
+ read_wmc_StateOrProvince: function(contactAddress, node) {
+ var stateOrProvince = this.getChildValue(node);
+ if (stateOrProvince) {
+ contactAddress.stateOrProvince = stateOrProvince;
+ }
+ },
+
+ /**
+ * Method: read_wmc_PostCode
+ */
+ read_wmc_PostCode: function(contactAddress, node) {
+ var postcode = this.getChildValue(node);
+ if (postcode) {
+ contactAddress.postcode = postcode;
+ }
+ },
+
+ /**
+ * Method: read_wmc_Country
+ */
+ read_wmc_Country: function(contactAddress, node) {
+ var country = this.getChildValue(node);
+ if (country) {
+ contactAddress.country = country;
+ }
+ },
+
+ /**
+ * Method: read_wmc_ContactVoiceTelephone
+ */
+ read_wmc_ContactVoiceTelephone: function(contact, node) {
+ var phone = this.getChildValue(node);
+ if (phone) {
+ contact.phone = phone;
+ }
+ },
+
+ /**
+ * Method: read_wmc_ContactFacsimileTelephone
+ */
+ read_wmc_ContactFacsimileTelephone: function(contact, node) {
+ var fax = this.getChildValue(node);
+ if (fax) {
+ contact.fax = fax;
+ }
+ },
+
+ /**
+ * Method: read_wmc_ContactElectronicMailAddress
+ */
+ read_wmc_ContactElectronicMailAddress: function(contact, node) {
+ var email = this.getChildValue(node);
+ if (email) {
+ contact.email = email;
+ }
+ },
+
+ /**
+ * Method: read_wmc_DataURL
+ */
+ read_wmc_DataURL: function(layerContext, node) {
+ layerContext.dataURL = this.getOnlineResource_href(node);
+ },
+
+ /**
* Method: read_wmc_LegendURL
*/
read_wmc_LegendURL: function(style, node) {
var legend = {
width: node.getAttribute('width'),
- height: node.getAttribute('height')
+ height: node.getAttribute('height'),
+ format: node.getAttribute('format'),
+ href: this.getOnlineResource_href(node)
};
- var links = node.getElementsByTagName("OnlineResource");
- if(links.length > 0) {
- this.read_wmc_OnlineResource(legend, links[0]);
- }
style.legend = legend;
},
/**
+ * Method: read_wmc_DimensionList
+ */
+ read_wmc_DimensionList: function(layerContext, node) {
+ layerContext.dimensions = {};
+ this.runChildNodes(layerContext.dimensions, node);
+ },
+ /**
+ * Method: read_wmc_Dimension
+ */
+ read_wmc_Dimension: function(dimensions, node) {
+ var name = node.getAttribute("name").toLowerCase();
+
+ var dim = {
+ name: name,
+ units: node.getAttribute("units") || "",
+ unitSymbol: node.getAttribute("unitSymbol") || "",
+ userValue: node.getAttribute("userValue") || "",
+ nearestValue: node.getAttribute("nearestValue") === "1",
+ multipleValues: node.getAttribute("multipleValues") === "1",
+ current: node.getAttribute("current") === "1",
+ "default": node.getAttribute("default") || ""
+ };
+ var values = this.getChildValue(node);
+ dim.values = values.split(",");
+
+ dimensions[dim.name] = dim;
+ },
+
+ /**
* Method: write
*
* Parameters:
@@ -514,6 +728,33 @@
"Title", context.title
));
+ // optional KeywordList element
+ if (context.keywords) {
+ node.appendChild(this.write_wmc_KeywordList(context.keywords));
+ }
+
+ // optional Abstract element
+ if (context["abstract"]) {
+ node.appendChild(this.createElementDefaultNS(
+ "Abstract", context["abstract"]
+ ));
+ }
+
+ // Optional LogoURL element
+ if (context.logo) {
+ node.appendChild(this.write_wmc_URLType("LogoURL", context.logo.href, context.logo));
+ }
+
+ // Optional DescriptionURL element
+ if (context.descriptionURL) {
+ node.appendChild(this.write_wmc_URLType("DescriptionURL", context.descriptionURL));
+ }
+
+ // Optional ContactInformation element
+ if (context.contactInformation) {
+ node.appendChild(this.write_wmc_ContactInformation(context.contactInformation));
+ }
+
// OpenLayers specific map properties
node.appendChild(this.write_ol_MapExtension(context));
@@ -521,6 +762,110 @@
},
/**
+ * Method: write_wmc_KeywordList
+ */
+ write_wmc_KeywordList: function(keywords) {
+ var node = this.createElementDefaultNS("KeywordList");
+
+ for (var i=0, len=keywords.length; i<len; i++) {
+ node.appendChild(this.createElementDefaultNS(
+ "Keyword", keywords[i]
+ ));
+ }
+ return node;
+ },
+ /**
+ * Method: write_wmc_ContactInformation
+ */
+ write_wmc_ContactInformation: function(contact) {
+ var node = this.createElementDefaultNS("ContactInformation");
+
+ if (contact.personPrimary) {
+ node.appendChild(this.write_wmc_ContactPersonPrimary(contact.personPrimary));
+ }
+ if (contact.position) {
+ node.appendChild(this.createElementDefaultNS(
+ "ContactPosition", contact.position
+ ));
+ }
+ if (contact.contactAddress) {
+ node.appendChild(this.write_wmc_ContactAddress(contact.contactAddress));
+ }
+ if (contact.phone) {
+ node.appendChild(this.createElementDefaultNS(
+ "ContactVoiceTelephone", contact.phone
+ ));
+ }
+ if (contact.fax) {
+ node.appendChild(this.createElementDefaultNS(
+ "ContactFacsimileTelephone", contact.fax
+ ));
+ }
+ if (contact.email) {
+ node.appendChild(this.createElementDefaultNS(
+ "ContactElectronicMailAddress", contact.email
+ ));
+ }
+ return node;
+ },
+
+ /**
+ * Method: write_wmc_ContactPersonPrimary
+ */
+ write_wmc_ContactPersonPrimary: function(personPrimary) {
+ var node = this.createElementDefaultNS("ContactPersonPrimary");
+ if (personPrimary.person) {
+ node.appendChild(this.createElementDefaultNS(
+ "ContactPerson", personPrimary.person
+ ));
+ }
+ if (personPrimary.organization) {
+ node.appendChild(this.createElementDefaultNS(
+ "ContactOrganization", personPrimary.organization
+ ));
+ }
+ return node;
+ },
+
+ /**
+ * Method: write_wmc_ContactAddress
+ */
+ write_wmc_ContactAddress: function(contactAddress) {
+ var node = this.createElementDefaultNS("ContactAddress");
+ if (contactAddress.type) {
+ node.appendChild(this.createElementDefaultNS(
+ "AddressType", contactAddress.type
+ ));
+ }
+ if (contactAddress.address) {
+ node.appendChild(this.createElementDefaultNS(
+ "Address", contactAddress.address
+ ));
+ }
+ if (contactAddress.city) {
+ node.appendChild(this.createElementDefaultNS(
+ "City", contactAddress.city
+ ));
+ }
+ if (contactAddress.stateOrProvince) {
+ node.appendChild(this.createElementDefaultNS(
+ "StateOrProvince", contactAddress.stateOrProvince
+ ));
+ }
+ if (contactAddress.postcode) {
+ node.appendChild(this.createElementDefaultNS(
+ "PostCode", contactAddress.postcode
+ ));
+ }
+ if (contactAddress.country) {
+ node.appendChild(this.createElementDefaultNS(
+ "Country", contactAddress.country
+ ));
+ }
+ return node;
+ },
+
+ /**
* Method: write_ol_MapExtension
*/
write_ol_MapExtension: function(context) {
@@ -594,9 +939,21 @@
"Title", context.title
));
+ // optional Abstract element
+ if (context["abstract"]) {
+ node.appendChild(this.createElementDefaultNS(
+ "Abstract", context["abstract"]
+ ));
+ }
+
+ // optional DataURL element
+ if (context.dataURL) {
+ node.appendChild(this.write_wmc_URLType("DataURL", context.dataURL));
+ }
+
// optional MetadataURL element
if (context.metadataURL) {
- node.appendChild(this.write_wmc_MetadataURL(context.metadataURL));
+ node.appendChild(this.write_wmc_URLType("MetadataURL", context.metadataURL));
}
return node;
@@ -682,34 +1039,79 @@
* {Element} A WMC Server element node.
*/
write_wmc_Server: function(context) {
+ var server = context.server;
var node = this.createElementDefaultNS("Server");
- this.setAttributes(node, {
+ var attributes = {
service: "OGC:WMS",
- version: context.version
- });
+ version: server.version
+ };
+ if (server.title) {
+ attributes.title = server.title
+ }
+ this.setAttributes(node, attributes);
// required OnlineResource element
- node.appendChild(this.write_wmc_OnlineResource(context.url));
+ node.appendChild(this.write_wmc_OnlineResource(server.url));
return node;
},
/**
- * Method: write_wmc_MetadataURL
- * Create a MetadataURL node given a metadataURL string.
+ * Method: write_wmc_URLType
+ * Create a LogoURL/DescriptionURL/MetadataURL/DataURL/LegendURL node given a object and elementName.
*
* Parameters:
- * metadataURL - {String} MetadataURL string value.
- *
+ * elName - {String} Name of element (LogoURL/DescriptionURL/MetadataURL/LegendURL)
+ * url - {String} URL string value
+ * attr - {Object} Optional attributes (width, height, format)
* Returns:
- * {Element} A WMC metadataURL element node.
+ * {Element} A WMC element node.
*/
- write_wmc_MetadataURL: function(metadataURL) {
- var node = this.createElementDefaultNS("MetadataURL");
+ write_wmc_URLType: function(elName, url, attr) {
+ var node = this.createElementDefaultNS(elName);
+ node.appendChild(this.write_wmc_OnlineResource(url));
+ if (attr) {
+ var optionalAttributes = ["width", "height", "format"];
+ for (var i=0; i<optionalAttributes.length; i++) {
+ if (optionalAttributes[i] in attr) {
+ node.setAttribute(optionalAttributes[i], attr[optionalAttributes[i]]);
+ }
+ }
+ }
+ return node;
+ },
- // required OnlineResource element
- node.appendChild(this.write_wmc_OnlineResource(metadataURL));
+ /**
+ * Method: write_wmc_DimensionList
+ */
+ write_wmc_DimensionList: function(context) {
+ var node = this.createElementDefaultNS("DimensionList");
+ var required_attributes = {
+ name: true,
+ units: true,
+ unitSymbol: true,
+ userValue: true
+ };
+ for (var dim in context.dimensions) {
+ var attributes = {};
+ var dimension = context.dimensions[dim];
+ for (var name in dimension) {
+ if (typeof dimension[name] == "boolean") {
+ attributes[name] = Number(dimension[name]);
+ } else {
+ attributes[name] = dimension[name];
+ }
+ }
+ var values = "";
+ if (attributes.values) {
+ values = attributes.values.join(",");
+ delete attributes.values;
+ }
+ node.appendChild(this.createElementDefaultNS(
+ "Dimension", values, attributes
+ ));
+ }
return node;
},
@@ -769,17 +1171,37 @@
);
if(s.href) { // [1]
sld = this.createElementDefaultNS("SLD");
- var link = this.write_wmc_OnlineResource(s.href);
- sld.appendChild(link);
- // Name is required.
+ // Name is optional.
+ if (s.name) {
sld.appendChild(this.createElementDefaultNS("Name", s.name));
+ }
// Title is optional.
if (s.title) {
sld.appendChild(this.createElementDefaultNS("Title", s.title));
}
+ // LegendURL is optional
+ if (s.legend) {
+ sld.appendChild(this.write_wmc_URLType("LegendURL", s.legend.href, s.legend));
+ }
+
+ var link = this.write_wmc_OnlineResource(s.href);
+ sld.appendChild(link);
style.appendChild(sld);
} else if(s.body) { // [2]
sld = this.createElementDefaultNS("SLD");
+ // Name is optional.
+ if (s.name) {
+ sld.appendChild(this.createElementDefaultNS("Name", s.name));
+ }
+ // Title is optional.
+ if (s.title) {
+ sld.appendChild(this.createElementDefaultNS("Title", s.title));
+ }
+ // LegendURL is optional
+ if (s.legend) {
+ sld.appendChild(this.write_wmc_URLType("LegendURL", s.legend.href, s.legend));
+ }
+
// read in body as xml doc - assume proper namespace declarations
var doc = OpenLayers.Format.XML.prototype.read.apply(this, [s.body]);
// append to StyledLayerDescriptor node
@@ -788,12 +1210,6 @@
imported = sld.ownerDocument.importNode(imported, true);
}
sld.appendChild(imported);
- // Name is required.
- sld.appendChild(this.createElementDefaultNS("Name", s.name));
- // Title is optional.
- if (s.title) {
- sld.appendChild(this.createElementDefaultNS("Title", s.title));
- }
style.appendChild(sld);
} else { // [3]
// both Name and Title are required.
@@ -805,7 +1221,11 @@
"Abstract", s['abstract']
));
}
+ // LegendURL is optional
+ if (s.legend) {
+ style.appendChild(this.write_wmc_URLType("LegendURL", s.legend.href, s.legend));
}
+ }
node.appendChild(style);
}
}
@@ -830,6 +1250,19 @@
return node;
},
+ /**
+ * Method: getOnlineResource_href
+ */
+ getOnlineResource_href: function(node) {
+ var object = {};
+ var links = node.getElementsByTagName("OnlineResource");
+ if(links.length > 0) {
+ this.read_wmc_OnlineResource(object, links[0]);
+ }
+ return object.href;
+ },
+
+
CLASS_NAME: "OpenLayers.Format.WMC.v1"
});
Modified: trunk/openlayers/lib/OpenLayers/Format/WMC/v1_0_0.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/WMC/v1_0_0.js 2011-04-04 17:11:14 UTC (rev 11870)
+++ trunk/openlayers/lib/OpenLayers/Format/WMC/v1_0_0.js 2011-04-04 17:15:14 UTC (rev 11871)
@@ -46,6 +46,20 @@
},
/**
+ * Method: read_wmc_SRS
+ */
+ read_wmc_SRS: function(layerContext, node) {
+ var srs = this.getChildValue(node);
+ if (typeof layerContext.projections != "object") {
+ layerContext.projections = {};
+ }
+ var values = srs.split(/ +/);
+ for (var i=0, len=values.length; i<len; i++) {
+ layerContext.projections[values[i]] = true;
+ }
+ },
+
+ /**
* Method: write_wmc_Layer
* Create a Layer node given a layer context object. This method adds
* elements specific to version 1.0.0.
@@ -61,12 +75,26 @@
this, [context]
);
+ // optional SRS element(s)
+ if (context.srs) {
+ var projections = [];
+ for(var name in context.srs) {
+ projections.push(name);
+ }
+ node.appendChild(this.createElementDefaultNS("SRS", projections.join(" ")));
+ }
+
// optional FormatList element
node.appendChild(this.write_wmc_FormatList(context));
// optional StyleList element
node.appendChild(this.write_wmc_StyleList(context));
+ // optional DimensionList element
+ if (context.dimensions) {
+ node.appendChild(this.write_wmc_DimensionList(layer));
+ }
+
// OpenLayers specific properties go in an Extension element
node.appendChild(this.write_wmc_LayerExtension(context));
},
Modified: trunk/openlayers/lib/OpenLayers/Format/WMC/v1_1_0.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/WMC/v1_1_0.js 2011-04-04 17:11:14 UTC (rev 11870)
+++ trunk/openlayers/lib/OpenLayers/Format/WMC/v1_1_0.js 2011-04-04 17:15:14 UTC (rev 11871)
@@ -77,6 +77,16 @@
},
/**
+ * Method: read_wmc_SRS
+ */
+ read_wmc_SRS: function(layerContext, node) {
+ if (! ("srs" in layerContext)) {
+ layerContext.srs = {};
+ }
+ layerContext.srs[this.getChildValue(node)] = true;
+ },
+
+ /**
* Method: write_wmc_Layer
* Create a Layer node given a layer context object. This method adds
* elements specific to version 1.1.0.
@@ -109,12 +119,24 @@
node.appendChild(maxSD);
}
+ // optional SRS element(s)
+ if (context.srs) {
+ for(var name in context.srs) {
+ node.appendChild(this.createElementDefaultNS("SRS", name));
+ }
+ }
+
// optional FormatList element
node.appendChild(this.write_wmc_FormatList(context));
// optional StyleList element
node.appendChild(this.write_wmc_StyleList(context));
+ // optional DimensionList element
+ if (context.dimensions) {
+ node.appendChild(this.write_wmc_DimensionList(context));
+ }
+
// OpenLayers specific properties go in an Extension element
node.appendChild(this.write_wmc_LayerExtension(context));
Modified: trunk/openlayers/lib/OpenLayers/Format/WMC.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/WMC.js 2011-04-04 17:11:14 UTC (rev 11870)
+++ trunk/openlayers/lib/OpenLayers/Format/WMC.js 2011-04-04 17:15:14 UTC (rev 11871)
@@ -74,9 +74,13 @@
visibility: layer.visibility,
name: layer.params["LAYERS"],
title: layer.name,
+ "abstract": layer.metadata["abstract"],
+ dataURL: layer.metadata.dataURL,
metadataURL: layer.metadataURL,
+ server: {
version: layer.params["VERSION"],
- url: layer.url,
+ url: layer.url
+ },
maxExtent: layer.maxExtent,
transparent: layer.params["TRANSPARENT"],
numZoomLevels: layer.numZoomLevels,
@@ -97,18 +101,54 @@
layer.options.minResolution ||
layer.options.maxScale) ?
layer.maxScale : undefined,
- formats: [{
+ formats: [],
+ styles: [],
+ srs: layer.srs,
+ dimensions: layer.dimensions
+ };
+
+
+ if (layer.metadata.servertitle) {
+ layerContext.server.title = layer.metadata.servertitle;
+ }
+
+ if (layer.metadata.formats && layer.metadata.formats.length > 0) {
+ for (var i=0, len=layer.metadata.formats.length; i<len; i++) {
+ var format = layer.metadata.formats[i];
+ layerContext.formats.push({
+ value: format.value,
+ current: (format.value == layer.params["FORMAT"])
+ });
+ }
+ } else {
+ layerContext.formats.push({
value: layer.params["FORMAT"],
current: true
- }],
- styles: [{
+ });
+ }
+
+ if (layer.metadata.styles && layer.metadata.styles.length > 0) {
+ for (var i=0, len=layer.metadata.styles.length; i<len; i++) {
+ var style = layer.metadata.styles[i];
+ if ((style.href == layer.params["SLD"]) ||
+ (style.body == layer.params["SLD_BODY"]) ||
+ (style.name == layer.params["STYLES"])) {
+ style.current = true;
+ } else {
+ style.current = false;
+ }
+ layerContext.styles.push(style);
+ }
+ } else {
+ layerContext.styles.push({
href: layer.params["SLD"],
body: layer.params["SLD_BODY"],
name: layer.params["STYLES"] || parser.defaultStyleName,
title: parser.defaultStyleTitle,
current: true
- }]
- };
+ });
+ }
+
return layerContext;
},
@@ -126,16 +166,22 @@
toContext: function(obj) {
var context = {};
var layers = obj.layers;
- if(obj.CLASS_NAME == "OpenLayers.Map") {
+ if (obj.CLASS_NAME == "OpenLayers.Map") {
+ var metadata = obj.metadata || {};
+ context.size = obj.getSize();
context.bounds = obj.getExtent();
+ context.projection = obj.projection;
+ context.title = obj.title;
+ context.keywords = metadata.keywords;
+ context["abstract"] = metadata["abstract"];
+ context.logo = metadata.logo;
+ context.descriptionURL = metadata.descriptionURL;
+ context.contactInformation = metadata.contactInformation;
context.maxExtent = obj.maxExtent;
- context.projection = obj.projection;
- context.size = obj.getSize();
- }
- else {
+ } else {
// copy all obj properties except the "layers" property
OpenLayers.Util.applyDefaults(context, obj);
- if(context.layers != undefined) {
+ if (context.layers != undefined) {
delete(context.layers);
}
}
@@ -148,7 +194,7 @@
if (layers != undefined && layers instanceof Array) {
for (var i=0, len=layers.length; i<len; i++) {
var layer = layers[i];
- if(layer instanceof OpenLayers.Layer.WMS) {
+ if (layer instanceof OpenLayers.Layer.WMS) {
context.layersContext.push(this.layerToContext(layer));
}
}
Modified: trunk/openlayers/tests/Format/WMC/v1.html
===================================================================
--- trunk/openlayers/tests/Format/WMC/v1.html 2011-04-04 17:11:14 UTC (rev 11870)
+++ trunk/openlayers/tests/Format/WMC/v1.html 2011-04-04 17:15:14 UTC (rev 11871)
@@ -4,7 +4,7 @@
<script type="text/javascript">
function test_write_wmc_StyleList(t) {
- t.plan(3);
+ t.plan(4);
var layer, layerContext, got, expected;
@@ -39,10 +39,10 @@
"<StyleList xmlns='http://www.opengis.net/context'>" +
"<Style current='1'>" +
"<SLD>" +
+ "<Title>Default</Title>" +
"<OnlineResource xmlns:xlink='http://www.w3.org/1999/xlink' "+
"xlink:type='simple' " +
"xlink:href='http://linked.sld' />" +
- "<Name></Name><Title>Default</Title>" +
"</SLD>" +
"</Style>" +
"</StyleList>";
@@ -88,6 +88,7 @@
"<StyleList xmlns='http://www.opengis.net/context'>" +
"<Style current='1'>" +
"<SLD>" +
+ "<Title>Default</Title>" +
"<sld:StyledLayerDescriptor version='1.0.0' " +
"xmlns:sld='http://www.opengis.net/sld' " +
"xmlns:ogc='http://www.opengis.net/ogc' " +
@@ -115,13 +116,71 @@
"</sld:UserStyle>" +
"</sld:NamedLayer>" +
"</sld:StyledLayerDescriptor>" +
- "<Name></Name><Title>Default</Title>" +
"</SLD>" +
"</Style>" +
"</StyleList>";
t.xml_eq(got, expected, "inline style correctly written");
layer.destroy();
+
+ // test inline FeatureTypeStyle
+ layer = new OpenLayers.Layer.WMS(name, url, {
+ sld_body:
+ "<sld:FeatureTypeStyle version='1.0.0' " +
+ "xmlns:sld='http://www.opengis.net/sld' " +
+ "xmlns:ogc='http://www.opengis.net/ogc' " +
+ "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
+ "xsi:schemaLocation='http://www.opengis.net/sld http://schemas.opengeospatial.net/sld/1.0.0/StyledLayerDescriptor.xsd'>" +
+ "<sld:Rule>" +
+ "<sld:TextSymbolizer>" +
+ "<sld:Label>" +
+ "<ogc:PropertyName>ZONENR</ogc:PropertyName>" +
+ "</sld:Label>" +
+ "<sld:Font>" +
+ "<sld:CssParameter name='font-family'>Arial</sld:CssParameter>" +
+ "<sld:CssParameter name='font-size'>10</sld:CssParameter>" +
+ "</sld:Font>" +
+ "<sld:Fill>" +
+ "<sld:CssParameter name='fill'>#FF9900</sld:CssParameter>" +
+ "</sld:Fill>" +
+ "</sld:TextSymbolizer>" +
+ "</sld:Rule>" +
+ "</sld:FeatureTypeStyle>"
+ });
+
+ layerContext = format.layerToContext(layer);
+ got = parser.write_wmc_StyleList(layerContext);
+ expected =
+ "<StyleList xmlns='http://www.opengis.net/context'>" +
+ "<Style current='1'>" +
+ "<SLD>" +
+ "<Title>Default</Title>" +
+ "<sld:FeatureTypeStyle version='1.0.0' " +
+ "xmlns:sld='http://www.opengis.net/sld' " +
+ "xmlns:ogc='http://www.opengis.net/ogc' " +
+ "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
+ "xsi:schemaLocation='http://www.opengis.net/sld http://schemas.opengeospatial.net/sld/1.0.0/StyledLayerDescriptor.xsd'>" +
+ "<sld:Rule>" +
+ "<sld:TextSymbolizer>" +
+ "<sld:Label>" +
+ "<ogc:PropertyName>ZONENR</ogc:PropertyName>" +
+ "</sld:Label>" +
+ "<sld:Font>" +
+ "<sld:CssParameter name='font-family'>Arial</sld:CssParameter>" +
+ "<sld:CssParameter name='font-size'>10</sld:CssParameter>" +
+ "</sld:Font>" +
+ "<sld:Fill>" +
+ "<sld:CssParameter name='fill'>#FF9900</sld:CssParameter>" +
+ "</sld:Fill>" +
+ "</sld:TextSymbolizer>" +
+ "</sld:Rule>" +
+ "</sld:FeatureTypeStyle>" +
+ "</SLD>" +
+ "</Style>" +
+ "</StyleList>";
+
+ t.xml_eq(got, expected, "inline FeatureTypeStyle correctly written");
+ layer.destroy();
}
function test_read_wmc_StyleList(t) {
Modified: trunk/openlayers/tests/Format/WMC.html
===================================================================
--- trunk/openlayers/tests/Format/WMC.html 2011-04-04 17:11:14 UTC (rev 11870)
+++ trunk/openlayers/tests/Format/WMC.html 2011-04-04 17:15:14 UTC (rev 11871)
@@ -6,9 +6,10 @@
var v1_0_0 = '<ViewContext xmlns="http://www.opengis.net/context" version="1.0.0" id="OpenLayers_Context_233" xsi:schemaLocation="http://www.opengis.net/context http://schemas.opengis.net/context/1.0.0/context.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><General><Window width="512" height="256"/><BoundingBox minx="-109.9709708" miny="27.01451459" maxx="-80.02902918" maxy="41.98548541" SRS="EPSG:4326"/><Title/><Extension><ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="-130.0000000" miny="14.00000000" maxx="-60.00000000" maxy="55.00000000"/></Extension></General><LayerList><Layer queryable="1" hidden="0"><Server service="OGC:WMS" version="1.1.1"><OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://t1.hypercube.telascience.org/cgi-bin/landsat7"/></Server><Name>landsat7</Name><Title>NASA Global Mosaic</Title><FormatList><Format current="1">image/jpeg</Format></FormatList><StyleList><Style current="1"><N
ame/><Title>Default</Title></Style></StyleList><Extension><ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="-130.0000000" miny="14.00000000" maxx="-60.00000000" maxy="55.00000000"/><ol:numZoomLevels xmlns:ol="http://openlayers.org/context">4</ol:numZoomLevels><ol:units xmlns:ol="http://openlayers.org/context">degrees</ol:units><ol:isBaseLayer xmlns:ol="http://openlayers.org/context">true</ol:isBaseLayer><ol:displayInLayerSwitcher xmlns:ol="http://openlayers.org/context">true</ol:displayInLayerSwitcher><ol:singleTile xmlns:ol="http://openlayers.org/context">false</ol:singleTile><ol:tileSize xmlns:ol="http://openlayers.org/context" width="512" height="1024"/></Extension></Layer><Layer queryable="1" hidden="1"><Server service="OGC:WMS" version="1.1.1"><OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://labs.metacarta.com/wms/vmap0"/></Server><Name>basic</Name><Title>OpenLayers WMS</Title><FormatList><Format current="1">im
age/jpeg</Format></FormatList><StyleList><Style current="1"><Name/><Title>Default</Title></Style></StyleList><Extension><ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="-130.0000000" miny="14.00000000" maxx="-60.00000000" maxy="55.00000000"/><ol:numZoomLevels xmlns:ol="http://openlayers.org/context">4</ol:numZoomLevels><ol:units xmlns:ol="http://openlayers.org/context">degrees</ol:units><ol:isBaseLayer xmlns:ol="http://openlayers.org/context">true</ol:isBaseLayer><ol:displayInLayerSwitcher xmlns:ol="http://openlayers.org/context">true</ol:displayInLayerSwitcher><ol:singleTile xmlns:ol="http://openlayers.org/context">false</ol:singleTile></Extension></Layer><Layer queryable="1" hidden="0"><Server service="OGC:WMS" version="1.1.1"><OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://lioapp.lrc.gov.on.ca/cubeserv/cubeserv.pl"/></Server><Name>na_road:CCRS</Name><Title>Transportation Network</Title><FormatList><Format curre
nt="1">image/png</Format></FormatList><StyleList><Style current="1"><Name/><Title>Default</Title></Style></StyleList><Extension><ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="-166.5320000" miny="4.050460000" maxx="-0.2068180000" maxy="70.28700000"/><ol:transparent xmlns:ol="http://openlayers.org/context">TRUE</ol:transparent><ol:numZoomLevels xmlns:ol="http://openlayers.org/context">4</ol:numZoomLevels><ol:units xmlns:ol="http://openlayers.org/context">degrees</ol:units><ol:isBaseLayer xmlns:ol="http://openlayers.org/context">false</ol:isBaseLayer><ol:opacity xmlns:ol="http://openlayers.org/context">0.6</ol:opacity><ol:displayInLayerSwitcher xmlns:ol="http://openlayers.org/context">false</ol:displayInLayerSwitcher><ol:singleTile xmlns:ol="http://openlayers.org/context">false</ol:singleTile></Extension></Layer><Layer queryable="1" hidden="0"><Server service="OGC:WMS" version="1.1.1"><OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" x
link:href="http://columbo.nrlssc.navy.mil/ogcwms/servlet/WMSServlet/AccuWeather_Maps.wms"/></Server><Name>3:1</Name><Title>Radar 3:1</Title><FormatList><Format current="1">image/png</Format></FormatList><StyleList><Style current="1"><Name/><Title>Default</Title></Style></StyleList><Extension><ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="-131.0294952" miny="14.56289673" maxx="-61.02950287" maxy="54.56289673"/><ol:transparent xmlns:ol="http://openlayers.org/context">TRUE</ol:transparent><ol:numZoomLevels xmlns:ol="http://openlayers.org/context">4</ol:numZoomLevels><ol:units xmlns:ol="http://openlayers.org/context">degrees</ol:units><ol:isBaseLayer xmlns:ol="http://openlayers.org/context">false</ol:isBaseLayer><ol:opacity xmlns:ol="http://openlayers.org/context">0.8</ol:opacity><ol:displayInLayerSwitcher xmlns:ol="http://openlayers.org/context">false</ol:displayInLayerSwitcher><ol:singleTile xmlns:ol="http://openlayers.org/context">true</ol:singleTile></Extension
></Layer></LayerList></ViewContext>';
var v1_1_0 = '<ViewContext xmlns="http://www.opengis.net/context" version="1.1.0" id="OpenLayers_Context_232" xsi:schemaLocation="http://www.opengis.net/context http://schemas.opengis.net/context/1.1.0/context.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><General><Window width="512" height="256"/><BoundingBox minx="-109.9709708" miny="27.01451459" maxx="-80.02902918" maxy="41.98548541" SRS="EPSG:4326"/><Title/><Extension><ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="-130.0000000" miny="14.00000000" maxx="-60.00000000" maxy="55.00000000"/></Extension></General><LayerList><Layer queryable="1" hidden="0"><Server service="OGC:WMS" version="1.1.1"><OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://t1.hypercube.telascience.org/cgi-bin/landsat7"/></Server><Name>landsat7</Name><Title>NASA Global Mosaic</Title><sld:MinScaleDenominator xmlns:sld="http://www.opengis.net/sld">6299645.760</sld:MinScaleDenomin
ator><sld:MaxScaleDenominator xmlns:sld="http://www.opengis.net/sld">31498228.80</sld:MaxScaleDenominator><FormatList><Format current="1">image/jpeg</Format></FormatList><StyleList><Style current="1"><Name/><Title>Default</Title></Style></StyleList><Extension><ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="-130.0000000" miny="14.00000000" maxx="-60.00000000" maxy="55.00000000"/><ol:tileSize xmlns:ol="http://openlayers.org/context" width="512" height="1024"/><ol:numZoomLevels xmlns:ol="http://openlayers.org/context">4</ol:numZoomLevels><ol:units xmlns:ol="http://openlayers.org/context">degrees</ol:units><ol:isBaseLayer xmlns:ol="http://openlayers.org/context">true</ol:isBaseLayer><ol:displayInLayerSwitcher xmlns:ol="http://openlayers.org/context">true</ol:displayInLayerSwitcher><ol:singleTile xmlns:ol="http://openlayers.org/context">false</ol:singleTile></Extension></Layer><Layer queryable="1" hidden="1"><Server service="OGC:WMS" version="1.1.1"><OnlineResource x
link:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://labs.metacarta.com/wms/vmap0"/></Server><Name>basic</Name><Title>OpenLayers WMS</Title><sld:MinScaleDenominator xmlns:sld="http://www.opengis.net/sld">6299645.760</sld:MinScaleDenominator><sld:MaxScaleDenominator xmlns:sld="http://www.opengis.net/sld">31498228.80</sld:MaxScaleDenominator><FormatList><Format current="1">image/jpeg</Format></FormatList><StyleList><Style current="1"><Name/><Title>Default</Title></Style></StyleList><Extension><ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="-130.0000000" miny="14.00000000" maxx="-60.00000000" maxy="55.00000000"/><ol:tileSize xmlns:ol="http://openlayers.org/context" width="512" height="1024"/><ol:numZoomLevels xmlns:ol="http://openlayers.org/context">4</ol:numZoomLevels><ol:units xmlns:ol="http://openlayers.org/context">degrees</ol:units><ol:isBaseLayer xmlns:ol="http://openlayers.org/context">true</ol:isBaseLayer><ol:displayInLayerSwitch
er xmlns:ol="http://openlayers.org/context">true</ol:displayInLayerSwitcher><ol:singleTile xmlns:ol="http://openlayers.org/context">false</ol:singleTile></Extension></Layer><Layer queryable="1" hidden="0"><Server service="OGC:WMS" version="1.1.1"><OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://lioapp.lrc.gov.on.ca/cubeserv/cubeserv.pl"/></Server><Name>na_road:CCRS</Name><Title>Transportation Network</Title><sld:MinScaleDenominator xmlns:sld="http://www.opengis.net/sld">6200000.000</sld:MinScaleDenominator><sld:MaxScaleDenominator xmlns:sld="http://www.opengis.net/sld">32000000.00</sld:MaxScaleDenominator><FormatList><Format current="1">image/png</Format></FormatList><StyleList><Style current="1"><Name/><Title>Default</Title></Style></StyleList><Extension><ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="-166.5320000" miny="4.050460000" maxx="-0.2068180000" maxy="70.28700000"/><ol:tileSize xmlns:ol="http://openlayer
s.org/context" width="512" height="1024"/><ol:transparent xmlns:ol="http://openlayers.org/context">TRUE</ol:transparent><ol:numZoomLevels xmlns:ol="http://openlayers.org/context">4</ol:numZoomLevels><ol:units xmlns:ol="http://openlayers.org/context">degrees</ol:units><ol:isBaseLayer xmlns:ol="http://openlayers.org/context">false</ol:isBaseLayer><ol:opacity xmlns:ol="http://openlayers.org/context">0.6</ol:opacity><ol:displayInLayerSwitcher xmlns:ol="http://openlayers.org/context">false</ol:displayInLayerSwitcher><ol:singleTile xmlns:ol="http://openlayers.org/context">false</ol:singleTile></Extension></Layer><Layer queryable="1" hidden="0"><Server service="OGC:WMS" version="1.1.1"><OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://columbo.nrlssc.navy.mil/ogcwms/servlet/WMSServlet/AccuWeather_Maps.wms"/></Server><Name>3:1</Name><Title>Radar 3:1</Title><sld:MinScaleDenominator xmlns:sld="http://www.opengis.net/sld">6299645.760</sld:
MinScaleDenominator><sld:MaxScaleDenominator xmlns:sld="http://www.opengis.net/sld">31498228.80</sld:MaxScaleDenominator><FormatList><Format current="1">image/png</Format></FormatList><StyleList><Style current="1"><Name/><Title>Default</Title></Style></StyleList><Extension><ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="-131.0294952" miny="14.56289673" maxx="-61.02950287" maxy="54.56289673"/><ol:transparent xmlns:ol="http://openlayers.org/context">TRUE</ol:transparent><ol:numZoomLevels xmlns:ol="http://openlayers.org/context">4</ol:numZoomLevels><ol:units xmlns:ol="http://openlayers.org/context">degrees</ol:units><ol:isBaseLayer xmlns:ol="http://openlayers.org/context">false</ol:isBaseLayer><ol:opacity xmlns:ol="http://openlayers.org/context">0.8</ol:opacity><ol:displayInLayerSwitcher xmlns:ol="http://openlayers.org/context">true</ol:displayInLayerSwitcher><ol:singleTile xmlns:ol="http://openlayers.org/context">true</ol:singleTile></Extension></Layer></LayerList
></ViewContext>';
var polar = '<ViewContext xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:default="http://www.opengis.net/context" xmlns:ol="http://openlayers.org/context" xmlns="http://www.opengis.net/context" xmlns:wms="http://www.opengis.net/wms" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1.0" id="OpenLayers_Context_466" xsi:schemaLocation="http://www.opengis.net/context http://schemas.opengis.net/context/1.1.0/context.xsd"><General><BoundingBox minx="-3000000" miny="-3000000" maxx="7000000" maxy="7000000" SRS="EPSG:32661"/><Title>WMS viewer</Title><Extension><ol:maxExtent minx="-3000000" miny="-3000000" maxx="7000000" maxy="7000000"/><ol:units>m</ol:units></Extension></General><LayerList xmlns="http://www.opengis.net/context"><Layer queryable="0" hidden="0"><Server service="OGC:WMS" version="1.1.1" foo="bar"><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://wms.met.no/maps/northpole.map"/></Server><Name>world</Na
me><Title>The World</Title><FormatList><Format>image/jpeg</Format><Format current="1">image/png</Format></FormatList></Layer></LayerList></ViewContext>';
+ var fulldoc = '<ViewContext xmlns="http://www.opengis.net/context" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sld="http://www.opengis.net/sld" version="1.1.0" id="eos_data_gateways" xsi:schemaLocation="http://www.opengis.net/context context.xsd"><General><Window width="500" height="300"/><BoundingBox SRS="EPSG:4326" minx="-180.000000" miny="-90.000000" maxx="180.000000" maxy="90.000000"/><Title>EOS Data Gateways</Title><KeywordList><Keyword>EOS</Keyword><Keyword>EOSDIS</Keyword><Keyword>NASA</Keyword><Keyword>CCRS</Keyword><Keyword>CEOS</Keyword><Keyword>OGC</Keyword></KeywordList><Abstract>Map View of EOSDIS partners locations</Abstract><LogoURL width="130" height="74" format="image/gif"><OnlineResource xlink:type="simple" xlink:href="http://redhook.gsfc.nasa.gov/~imswww/pub/icons/logo.gif"/></LogoURL><DescriptionURL format="text/html"><OnlineResource xlink:type="simple" xlink:href="http://eos.nasa.gov/imswelco
me"/></DescriptionURL><ContactInformation><ContactPersonPrimary><ContactPerson>Tom Kralidis</ContactPerson><ContactOrganization>Environment Canada</ContactOrganization></ContactPersonPrimary><ContactPosition>Systems Scientist</ContactPosition><ContactAddress><AddressType>postal</AddressType><Address>867 Lakeshore Road</Address><City>Burlington</City><StateOrProvince>Ontario</StateOrProvince><PostCode>L7R 4A6</PostCode><Country>Canada</Country></ContactAddress><ContactVoiceTelephone>+01-905-336-4409</ContactVoiceTelephone><ContactFacsimileTelephone>+01-905-336-4499</ContactFacsimileTelephone><ContactElectronicMailAddress>tom.kralidis at ec.gc.ca</ContactElectronicMailAddress></ContactInformation></General><LayerList><Layer queryable="1" hidden="0"><Server service="OGC:WMS" version="1.1.1" title="ESA CubeSERV"><OnlineResource xlink:type="simple" xlink:href="http://mapserv2.esrin.esa.it/cubestor/cubeserv/cubeserv.cgi"/></Server><Name>WORLD_MODIS_1KM:MapAdmin</Name><Title>WORLD_MOD
IS_1KM</Title><Abstract>Global maps derived from various Earth Observation sensors / WORLD_MODIS_1KM:MapAdmin</Abstract><SRS>EPSG:4326</SRS><FormatList><Format current="1">image/png</Format><Format>image/gif</Format><Format>image/jpeg</Format></FormatList><StyleList><Style current="1"><Name>default</Name><Title>default</Title><LegendURL width="16" height="16" format="image/gif"><OnlineResource xlink:type="simple" xlink:href="http://mapserv2.esrin.esa.it/cubestor/cubeserv/cubeserv.cgi?version=1.1.1&request=GetLegendGraphic&layer=WORLD_MODIS_1KM:MapAdmin&style=default&format=image/gif"/></LegendURL></Style></StyleList></Layer><Layer queryable="0" hidden="0"><Server service="OGC:WMS" version="1.1.1" title="The GLOBE Program Visualization Server"><OnlineResource xlink:type="simple" xlink:href="http://globe.digitalearth.gov/viz-bin/wmt.cgi"/></Server><Name>COASTLINES</Name><Title>Coastlines</Title><Abstract>Context layer: Coastlines</Abstract><SRS>EPSG:4326</SRS><
SRS>EPSG:900913</SRS><FormatList><Format current="1">image/gif</Format><Format>image/png</Format></FormatList><StyleList><Style current="1"><Name>default</Name><Title>Default</Title><LegendURL width="180" format="image/gif" height="50"><OnlineResource xlink:type="simple" xlink:href="http://globe.digitalearth.gov/globe/en/icons/colorbars/COASTLINES.gif"/></LegendURL></Style></StyleList><DimensionList><Dimension name="time" units="ISO8601" nearestValue="1">2011-03-31,2011-04-01</Dimension></DimensionList></Layer><Layer queryable="1" hidden="0"><Server service="OGC:WMS" version="1.1.1" title="The GLOBE Program Visualization Server"><OnlineResource xlink:type="simple" xlink:href="http://globe.digitalearth.gov/viz-bin/wmt.cgi"/></Server><Name>NATIONAL</Name><Title>National Boundaries</Title><Abstract>Context layer: National Boundaries</Abstract><DataURL><OnlineResource xlink:type="simple" xlink:href="http://globe.digitalearth.gov/data/national.gml"/></DataURL><MetadataURL><Online
Resource xlink:type="simple" xlink:href="http://globe.digitalearth.gov/metadata/national.txt"/></MetadataURL><SRS>EPSG:4326</SRS><FormatList><Format current="1">image/gif</Format><Format>image/png</Format></FormatList><StyleList><Style current="1"><Name>default</Name><Title>Default</Title><LegendURL width="180" format="image/gif" height="50"><OnlineResource xlink:type="simple" xlink:href="http://globe.digitalearth.gov/globe/en/icons/colorbars/NATIONAL.gif"/></LegendURL></Style></StyleList></Layer><Layer queryable="1" hidden="0"><Server service="OGC:WMS" version="1.1.1" title="Canada Centre for Remote Sensing Web Map Service"><OnlineResource xlink:type="simple" xlink:href="http://ceoware2.ccrs.nrcan.gc.ca/cubewerx/cubeserv/cubeserv.cgi"/></Server><Name>EOS_DATA_GATEWAYS:CEOWARE2</Name><Title>EOS Data Gateways</Title><Abstract>Locations of EOS Data Gateway Locations. The same services and data are available through each gateway location.</Abstract><sld:MinScaleDenominator>1000
</sld:MinScaleDenominator><sld:MaxScaleDenominator>500000</sld:MaxScaleDenominator><SRS>EPSG:4326</SRS><FormatList><Format current="1">image/gif</Format><Format>image/png</Format><Format>image/jpeg</Format></FormatList><StyleList><Style current="1"><Name>default</Name><Title>default</Title><LegendURL width="16" height="16" format="image/gif"><OnlineResource xlink:type="simple" xlink:href="http://ceoware2.ccrs.nrcan.gc.ca/cubewerx/cubeserv/cubeserv.cgi?version=1.1.1&request=GetLegendGraphic&layer=EOS_DATA_GATEWAYS:CEOWARE2&style=default&format=image/gif"/></LegendURL></Style><Style><SLD><Title>Default</Title><sld:StyledLayerDescriptor xmlns:ogc="http://www.opengis.net/ogc" xmlns:sld="http://www.opengis.net/sld" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengeospatial.net/sld/1.0.0/StyledLayerDescriptor.xsd"><sld:NamedLayer><sld:Name>AAA212</sld:Name><sld:UserStyle><sld:Fe
atureTypeStyle><sld:Rule><sld:TextSymbolizer><sld:Label><ogc:PropertyName>ZONENR</ogc:PropertyName></sld:Label><sld:Font><sld:CssParameter name="font-family">Arial</sld:CssParameter><sld:CssParameter name="font-size">10</sld:CssParameter></sld:Font><sld:Fill><sld:CssParameter name="fill">#FF9900</sld:CssParameter></sld:Fill></sld:TextSymbolizer></sld:Rule></sld:FeatureTypeStyle></sld:UserStyle></sld:NamedLayer></sld:StyledLayerDescriptor></SLD></Style><Style><SLD><Title>Default</Title><sld:FeatureTypeStyle xmlns:ogc="http://www.opengis.net/ogc" xmlns:sld="http://www.opengis.net/sld" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengeospatial.net/sld/1.0.0/StyledLayerDescriptor.xsd"><sld:Rule><sld:TextSymbolizer><sld:Label><PropertyName>ZONENR</PropertyName></sld:Label><sld:Font><sld:CssParameter name="font-family">Arial</sld:CssParameter><sld:CssParameter name="font-size">10</sld:CssParame
ter></sld:Font><sld:Fill><sld:CssParameter name="fill">#FF9900</sld:CssParameter></sld:Fill></sld:TextSymbolizer></sld:Rule></sld:FeatureTypeStyle></SLD></Style></StyleList></Layer></LayerList></ViewContext>';
function test_Format_WMC_read(t) {
- t.plan(37);
+ t.plan(64);
var format = new OpenLayers.Format.WMC();
var map, layer;
@@ -104,6 +105,89 @@
"mapOptions correctly passed to the created map object");
map.destroy();
+ map = format.read(fulldoc, {map: "map"});
+
+ var meta = map.metadata;
+
+ // Check if ContextInformation is set properly
+ var cinfo = meta.contactInformation;
+
+ t.eq(cinfo.personPrimary.person, "Tom Kralidis", "got correct person");
+ t.eq(cinfo.personPrimary.organization, "Environment Canada", "got correct organization");
+
+ t.eq(cinfo.contactAddress.address, "867 Lakeshore Road", "got correct address");
+ t.eq(cinfo.contactAddress.city, "Burlington", "got correct city");
+ t.eq(cinfo.contactAddress.country, "Canada", "got correct country");
+ t.eq(cinfo.contactAddress.postcode, "L7R 4A6", "got correct postcode");
+ t.eq(cinfo.contactAddress.stateOrProvince, "Ontario", "got correct stateOrProvince");
+ t.eq(cinfo.contactAddress.type, "postal", "got correct address type");
+
+ t.eq(cinfo.email, "tom.kralidis at ec.gc.ca", "got correct email");
+ t.eq(cinfo.fax, "+01-905-336-4499", "got correct fax number");
+ t.eq(cinfo.phone, "+01-905-336-4409", "got correct phone number");
+ t.eq(cinfo.position, "Systems Scientist", "got correct position");
+
+ // Check if LogoURL is read properly
+ var logo = meta.logo;
+ t.eq(logo, {
+ href: "http://redhook.gsfc.nasa.gov/~imswww/pub/icons/logo.gif",
+ width: "130",
+ height: "74",
+ format: "image/gif"},
+ "got currect logo");
+
+ t.eq(meta.descriptionURL, "http://eos.nasa.gov/imswelcome", "got correct descriptionURL");
+
+ t.eq(meta.keywords,
+ ["EOS", "EOSDIS", "NASA", "CCRS", "CEOS", "OGC"],
+ "got correct keywords");
+
+ layer = map.layers[1];
+
+ t.eq(layer.metadata.servertitle,
+ "The GLOBE Program Visualization Server",
+ "got correct title for server");
+
+ t.eq(layer.srs,
+ {"EPSG:4326": true, "EPSG:900913": true},
+ "SRS read correctly");
+
+ t.eq(layer.metadata.formats,
+ [{value: "image/gif", current: true},
+ {value: "image/png"}],
+ "formats read correctly");
+
+ var style = layer.metadata.styles[0];
+ t.eq(style.legend, {
+ href: "http://globe.digitalearth.gov/globe/en/icons/colorbars/COASTLINES.gif",
+ width: "180",
+ height: "50",
+ format: "image/gif"},
+ "got currect legend");
+
+
+ var dim = layer.dimensions["time"];
+ t.eq(dim.name, "time", "got correct name of dimension");
+ t.eq(dim.units, "ISO8601", "got correct units for dimension");
+ t.eq(dim.nearestValue, true, "got correct value for nearestValue");
+ t.eq(dim.values, ["2011-03-31", "2011-04-01"], "got correct values for dimension");
+
+ layer = map.layers[2];
+ t.eq(layer.metadata.dataURL,
+ "http://globe.digitalearth.gov/data/national.gml",
+ "got correct dataURL");
+ t.eq(layer.metadataURL,
+ "http://globe.digitalearth.gov/metadata/national.txt",
+ "got correct metadataURL");
+
+ layer = map.layers[3];
+ var sld_body = '<sld:StyledLayerDescriptor xmlns:ogc="http://www.opengis.net/ogc" xmlns:sld="http://www.opengis.net/sld" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengeospatial.net/sld/1.0.0/StyledLayerDescriptor.xsd"><sld:NamedLayer><sld:Name>AAA212</sld:Name><sld:UserStyle><sld:FeatureTypeStyle><sld:Rule><sld:TextSymbolizer><sld:Label><ogc:PropertyName>ZONENR</ogc:PropertyName></sld:Label><sld:Font><sld:CssParameter name="font-family">Arial</sld:CssParameter><sld:CssParameter name="font-size">10</sld:CssParameter></sld:Font><sld:Fill><sld:CssParameter name="fill">#FF9900</sld:CssParameter></sld:Fill></sld:TextSymbolizer></sld:Rule></sld:FeatureTypeStyle></sld:UserStyle></sld:NamedLayer></sld:StyledLayerDescriptor>';
+ var styles = layer.metadata.styles;
+ t.xml_eq(styles[1].body, sld_body, "StyledLayerDescriptor body read correctly");
+
+ sld_body = '<sld:FeatureTypeStyle xmlns:ogc="http://www.opengis.net/ogc" xmlns:sld="http://www.opengis.net/sld" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengeospatial.net/sld/1.0.0/StyledLayerDescriptor.xsd"><sld:Rule><sld:TextSymbolizer><sld:Label><PropertyName xmlns="http://www.opengis.net/context">ZONENR</PropertyName></sld:Label><sld:Font><sld:CssParameter name="font-family">Arial</sld:CssParameter><sld:CssParameter name="font-size">10</sld:CssParameter></sld:Font><sld:Fill><sld:CssParameter name="fill">#FF9900</sld:CssParameter></sld:Fill></sld:TextSymbolizer></sld:Rule></sld:FeatureTypeStyle>';
+ t.xml_eq(styles[2].body, sld_body, "FeatureTypeStyle body read correctly");
+
}
function test_Format_WMC_write(t) {
@@ -141,7 +225,7 @@
t.plan(0);
t.debug_print("WMC writing works but is not tested in Opera");
} else {
- t.plan(1);
+ t.plan(11);
map = format.read(v1_1_0, {map: "map"});
wmc = format.write(map);
@@ -149,7 +233,78 @@
"(v1.1.0) write gives what read got");
map.destroy();
+ var parser = format.getParser("1.1.0");
+ map = format.read(fulldoc, {map: "map"});
+ var context = format.toContext(map);
+
+ // KeywordList
+ var expected = '<KeywordList xmlns="http://www.opengis.net/context"><Keyword>EOS</Keyword><Keyword>EOSDIS</Keyword><Keyword>NASA</Keyword><Keyword>CCRS</Keyword><Keyword>CEOS</Keyword><Keyword>OGC</Keyword></KeywordList>';
+ t.xml_eq(parser.write_wmc_KeywordList(context.keywords),
+ expected,
+ "keywordlist written correctly");
+
+ // ContactInformation
+ expected = '<ContactInformation xmlns="http://www.opengis.net/context"><ContactPersonPrimary><ContactPerson>Tom Kralidis</ContactPerson><ContactOrganization>Environment Canada</ContactOrganization></ContactPersonPrimary><ContactPosition>Systems Scientist</ContactPosition><ContactAddress><AddressType>postal</AddressType><Address>867 Lakeshore Road</Address><City>Burlington</City><StateOrProvince>Ontario</StateOrProvince><PostCode>L7R 4A6</PostCode><Country>Canada</Country></ContactAddress><ContactVoiceTelephone>+01-905-336-4409</ContactVoiceTelephone><ContactFacsimileTelephone>+01-905-336-4499</ContactFacsimileTelephone><ContactElectronicMailAddress>tom.kralidis at ec.gc.ca</ContactElectronicMailAddress></ContactInformation>';
+ t.xml_eq(parser.write_wmc_ContactInformation(context.contactInformation),
+ expected,
+ "contactInformation written correctly");
+
+ // LogoURL
+ expected = '<LogoURL xmlns="http://www.opengis.net/context" width="130" height="74" format="image/gif"><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://redhook.gsfc.nasa.gov/~imswww/pub/icons/logo.gif"/></LogoURL>';
+ t.xml_eq(parser.write_wmc_URLType("LogoURL", context.logo.href, context.logo),
+ expected,
+ "LogoURL written correctly");
+
+ // DescriptionURL
+ expected = '<DescriptionURL xmlns="http://www.opengis.net/context"><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://eos.nasa.gov/imswelcome"/></DescriptionURL>';
+ t.xml_eq(parser.write_wmc_URLType("DescriptionURL", context.descriptionURL),
+ expected,
+ "DescriptionURL written correctly");
+
+
+ var layerContext = context.layersContext[1];
+
+ // Server
+ expected = '<Server xmlns="http://www.opengis.net/context" service="OGC:WMS" version="1.1.1" title="The GLOBE Program Visualization Server"><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://globe.digitalearth.gov/viz-bin/wmt.cgi"/></Server>';
+ t.xml_eq(parser.write_wmc_Server(layerContext),
+ expected,
+ "Server written correctly");
+
+ // FormatList
+ expected = '<FormatList xmlns="http://www.opengis.net/context"><Format current="1">image/gif</Format><Format>image/png</Format></FormatList>';
+ t.xml_eq(parser.write_wmc_FormatList(layerContext),
+ expected,
+ "FormatList written correctly");
+
+ // DimensionList
+ expected = '<DimensionList xmlns="http://www.opengis.net/context"><Dimension name="time" units="ISO8601" nearestValue="1" unitSymbol="" userValue="" multipleValues="0" current="0" default="">2011-03-31,2011-04-01</Dimension></DimensionList>';
+ t.xml_eq(parser.write_wmc_DimensionList(layerContext),
+ expected,
+ "DimensionList written correctly");
+
+ // LegendURL
+ var legend = layerContext.styles[0].legend;
+ expected = '<LegendURL xmlns="http://www.opengis.net/context" width="180" format="image/gif" height="50"><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://globe.digitalearth.gov/globe/en/icons/colorbars/COASTLINES.gif"/></LegendURL>';
+ t.xml_eq(parser.write_wmc_URLType("LegendURL", legend.href, legend),
+ expected,
+ "LegendURL written correctly");
+
+ layerContext = context.layersContext[2];
+
+ // DataURL
+ expected = '<DataURL xmlns="http://www.opengis.net/context"><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://globe.digitalearth.gov/data/national.gml" /></DataURL>';
+ t.xml_eq(parser.write_wmc_URLType("DataURL", layerContext.dataURL),
+ expected,
+ "DataURL written correctly");
+
+ // MetadataURL
+ expected = '<MetadataURL xmlns="http://www.opengis.net/context"><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://globe.digitalearth.gov/metadata/national.txt" /></MetadataURL>';
+ t.xml_eq(parser.write_wmc_URLType("MetadataURL", layerContext.metadataURL),
+ expected,
+ "MetadataURL written correctly");
+
}
+
}
</script>
More information about the Commits
mailing list