1
|
/* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license.
|
2
|
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the full
|
3
|
* text of the license. */
|
4
|
|
5
|
OpenLayers.ProxyHost = "";
|
6
|
//OpenLayers.ProxyHost = "examples/proxy.cgi?url=";
|
7
|
|
8
|
/**
|
9
|
* Ajax reader for OpenLayers
|
10
|
*
|
11
|
*@uri url to do remote XML http get
|
12
|
*@param 'get' format params (x=y&a=b...)
|
13
|
*@who object to handle callbacks for this request
|
14
|
*@complete the function to be called on success
|
15
|
*@failure the function to be called on failure
|
16
|
*
|
17
|
* example usage from a caller:
|
18
|
*
|
19
|
* caps: function(request) {
|
20
|
* -blah-
|
21
|
* },
|
22
|
*
|
23
|
* OpenLayers.loadURL(url,params,this,caps);
|
24
|
*
|
25
|
* Notice the above example does not provide an error handler; a default empty
|
26
|
* handler is provided which merely logs the error if a failure handler is not
|
27
|
* supplied
|
28
|
*
|
29
|
*/
|
30
|
|
31
|
|
32
|
/**
|
33
|
* @param {} request
|
34
|
*/
|
35
|
OpenLayers.nullHandler = function(request) {
|
36
|
alert("Unhandled request return " + request.statusText);
|
37
|
};
|
38
|
|
39
|
/** Background load a document
|
40
|
*
|
41
|
* @param {String} uri URI of source doc
|
42
|
* @param {String} params Params on get (doesnt seem to work)
|
43
|
* @param {Object} caller object which gets callbacks
|
44
|
* @param {Function} onComplete callback for success
|
45
|
* @param {Function} onFailure callback for failure
|
46
|
*
|
47
|
* Both callbacks optional (though silly)
|
48
|
*/
|
49
|
OpenLayers.loadURL = function(uri, params, caller,
|
50
|
onComplete, onFailure) {
|
51
|
|
52
|
if (OpenLayers.ProxyHost && uri.startsWith("http")) {
|
53
|
uri = OpenLayers.ProxyHost + escape(uri);
|
54
|
}
|
55
|
|
56
|
var success = (onComplete) ? onComplete.bind(caller)
|
57
|
: OpenLayers.nullHandler;
|
58
|
|
59
|
var failure = (onFailure) ? onFailure.bind(caller)
|
60
|
: OpenLayers.nullHandler;
|
61
|
|
62
|
// from prototype.js
|
63
|
new Ajax.Request(uri,
|
64
|
{ method: 'get',
|
65
|
parameters: params,
|
66
|
onComplete: success,
|
67
|
onFailure: failure
|
68
|
}
|
69
|
);
|
70
|
};
|
71
|
|
72
|
/** Parse XML into a doc structure
|
73
|
* @param {String} text
|
74
|
*
|
75
|
* @returns Parsed Ajax Response ??
|
76
|
* @type ?
|
77
|
*/
|
78
|
OpenLayers.parseXMLString = function(text) {
|
79
|
|
80
|
//MS sucks, if the server is bad it dies
|
81
|
var index = text.indexOf('<');
|
82
|
if (index > 0) {
|
83
|
text = text.substring(index);
|
84
|
}
|
85
|
|
86
|
var ajaxResponse = Try.these(
|
87
|
function() {
|
88
|
var xmldom = new ActiveXObject('Microsoft.XMLDOM');
|
89
|
xmldom.loadXML(text);
|
90
|
return xmldom;
|
91
|
},
|
92
|
function() {
|
93
|
return new DOMParser().parseFromString(text, 'text/xml');
|
94
|
},
|
95
|
function() {
|
96
|
var req = new XMLHttpRequest();
|
97
|
req.open("GET", "data:" + "text/xml" +
|
98
|
";charset=utf-8," + encodeURIComponent(text), false);
|
99
|
if (req.overrideMimeType) {
|
100
|
req.overrideMimeType("text/xml");
|
101
|
}
|
102
|
req.send(null);
|
103
|
return req.responseXML;
|
104
|
}
|
105
|
);
|
106
|
|
107
|
return ajaxResponse;
|
108
|
};
|