When I was doing WMS service aggregation, I encountered a problem. The whole process was like this:
1. Use ArcServer to publish a map WMS service,
2. Then, use the client aggregation example-wms demo provided by Hypergraph to input the WMS address of ArcGIS to the address,
3. Click Next. In the displayed layer name, the layers of the Chinese name are garbled.
I checked the relevant page code and js Code, and finally found that the SuperMap. Utility. getXmlHttpRequest () in the js method provided by hypergraphs has a problem.
The source code provided by the Hypergraph is as follows:
/*** Get metadata information */function getCapabilities () {hideElement ("divWMSLayerSettings"); var url = document. getElementById ("txtWMSAddress "). value; var msg = "retrieving metadata information"; msg + = url; document. getElementById ("divMsg "). innerHTML = msg; showElement ("divMsg"); var url = document. getElementById ("txtWMSAddress "). value; if (url & url. trim ()! = "") {If (url. indexOf ("? ")! =-1) {url + = "&";} else {url + = "? ";} Url + =" SERVICE = WMS & VERSION = 1.1.1 & REQUEST = GetCapabilities "; // obtain the metadata var xhr = SuperMap of the SERVICE. utility. getXmlHttpRequest (); url = getContextPath () + "ajaxhandler? Url = "+ escape (url); xhr. open ("GET", url, true); xhr. setRequestHeader ("Content-Type", "application/x-www-form-urlencoded; charset = gb2312"); var handler = onGetCapabilitiesComplete; var errorHandler = onGetCapabilitiesError; xhr. onreadystatechange = function () {if (xhr. readyState = 4) {if (xhr. status = 200) {var xmldoc; if (window. activeXObject) {xmldoc = new ActiveXObject ("microsoft. XMLDOM ");} else if (document. implementation & document. implementation. createDocument) {xmldoc = document. implementation. createDocument ("", "doc", null);} xmldoc. async = false; if (window. activeXObject) {xmldoc. loadXML (xhr. responseText);} else {var parser = new DOMParser (); xmldoc = parser. parseFromString (xhr. responseText, "text/xml");} handler (xhr. responseText) ;}else {errorHandler () ;}} xhr. send (null) ;}else {alert ("WMS service address cannot be blank"); onPre ();}};
Later, I added a getXMLHttpRequest method as follows:
function getXMLHttpRequest(){ var xhr = false; if(window.XMLHttpRequest){ xhr = new XMLHttpRequest(); } if(window.ActiveXObject){ xhr = new ActiveXObject("Microsoft.XMLHTTP"); } return xhr;}
In the original code, change var xhr = SuperMap. Utility. getXmlHttpRequest () to var xhr = getXMLHttpRequest ();
The layers with Chinese names are not garbled. If you have encountered similar problems, try again like me!