diff --git a/lib/OpenLayers/Format/Context.js b/lib/OpenLayers/Format/Context.js index 26e875e386..d572a39b59 100644 --- a/lib/OpenLayers/Format/Context.js +++ b/lib/OpenLayers/Format/Context.js @@ -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( diff --git a/lib/OpenLayers/Format/WMC.js b/lib/OpenLayers/Format/WMC.js index 3b2da37d5f..336532ed60 100644 --- a/lib/OpenLayers/Format/WMC.js +++ b/lib/OpenLayers/Format/WMC.js @@ -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 0) { + for (var i=0, len=layer.metadata.styles.length; i 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 0) { + this.read_wmc_OnlineResource(object, links[0]); + } + return object.href; + }, + + CLASS_NAME: "OpenLayers.Format.WMC.v1" }); diff --git a/lib/OpenLayers/Format/WMC/v1_0_0.js b/lib/OpenLayers/Format/WMC/v1_0_0.js index 005b0639ce..6fd9c024bf 100644 --- a/lib/OpenLayers/Format/WMC/v1_0_0.js +++ b/lib/OpenLayers/Format/WMC/v1_0_0.js @@ -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 diff --git a/tests/Format/WMC/v1.html b/tests/Format/WMC/v1.html index e64c30679a..05e60785fe 100644 --- a/tests/Format/WMC/v1.html +++ b/tests/Format/WMC/v1.html @@ -4,7 +4,7 @@