| 761 | | /** |
|---|
| 762 | | * @requires OpenLayers/Format/XML.js |
|---|
| 763 | | */ |
|---|
| 764 | | |
|---|
| 765 | | /** |
|---|
| 766 | | * Class: OpenLayers.Format.WMC.v1 |
|---|
| 767 | | * Superclass for WMC version 1 parsers. |
|---|
| 768 | | * |
|---|
| 769 | | * Inherits from: |
|---|
| 770 | | * - <OpenLayers.Format.XML> |
|---|
| 771 | | */ |
|---|
| 772 | | OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, { |
|---|
| 773 | | |
|---|
| 774 | | /** |
|---|
| 775 | | * Property: namespaces |
|---|
| 776 | | * {Object} Mapping of namespace aliases to namespace URIs. |
|---|
| 777 | | */ |
|---|
| 778 | | namespaces: { |
|---|
| 779 | | ol: "http://openlayers.org/context", |
|---|
| 780 | | wmc: "http://www.opengis.net/context", |
|---|
| 781 | | sld: "http://www.opengis.net/sld", |
|---|
| 782 | | xlink: "http://www.w3.org/1999/xlink", |
|---|
| 783 | | xsi: "http://www.w3.org/2001/XMLSchema-instance" |
|---|
| 784 | | }, |
|---|
| 785 | | |
|---|
| 786 | | /** |
|---|
| 787 | | * Property: schemaLocation |
|---|
| 788 | | * {String} Schema location for a particular minor version. |
|---|
| 789 | | */ |
|---|
| 790 | | schemaLocation: "", |
|---|
| 791 | | |
|---|
| 792 | | /** |
|---|
| 793 | | * Method: getNamespacePrefix |
|---|
| 794 | | * Get the namespace prefix for a given uri from the <namespaces> object. |
|---|
| 795 | | * |
|---|
| 796 | | * Returns: |
|---|
| 797 | | * {String} A namespace prefix or null if none found. |
|---|
| 798 | | */ |
|---|
| 799 | | getNamespacePrefix: function(uri) { |
|---|
| 800 | | var prefix = null; |
|---|
| 801 | | if(uri == null) { |
|---|
| 802 | | prefix = this.namespaces[this.defaultPrefix]; |
|---|
| 803 | | } else { |
|---|
| 804 | | for(prefix in this.namespaces) { |
|---|
| 805 | | if(this.namespaces[prefix] == uri) { |
|---|
| 806 | | break; |
|---|
| 807 | | } |
|---|
| 808 | | } |
|---|
| 809 | | } |
|---|
| 810 | | return prefix; |
|---|
| 811 | | }, |
|---|
| 812 | | |
|---|
| 813 | | /** |
|---|
| 814 | | * Property: defaultPrefix |
|---|
| 815 | | */ |
|---|
| 816 | | defaultPrefix: "wmc", |
|---|
| 817 | | |
|---|
| 818 | | /** |
|---|
| 819 | | * Property: rootPrefix |
|---|
| 820 | | * {String} Prefix on the root node that maps to the context namespace URI. |
|---|
| 821 | | */ |
|---|
| 822 | | rootPrefix: null, |
|---|
| 823 | | |
|---|
| 824 | | /** |
|---|
| 825 | | * Property: defaultStyleName |
|---|
| 826 | | * {String} Style name used if layer has no style param. Default is "". |
|---|
| 827 | | */ |
|---|
| 828 | | defaultStyleName: "", |
|---|
| 829 | | |
|---|
| 830 | | /** |
|---|
| 831 | | * Property: defaultStyleTitle |
|---|
| 832 | | * {String} Default style title. Default is "Default". |
|---|
| 833 | | */ |
|---|
| 834 | | defaultStyleTitle: "Default", |
|---|
| 835 | | |
|---|
| 836 | | /** |
|---|
| 837 | | * Constructor: OpenLayers.Format.WMC.v1 |
|---|
| 838 | | * Instances of this class are not created directly. Use the |
|---|
| 839 | | * <OpenLayers.Format.WMC> constructor instead. |
|---|
| 840 | | * |
|---|
| 841 | | * Parameters: |
|---|
| 842 | | * options - {Object} An optional object whose properties will be set on |
|---|
| 843 | | * this instance. |
|---|
| 844 | | */ |
|---|
| 845 | | initialize: function(options) { |
|---|
| 846 | | OpenLayers.Format.XML.prototype.initialize.apply(this, [options]); |
|---|
| 847 | | }, |
|---|
| 848 | | |
|---|
| 849 | | /** |
|---|
| 850 | | * Method: read |
|---|
| 851 | | * Read capabilities data from a string, and return a list of layers. |
|---|
| 852 | | * |
|---|
| 853 | | * Parameters: |
|---|
| 854 | | * data - {String} or {DOMElement} data to read/parse. |
|---|
| 855 | | * |
|---|
| 856 | | * Returns: |
|---|
| 857 | | * {Array} List of named layers. |
|---|
| 858 | | */ |
|---|
| 859 | | read: function(data) { |
|---|
| 860 | | if(typeof data == "string") { |
|---|
| 861 | | data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); |
|---|
| 862 | | } |
|---|
| 863 | | var root = data.documentElement; |
|---|
| 864 | | this.rootPrefix = root.prefix; |
|---|
| 865 | | var context = { |
|---|
| 866 | | version: root.getAttribute("version") |
|---|
| 867 | | }; |
|---|
| 868 | | this.runChildNodes(context, root); |
|---|
| 869 | | return context; |
|---|
| 870 | | }, |
|---|
| 871 | | |
|---|
| 872 | | /** |
|---|
| 873 | | * Method: runChildNodes |
|---|
| 874 | | */ |
|---|
| 875 | | runChildNodes: function(obj, node) { |
|---|
| 876 | | var children = node.childNodes; |
|---|
| 877 | | var childNode, processor, prefix, local; |
|---|
| 878 | | for(var i=0; i<children.length; ++i) { |
|---|
| 879 | | childNode = children[i]; |
|---|
| 880 | | if(childNode.nodeType == 1) { |
|---|
| 881 | | prefix = (childNode.prefix == this.rootPrefix) ? |
|---|
| 882 | | this.defaultPrefix : |
|---|
| 883 | | this.getNamespacePrefix(childNode.namespaceURI); |
|---|
| 884 | | local = childNode.nodeName.split(":").pop(); |
|---|
| 885 | | processor = this["read_" + prefix + "_" + local]; |
|---|
| 886 | | if(processor) { |
|---|
| 887 | | processor.apply(this, [obj, childNode]); |
|---|
| 888 | | } |
|---|
| 889 | | } |
|---|
| 890 | | } |
|---|
| 891 | | }, |
|---|
| 892 | | |
|---|
| 893 | | /** |
|---|
| 894 | | * Method: read_wmc_General |
|---|
| 895 | | */ |
|---|
| 896 | | read_wmc_General: function(context, node) { |
|---|
| 897 | | this.runChildNodes(context, node); |
|---|
| 898 | | }, |
|---|
| 899 | | |
|---|
| 900 | | /** |
|---|
| 901 | | * Method: read_wmc_BoundingBox |
|---|
| 902 | | */ |
|---|
| 903 | | read_wmc_BoundingBox: function(context, node) { |
|---|
| 904 | | context.projection = node.getAttribute("SRS"); |
|---|
| 905 | | context.bounds = new OpenLayers.Bounds( |
|---|
| 906 | | parseFloat(node.getAttribute("minx")), |
|---|
| 907 | | parseFloat(node.getAttribute("miny")), |
|---|
| 908 | | parseFloat(node.getAttribute("maxx")), |
|---|
| 909 | | parseFloat(node.getAttribute("maxy")) |
|---|
| 910 | | ); |
|---|
| 911 | | }, |
|---|
| 912 | | |
|---|
| 913 | | /** |
|---|
| 914 | | * Method: read_wmc_LayerList |
|---|
| 915 | | */ |
|---|
| 916 | | read_wmc_LayerList: function(context, node) { |
|---|
| 917 | | context.layers = []; |
|---|
| 918 | | this.runChildNodes(context, node); |
|---|
| 919 | | }, |
|---|
| 920 | | |
|---|
| 921 | | /** |
|---|
| 922 | | * Method: read_wmc_Layer |
|---|
| 923 | | */ |
|---|
| 924 | | read_wmc_Layer: function(context, node) { |
|---|
| 925 | | var layerInfo = { |
|---|
| 926 | | params: {}, |
|---|
| 927 | | options: { |
|---|
| 928 | | visibility: (node.getAttribute("hidden") != "1") |
|---|
| 929 | | }, |
|---|
| 930 | | queryable: (node.getAttribute("queryable") == "1"), |
|---|
| 931 | | formats: [], |
|---|
| 932 | | styles: [] |
|---|
| 933 | | }; |
|---|
| 934 | | this.runChildNodes(layerInfo, node); |
|---|
| 935 | | // set properties common to multiple objects on layer options/params |
|---|
| 936 | | layerInfo.params.layers = layerInfo.name; |
|---|
| 937 | | layerInfo.options.maxExtent = layerInfo.maxExtent; |
|---|
| 938 | | // create the layer |
|---|
| 939 | | var layer = this.getLayerFromInfo(layerInfo); |
|---|
| 940 | | context.layers.push(layer); |
|---|
| 941 | | }, |
|---|
| 942 | | |
|---|
| 943 | | /** |
|---|
| 944 | | * Method: getLayerFromInfo |
|---|
| 945 | | * Create a WMS layer from a layerInfo object. |
|---|
| 946 | | * |
|---|
| 947 | | * Parameters: |
|---|
| 948 | | * layerInfo - {Object} An object representing a WMS layer. |
|---|
| 949 | | * |
|---|
| 950 | | * Returns: |
|---|
| 951 | | * {<OpenLayers.Layer.WMS>} A WMS layer. |
|---|
| 952 | | */ |
|---|
| 953 | | getLayerFromInfo: function(layerInfo) { |
|---|
| 954 | | var layer = new OpenLayers.Layer.WMS( |
|---|
| 955 | | layerInfo.title, |
|---|
| 956 | | layerInfo.href, |
|---|
| 957 | | layerInfo.params, |
|---|
| 958 | | layerInfo.options |
|---|
| 959 | | ); |
|---|
| 960 | | return layer; |
|---|
| 961 | | }, |
|---|
| 962 | | |
|---|
| 963 | | /** |
|---|
| 964 | | * Method: read_wmc_Extension |
|---|
| 965 | | */ |
|---|
| 966 | | read_wmc_Extension: function(obj, node) { |
|---|
| 967 | | this.runChildNodes(obj, node); |
|---|
| 968 | | }, |
|---|
| 969 | | |
|---|
| 970 | | /** |
|---|
| 971 | | * Method: read_ol_units |
|---|
| 972 | | */ |
|---|
| 973 | | read_ol_units: function(layerInfo, node) { |
|---|
| 974 | | layerInfo.options.units = this.getChildValue(node); |
|---|
| 975 | | }, |
|---|
| 976 | | |
|---|
| 977 | | /** |
|---|
| 978 | | * Method: read_ol_maxExtent |
|---|
| 979 | | */ |
|---|
| 980 | | read_ol_maxExtent: function(obj, node) { |
|---|
| 981 | | var bounds = new OpenLayers.Bounds( |
|---|
| 982 | | node.getAttribute("minx"), node.getAttribute("miny"), |
|---|
| 983 | | node.getAttribute("maxx"), node.getAttribute("maxy") |
|---|
| 984 | | ); |
|---|
| 985 | | obj.maxExtent = bounds; |
|---|
| 986 | | }, |
|---|
| 987 | | |
|---|
| 988 | | /** |
|---|
| 989 | | * Method: read_ol_transparent |
|---|
| 990 | | */ |
|---|
| 991 | | read_ol_transparent: function(layerInfo, node) { |
|---|
| 992 | | layerInfo.params.transparent = this.getChildValue(node); |
|---|
| 993 | | }, |
|---|
| 994 | | |
|---|
| 995 | | /** |
|---|
| 996 | | * Method: read_ol_numZoomLevels |
|---|
| 997 | | */ |
|---|
| 998 | | read_ol_numZoomLevels: function(layerInfo, node) { |
|---|
| 999 | | layerInfo.options.numZoomLevels = parseInt(this.getChildValue(node)); |
|---|
| 1000 | | }, |
|---|
| 1001 | | |
|---|
| 1002 | | /** |
|---|
| 1003 | | * Method: read_ol_opacity |
|---|
| 1004 | | */ |
|---|
| 1005 | | read_ol_opacity: function(layerInfo, node) { |
|---|
| 1006 | | layerInfo.options.opacity = parseFloat(this.getChildValue(node)); |
|---|
| 1007 | | }, |
|---|
| 1008 | | |
|---|
| 1009 | | /** |
|---|
| 1010 | | * Method: read_ol_singleTile |
|---|
| 1011 | | */ |
|---|
| 1012 | | read_ol_singleTile: function(layerInfo, node) { |
|---|
| 1013 | | layerInfo.options.singleTile = (this.getChildValue(node) == "true"); |
|---|
| 1014 | | }, |
|---|
| 1015 | | |
|---|
| 1016 | | /** |
|---|
| 1017 | | * Method: read_ol_isBaseLayer |
|---|
| 1018 | | */ |
|---|
| 1019 | | read_ol_isBaseLayer: function(layerInfo, node) { |
|---|
| 1020 | | layerInfo.options.isBaseLayer = (this.getChildValue(node) == "true"); |
|---|
| 1021 | | }, |
|---|
| 1022 | | |
|---|
| 1023 | | /** |
|---|
| 1024 | | * Method: read_ol_displayInLayerSwitcher |
|---|
| 1025 | | */ |
|---|
| 1026 | | read_ol_displayInLayerSwitcher: function(layerInfo, node) { |
|---|
| 1027 | | layerInfo.options.displayInLayerSwitcher = |
|---|
| 1028 | | (this.getChildValue(node) == "true"); |
|---|
| 1029 | | }, |
|---|
| 1030 | | |
|---|
| 1031 | | /** |
|---|
| 1032 | | * Method: read_wmc_Server |
|---|
| 1033 | | */ |
|---|
| 1034 | | read_wmc_Server: function(layerInfo, node) { |
|---|
| 1035 | | layerInfo.params.version = node.getAttribute("version"); |
|---|
| 1036 | | this.runChildNodes(layerInfo, node); |
|---|
| 1037 | | }, |
|---|
| 1038 | | |
|---|
| 1039 | | /** |
|---|
| 1040 | | * Method: read_wmc_FormatList |
|---|
| 1041 | | */ |
|---|
| 1042 | | read_wmc_FormatList: function(layerInfo, node) { |
|---|
| 1043 | | this.runChildNodes(layerInfo, node); |
|---|
| 1044 | | }, |
|---|
| 1045 | | |
|---|
| 1046 | | /** |
|---|
| 1047 | | * Method: read_wmc_Format |
|---|
| 1048 | | */ |
|---|
| 1049 | | read_wmc_Format: function(layerInfo, node) { |
|---|
| 1050 | | var format = this.getChildValue(node) |
|---|
| 1051 | | layerInfo.formats.push(format); |
|---|
| 1052 | | if(node.getAttribute("current") == "1") { |
|---|
| 1053 | | layerInfo.params.format = format; |
|---|
| 1054 | | } |
|---|
| 1055 | | }, |
|---|
| 1056 | | |
|---|
| 1057 | | /** |
|---|
| 1058 | | * Method: read_wmc_StyleList |
|---|
| 1059 | | */ |
|---|
| 1060 | | read_wmc_StyleList: function(layerInfo, node) { |
|---|
| 1061 | | this.runChildNodes(layerInfo, node); |
|---|
| 1062 | | }, |
|---|
| 1063 | | |
|---|
| 1064 | | /** |
|---|
| 1065 | | * Method: read_wmc_Style |
|---|
| 1066 | | */ |
|---|
| 1067 | | read_wmc_Style: function(layerInfo, node) { |
|---|
| 1068 | | var style = {}; |
|---|
| 1069 | | this.runChildNodes(style, node); |
|---|
| 1070 | | if(node.getAttribute("current") == "1") { |
|---|
| 1071 | | layerInfo.params.style = style.name; |
|---|
| 1072 | | } |
|---|
| 1073 | | layerInfo.styles.push(style); |
|---|
| 1074 | | }, |
|---|
| 1075 | | |
|---|
| 1076 | | /** |
|---|
| 1077 | | * Method: read_wmc_OnlineResource |
|---|
| 1078 | | */ |
|---|
| 1079 | | read_wmc_OnlineResource: function(obj, node) { |
|---|
| 1080 | | obj.href = this.getAttributeNS( |
|---|
| 1081 | | node, this.namespaces.xlink, "href" |
|---|
| 1082 | | ); |
|---|
| 1083 | | }, |
|---|
| 1084 | | |
|---|
| 1085 | | /** |
|---|
| 1086 | | * Method: read_wmc_Name |
|---|
| 1087 | | */ |
|---|
| 1088 | | read_wmc_Name: function(obj, node) { |
|---|
| 1089 | | var name = this.getChildValue(node); |
|---|
| 1090 | | if(name) { |
|---|
| 1091 | | obj.name = name; |
|---|
| 1092 | | } |
|---|
| 1093 | | }, |
|---|
| 1094 | | |
|---|
| 1095 | | /** |
|---|
| 1096 | | * Method: read_wmc_Title |
|---|
| 1097 | | */ |
|---|
| 1098 | | read_wmc_Title: function(obj, node) { |
|---|
| 1099 | | var title = this.getChildValue(node); |
|---|
| 1100 | | if(title) { |
|---|
| 1101 | | obj.title = title; |
|---|
| 1102 | | } |
|---|
| 1103 | | }, |
|---|
| 1104 | | |
|---|
| 1105 | | /** |
|---|
| 1106 | | * Method: read_wmc_Abstract |
|---|
| 1107 | | */ |
|---|
| 1108 | | read_wmc_Abstract: function(obj, node) { |
|---|
| 1109 | | var abst = this.getChildValue(node); |
|---|
| 1110 | | if(abst) { |
|---|
| 1111 | | obj["abstract"] = abst; |
|---|
| 1112 | | } |
|---|
| 1113 | | }, |
|---|
| 1114 | | |
|---|
| 1115 | | /** |
|---|
| 1116 | | * Method: read_wmc_LatLonBoundingBox |
|---|
| 1117 | | */ |
|---|
| 1118 | | read_wmc_LatLonBoundingBox: function(layer, node) { |
|---|
| 1119 | | layer.llbbox = [ |
|---|
| 1120 | | parseFloat(node.getAttribute("minx")), |
|---|
| 1121 | | parseFloat(node.getAttribute("miny")), |
|---|
| 1122 | | parseFloat(node.getAttribute("maxx")), |
|---|
| 1123 | | parseFloat(node.getAttribute("maxy")) |
|---|
| 1124 | | ]; |
|---|
| 1125 | | }, |
|---|
| 1126 | | |
|---|
| 1127 | | /** |
|---|
| 1128 | | * Method: read_wmc_LegendURL |
|---|
| 1129 | | */ |
|---|
| 1130 | | read_wmc_LegendURL: function(style, node) { |
|---|
| 1131 | | var legend = { |
|---|
| 1132 | | width: node.getAttribute('width'), |
|---|
| 1133 | | height: node.getAttribute('height') |
|---|
| 1134 | | }; |
|---|
| 1135 | | var links = node.getElementsByTagName("OnlineResource"); |
|---|
| 1136 | | if(links.length > 0) { |
|---|
| 1137 | | this.read_wmc_OnlineResource(legend, links[0]); |
|---|
| 1138 | | } |
|---|
| 1139 | | style.legend = legend; |
|---|
| 1140 | | }, |
|---|
| 1141 | | |
|---|
| 1142 | | /** |
|---|
| 1143 | | * Method: write |
|---|
| 1144 | | * |
|---|
| 1145 | | * Parameters: |
|---|
| 1146 | | * context - {Object} An object representing the map context. |
|---|
| 1147 | | * options - {Object} Optional object. |
|---|
| 1148 | | * |
|---|
| 1149 | | * Returns: |
|---|
| 1150 | | * {String} A WMC document string. |
|---|
| 1151 | | */ |
|---|
| 1152 | | write: function(context, options) { |
|---|
| 1153 | | var root = this.createElementDefaultNS("ViewContext"); |
|---|
| 1154 | | this.setAttributes(root, { |
|---|
| 1155 | | version: this.VERSION, |
|---|
| 1156 | | id: (options && typeof options.id == "string") ? |
|---|
| 1157 | | options.id : |
|---|
| 1158 | | OpenLayers.Util.createUniqueID("OpenLayers_Context_") |
|---|
| 1159 | | }); |
|---|
| 1160 | | |
|---|
| 1161 | | // add schemaLocation attribute |
|---|
| 1162 | | this.setAttributeNS( |
|---|
| 1163 | | root, this.namespaces.xsi, |
|---|
| 1164 | | "xsi:schemaLocation", this.schemaLocation |
|---|
| 1165 | | ); |
|---|
| 1166 | | |
|---|
| 1167 | | // required General element |
|---|
| 1168 | | root.appendChild(this.write_wmc_General(context)); |
|---|
| 1169 | | |
|---|
| 1170 | | // required LayerList element |
|---|
| 1171 | | root.appendChild(this.write_wmc_LayerList(context)); |
|---|
| 1172 | | |
|---|
| 1173 | | return OpenLayers.Format.XML.prototype.write.apply(this, [root]); |
|---|
| 1174 | | }, |
|---|
| 1175 | | |
|---|
| 1176 | | /** |
|---|
| 1177 | | * Method: createElementDefaultNS |
|---|
| 1178 | | * Shorthand for createElementNS with namespace from <defaultPrefix>. |
|---|
| 1179 | | * Can optionally be used to set attributes and a text child value. |
|---|
| 1180 | | * |
|---|
| 1181 | | * Parameters: |
|---|
| 1182 | | * name - {String} The qualified node name. |
|---|
| 1183 | | * childValue - {String} Optional value for text child node. |
|---|
| 1184 | | * attributes - {Object} Optional object representing attributes. |
|---|
| 1185 | | * |
|---|
| 1186 | | * Returns: |
|---|
| 1187 | | * {Element} An element node. |
|---|
| 1188 | | */ |
|---|
| 1189 | | createElementDefaultNS: function(name, childValue, attributes) { |
|---|
| 1190 | | var node = this.createElementNS( |
|---|
| 1191 | | this.namespaces[this.defaultPrefix], |
|---|
| 1192 | | name |
|---|
| 1193 | | ); |
|---|
| 1194 | | if(childValue) { |
|---|
| 1195 | | node.appendChild(this.createTextNode(childValue)); |
|---|
| 1196 | | } |
|---|
| 1197 | | if(attributes) { |
|---|
| 1198 | | this.setAttributes(node, attributes); |
|---|
| 1199 | | } |
|---|
| 1200 | | return node; |
|---|
| 1201 | | }, |
|---|
| 1202 | | |
|---|
| 1203 | | /** |
|---|
| 1204 | | * Method: setAttributes |
|---|
| 1205 | | * Set multiple attributes given key value pairs from an object. |
|---|
| 1206 | | * |
|---|
| 1207 | | * Parameters: |
|---|
| 1208 | | * node - {Element} An element node. |
|---|
| 1209 | | * obj - {Object} An object whose properties represent attribute names and |
|---|
| 1210 | | * values represent attribute values. |
|---|
| 1211 | | */ |
|---|
| 1212 | | setAttributes: function(node, obj) { |
|---|
| 1213 | | var value; |
|---|
| 1214 | | for(var name in obj) { |
|---|
| 1215 | | value = obj[name].toString(); |
|---|
| 1216 | | if(value.match(/[A-Z]/)) { |
|---|
| 1217 | | // safari lowercases attributes with setAttribute |
|---|
| 1218 | | this.setAttributeNS(node, null, name, value); |
|---|
| 1219 | | } else { |
|---|
| 1220 | | node.setAttribute(name, value); |
|---|
| 1221 | | } |
|---|
| 1222 | | } |
|---|
| 1223 | | }, |
|---|
| 1224 | | |
|---|
| 1225 | | /** |
|---|
| 1226 | | * Method: write_wmc_General |
|---|
| 1227 | | * Create a General node given an context object. |
|---|
| 1228 | | * |
|---|
| 1229 | | * Parameters: |
|---|
| 1230 | | * context - {Object} Context object. |
|---|
| 1231 | | * |
|---|
| 1232 | | * Returns: |
|---|
| 1233 | | * {Element} A WMC General element node. |
|---|
| 1234 | | */ |
|---|
| 1235 | | write_wmc_General: function(context) { |
|---|
| 1236 | | var node = this.createElementDefaultNS("General"); |
|---|
| 1237 | | |
|---|
| 1238 | | // optional Window element |
|---|
| 1239 | | if(context.size) { |
|---|
| 1240 | | node.appendChild(this.createElementDefaultNS( |
|---|
| 1241 | | "Window", null, |
|---|
| 1242 | | { |
|---|
| 1243 | | width: context.size.w, |
|---|
| 1244 | | height: context.size.h |
|---|
| 1245 | | } |
|---|
| 1246 | | )); |
|---|
| 1247 | | } |
|---|
| 1248 | | |
|---|
| 1249 | | // required BoundingBox element |
|---|
| 1250 | | var bounds = context.bounds; |
|---|
| 1251 | | node.appendChild(this.createElementDefaultNS( |
|---|
| 1252 | | "BoundingBox", null, |
|---|
| 1253 | | { |
|---|
| 1254 | | minx: bounds.left.toPrecision(10), |
|---|
| 1255 | | miny: bounds.bottom.toPrecision(10), |
|---|
| 1256 | | maxx: bounds.right.toPrecision(10), |
|---|
| 1257 | | maxy: bounds.top.toPrecision(10), |
|---|
| 1258 | | SRS: context.projection |
|---|
| 1259 | | } |
|---|
| 1260 | | )); |
|---|
| 1261 | | |
|---|
| 1262 | | // required Title element |
|---|
| 1263 | | node.appendChild(this.createElementDefaultNS( |
|---|
| 1264 | | "Title", context.title |
|---|
| 1265 | | )); |
|---|
| 1266 | | |
|---|
| 1267 | | // OpenLayers specific map properties |
|---|
| 1268 | | node.appendChild(this.write_ol_MapExtension(context)); |
|---|
| 1269 | | |
|---|
| 1270 | | return node; |
|---|
| 1271 | | }, |
|---|
| 1272 | | |
|---|
| 1273 | | /** |
|---|
| 1274 | | * Method: write_ol_MapExtension |
|---|
| 1275 | | */ |
|---|
| 1276 | | write_ol_MapExtension: function(context) { |
|---|
| 1277 | | var node = this.createElementDefaultNS("Extension"); |
|---|
| 1278 | | |
|---|
| 1279 | | var bounds = context.maxExtent; |
|---|
| 1280 | | if(bounds) { |
|---|
| 1281 | | var maxExtent = this.createElementNS( |
|---|
| 1282 | | this.namespaces.ol, "ol:maxExtent" |
|---|
| 1283 | | ); |
|---|
| 1284 | | this.setAttributes(maxExtent, { |
|---|
| 1285 | | minx: bounds.left.toPrecision(10), |
|---|
| 1286 | | miny: bounds.bottom.toPrecision(10), |
|---|
| 1287 | | maxx: bounds.right.toPrecision(10), |
|---|
| 1288 | | maxy: bounds.top.toPrecision(10) |
|---|
| 1289 | | }); |
|---|
| 1290 | | node.appendChild(maxExtent); |
|---|
| 1291 | | } |
|---|
| 1292 | | |
|---|
| 1293 | | return node; |
|---|
| 1294 | | }, |
|---|
| 1295 | | |
|---|
| 1296 | | /** |
|---|
| 1297 | | * Method: write_wmc_LayerList |
|---|
| 1298 | | * Create a LayerList node given an context object. |
|---|
| 1299 | | * |
|---|
| 1300 | | * Parameters: |
|---|
| 1301 | | * context - {Object} Context object. |
|---|
| 1302 | | * |
|---|
| 1303 | | * Returns: |
|---|
| 1304 | | * {Element} A WMC LayerList element node. |
|---|
| 1305 | | */ |
|---|
| 1306 | | write_wmc_LayerList: function(context) { |
|---|
| 1307 | | var list = this.createElementDefaultNS("LayerList"); |
|---|
| 1308 | | |
|---|
| 1309 | | var layer; |
|---|
| 1310 | | for(var i=0; i<context.layers.length; ++i) { |
|---|
| 1311 | | layer = context.layers[i]; |
|---|
| 1312 | | if(layer instanceof OpenLayers.Layer.WMS) { |
|---|
| 1313 | | list.appendChild(this.write_wmc_Layer(layer)); |
|---|
| 1314 | | } |
|---|
| 1315 | | } |
|---|
| 1316 | | |
|---|
| 1317 | | return list; |
|---|
| 1318 | | }, |
|---|
| 1319 | | |
|---|
| 1320 | | /** |
|---|
| 1321 | | * Method: write_wmc_Layer |
|---|
| 1322 | | * Create a Layer node given a layer object. |
|---|
| 1323 | | * |
|---|
| 1324 | | * Parameters: |
|---|
| 1325 | | * layer - {<OpenLayers.Layer.WMS>} Layer object. |
|---|
| 1326 | | * |
|---|
| 1327 | | * Returns: |
|---|
| 1328 | | * {Element} A WMC Layer element node. |
|---|
| 1329 | | */ |
|---|
| 1330 | | write_wmc_Layer: function(layer) { |
|---|
| 1331 | | var node = this.createElementDefaultNS( |
|---|
| 1332 | | "Layer", null, { |
|---|
| 1333 | | queryable: "1", |
|---|
| 1334 | | hidden: layer.visibility ? "0" : "1" |
|---|
| 1335 | | } |
|---|
| 1336 | | ); |
|---|
| 1337 | | |
|---|
| 1338 | | // required Server element |
|---|
| 1339 | | node.appendChild(this.write_wmc_Server(layer)); |
|---|
| 1340 | | |
|---|
| 1341 | | // required Name element |
|---|
| 1342 | | node.appendChild(this.createElementDefaultNS( |
|---|
| 1343 | | "Name", layer.params["LAYERS"] |
|---|
| 1344 | | )); |
|---|
| 1345 | | |
|---|
| 1346 | | // required Title element |
|---|
| 1347 | | node.appendChild(this.createElementDefaultNS( |
|---|
| 1348 | | "Title", layer.name |
|---|
| 1349 | | )); |
|---|
| 1350 | | |
|---|
| 1351 | | // optional FormatList element |
|---|
| 1352 | | node.appendChild(this.write_wmc_FormatList(layer)); |
|---|
| 1353 | | |
|---|
| 1354 | | // optional StyleList element |
|---|
| 1355 | | node.appendChild(this.write_wmc_StyleList(layer)); |
|---|
| 1356 | | |
|---|
| 1357 | | // OpenLayers specific properties go in an Extension element |
|---|
| 1358 | | node.appendChild(this.write_wmc_LayerExtension(layer)); |
|---|
| 1359 | | |
|---|
| 1360 | | return node; |
|---|
| 1361 | | }, |
|---|
| 1362 | | |
|---|
| 1363 | | /** |
|---|
| 1364 | | * Method: write_wmc_LayerExtension |
|---|
| 1365 | | * Add OpenLayers specific layer parameters to an Extension element. |
|---|
| 1366 | | * |
|---|
| 1367 | | * Parameters: |
|---|
| 1368 | | * layer - {<OpenLayers.Layer.WMS>} A WMS layer. |
|---|
| 1369 | | * |
|---|
| 1370 | | * Returns: |
|---|
| 1371 | | * {Element} A WMC Extension element (for a layer). |
|---|
| 1372 | | */ |
|---|
| 1373 | | write_wmc_LayerExtension: function(layer) { |
|---|
| 1374 | | var node = this.createElementDefaultNS("Extension"); |
|---|
| 1375 | | |
|---|
| 1376 | | var bounds = layer.maxExtent; |
|---|
| 1377 | | var maxExtent = this.createElementNS( |
|---|
| 1378 | | this.namespaces.ol, "ol:maxExtent" |
|---|
| 1379 | | ); |
|---|
| 1380 | | this.setAttributes(maxExtent, { |
|---|
| 1381 | | minx: bounds.left.toPrecision(10), |
|---|
| 1382 | | miny: bounds.bottom.toPrecision(10), |
|---|
| 1383 | | maxx: bounds.right.toPrecision(10), |
|---|
| 1384 | | maxy: bounds.top.toPrecision(10) |
|---|
| 1385 | | }); |
|---|
| 1386 | | node.appendChild(maxExtent); |
|---|
| 1387 | | |
|---|
| 1388 | | var param = layer.params["TRANSPARENT"]; |
|---|
| 1389 | | if(param) { |
|---|
| 1390 | | var trans = this.createElementNS( |
|---|
| 1391 | | this.namespaces.ol, "ol:transparent" |
|---|
| 1392 | |
|---|