Enhancements to the WMC parser for better contact information, SRS, and style support. p=trondmm, r=me (closes #3236)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@11871 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -122,7 +122,11 @@ OpenLayers.Format.Context = OpenLayers.Class({
|
||||
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 @@ OpenLayers.Format.Context = OpenLayers.Class({
|
||||
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 @@ OpenLayers.Format.Context = OpenLayers.Class({
|
||||
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(
|
||||
|
||||
@@ -74,9 +74,13 @@ OpenLayers.Format.WMC = OpenLayers.Class(OpenLayers.Format.Context, {
|
||||
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 @@ OpenLayers.Format.WMC = OpenLayers.Class(OpenLayers.Format.Context, {
|
||||
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 @@ OpenLayers.Format.WMC = OpenLayers.Class(OpenLayers.Format.Context, {
|
||||
toContext: function(obj) {
|
||||
var context = {};
|
||||
var layers = obj.layers;
|
||||
if(obj.CLASS_NAME == "OpenLayers.Map") {
|
||||
context.bounds = obj.getExtent();
|
||||
context.maxExtent = obj.maxExtent;
|
||||
context.projection = obj.projection;
|
||||
if (obj.CLASS_NAME == "OpenLayers.Map") {
|
||||
var metadata = obj.metadata || {};
|
||||
context.size = obj.getSize();
|
||||
}
|
||||
else {
|
||||
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;
|
||||
} 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 @@ OpenLayers.Format.WMC = OpenLayers.Class(OpenLayers.Format.Context, {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +171,8 @@ OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
visibility: (node.getAttribute("hidden") != "1"),
|
||||
queryable: (node.getAttribute("queryable") == "1"),
|
||||
formats: [],
|
||||
styles: []
|
||||
styles: [],
|
||||
metadata: {}
|
||||
};
|
||||
|
||||
this.runChildNodes(layerContext, node);
|
||||
@@ -259,12 +260,8 @@ OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
*/
|
||||
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 @@ OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
},
|
||||
|
||||
/**
|
||||
* 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 @@ OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
* 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 @@ OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
},
|
||||
|
||||
/**
|
||||
* 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 @@ OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
"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 @@ OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
},
|
||||
|
||||
/**
|
||||
* 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 @@ OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
"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 @@ OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
* {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 @@ OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
);
|
||||
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 @@ OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
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 @@ OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
"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 @@ OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
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"
|
||||
|
||||
});
|
||||
|
||||
@@ -45,6 +45,20 @@ OpenLayers.Format.WMC.v1_0_0 = OpenLayers.Class(
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -61,12 +75,26 @@ OpenLayers.Format.WMC.v1_0_0 = OpenLayers.Class(
|
||||
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));
|
||||
},
|
||||
|
||||
@@ -76,6 +76,16 @@ OpenLayers.Format.WMC.v1_1_0 = OpenLayers.Class(
|
||||
layerContext.minScale = parseFloat(this.getChildValue(node));
|
||||
},
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -109,12 +119,24 @@ OpenLayers.Format.WMC.v1_1_0 = OpenLayers.Class(
|
||||
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));
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user